Skip to content

feat(sdk): Add a tasks that listens for historic room keys if they arrive out of order #5322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

poljar
Copy link
Contributor

@poljar poljar commented Jul 1, 2025

Historic room key bundles are uploaded as an encrypted file to the media repo and the key to decrypt the file is sent as a to-device message to the recipient device.

In the nominal case, the invite and this to-device message should arrive at the same time and accepting the invite would download and import the bundle. If the to-device message arrives after the invite has already been accepted we would never download and import the bundle.

To mitigate this problem, this patch introduces a task that listens for bundles that arrive. If the bundle is for a room that we have joined we will consider importing the bundle.

Note: that the acceptance rules aren't yet decided and this PR needs to be updated with some better acceptance rules before it gets merged.

This closes: #4926.

  • Public API changes documented in changelogs (optional)

@poljar poljar requested a review from a team as a code owner July 1, 2025 12:46
@poljar poljar requested review from andybalaam and removed request for a team July 1, 2025 12:46
poljar added 3 commits July 1, 2025 14:57
…rive out of order

Historic room key bundles are uploaded as an encrypted file to the media
repo and the key to decrypt the file is sent as a to-device message to
the recipient device.

In the nominal case, the invite and this to-device message should arrive
at the same time and accepting the invite would download and import the
bundle.

If the to-device message arrives after the invite has already been
accepted we would never download and import the bundle.

To mitigate this problem, this patch introduces a task that listens for
bundles that arrive. If the bundle is for a room that we have joined we
will consider importing the bundle.
Copy link

codecov bot commented Jul 1, 2025

Codecov Report

Attention: Patch coverage is 95.08197% with 3 lines in your changes missing coverage. Please review.

Project coverage is 88.77%. Comparing base (59c2980) to head (6368654).
Report is 21 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
crates/matrix-sdk/src/encryption/tasks.rs 94.00% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5322   +/-   ##
=======================================
  Coverage   88.76%   88.77%           
=======================================
  Files         333      333           
  Lines       90228    90280   +52     
  Branches    90228    90280   +52     
=======================================
+ Hits        80093    80147   +54     
+ Misses       6309     6305    -4     
- Partials     3826     3828    +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@poljar poljar force-pushed the poljar/shared-history/out-of-order branch from f258ada to bc5afce Compare July 1, 2025 12:58
Copy link
Member

@andybalaam andybalaam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far - some small questions inline.

#[instrument(skip(room), fields(room_id = %room.room_id()))]
async fn handle_bundle(room: &Room, bundle_info: &RoomKeyBundleInfo) {
if Self::should_accept_bundle(room, bundle_info) {
info!("Accepting an out of order key bundle.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really "out of order", right? More "late-arriving".

@poljar
Copy link
Contributor Author

poljar commented Jul 2, 2025

I think we'll want to rebase this on top of #5333. We should at least restrict this behavior to accept such bundles only if the user explicitly accepted the invite, so the homeserver can't join you into a room.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

History sharing: handle the key bundle arriving *after* the invite
2 participants