Skip to content

Conversation

richvdh
Copy link
Member

@richvdh richvdh commented Oct 9, 2025

This PR fixes a pair of bugs around how device verification on incoming encrypted to-device messages. See individual commits for more details.

Fixes: #5613
Fixes: #5768

@richvdh richvdh force-pushed the rav/history_sharing_exclude_insecure_devices branch from a364d10 to 0a18741 Compare October 9, 2025 00:02
Copy link

codspeed-hq bot commented Oct 9, 2025

CodSpeed Performance Report

Merging #5763 will not alter performance

Comparing rav/history_sharing_exclude_insecure_devices (c6d1b60) with main (588d604)

Summary

✅ 50 untouched

`Account::parse_decrypted_to_device_event` is getting a bit big and unwieldy,
so factor out the bit that attempts to find the sending device.

(Also, remove an outdated TODO.)
@richvdh richvdh force-pushed the rav/history_sharing_exclude_insecure_devices branch from 0a18741 to 28beb91 Compare October 9, 2025 17:28
Copy link

codecov bot commented Oct 9, 2025

Codecov Report

❌ Patch coverage is 86.74699% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.43%. Comparing base (9b48501) to head (c6d1b60).
⚠️ Report is 23 commits behind head on main.

Files with missing lines Patch % Lines
crates/matrix-sdk-crypto/src/olm/account.rs 68.57% 7 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5763      +/-   ##
==========================================
+ Coverage   88.42%   88.43%   +0.01%     
==========================================
  Files         360      360              
  Lines       99796    99842      +46     
  Branches    99796    99842      +46     
==========================================
+ Hits        88244    88300      +56     
+ Misses       7411     7399      -12     
- Partials     4141     4143       +2     

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

Currently, when we receive a room key bundle to-device event, we don't look up
the sender device at all, meaning that the message is then marked as "from
missing device", which means that if you turn on "exclude insecure devices",
the message is dropped.

This patch changes the logic so that room key bundle to-device events are
treated the same way as most other to-device events (except room keys, which
continue to be special).

Fixes: #5613, although the
integration test now fails because instead we hit #5768.
I'm going to need to suppress `sender_device_keys` for more tests, so pull out
a test helper to help with this.
…per`

No need to convert the event content to a to-device request, and then convert
back again.
…sages

When receiving an encrypted to-device message, if the sender device is not in
the store, but the event includes `sender_device_keys`, use
`sender_device_keys` to do the verification checks etc.

Fixes: #5768
Add a test to ensure that history-sharing still works when "exclude insecure
devices" is enabled.
@richvdh richvdh force-pushed the rav/history_sharing_exclude_insecure_devices branch from fbe146a to c6d1b60 Compare October 10, 2025 14:47
@richvdh richvdh changed the title WIP: crypto: look up sender device for key bundles crypto: Fix bugs in processing incoming encrypted to-device messages Oct 10, 2025
@richvdh richvdh marked this pull request as ready for review October 10, 2025 15:39
@richvdh richvdh requested review from a team as code owners October 10, 2025 15:39
@richvdh richvdh requested review from poljar and removed request for a team October 10, 2025 15:39
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.

Encrypted to-device messages from unknown devices are dropped History-sharing-on-invite is broken when "Exclude insecure devices" is set

1 participant