feat(sdk): Rotate session keys when a member leaves the room#6292
feat(sdk): Rotate session keys when a member leaves the room#6292
Conversation
d15f1b2 to
11a27af
Compare
11a27af to
f0c2d33
Compare
| let Some(user_id) = client.user_id() else { | ||
| // We aren't logged in, so this shouldn't ever happen. | ||
| return; | ||
| }; |
There was a problem hiding this comment.
I'm tempted to use unwrap here, but I am wary that if any of these assumptions are wrong, this will crash the client entirely.
Signed-off-by: Skye Elliot <[email protected]>
Signed-off-by: Skye Elliot <[email protected]>
f0c2d33 to
f0d12dd
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6292 +/- ##
==========================================
- Coverage 89.94% 89.90% -0.05%
==========================================
Files 374 374
Lines 102613 102635 +22
Branches 102613 102635 +22
==========================================
- Hits 92299 92270 -29
- Misses 6771 6799 +28
- Partials 3543 3566 +23 ☔ View full report in Codecov by Sentry. |
|
@kaylendog in the description of the PR, could you link the issue that explains why we need to do this? |
richvdh
left a comment
There was a problem hiding this comment.
mostly lgtm, a couple of small comments
testing/matrix-sdk-integration-testing/src/tests/e2ee/shared_history.rs
Outdated
Show resolved
Hide resolved
testing/matrix-sdk-integration-testing/src/tests/e2ee/shared_history.rs
Outdated
Show resolved
Hide resolved
testing/matrix-sdk-integration-testing/src/tests/e2ee/shared_history.rs
Outdated
Show resolved
Hide resolved
| /// Sets up a handler to rotate room keys when a user leaves a room. | ||
| fn setup_room_membership_session_discard_handler(&self) { | ||
| let client = WeakClient::from_client(&self.client); | ||
| self.client.add_event_handler(move |ev: SyncRoomMemberEvent, room: Room| async move { |
There was a problem hiding this comment.
do things added by add_event_handler definitely get called when state changes outside the timeline section of the sync response?
It might be good to do a test which does something like:
- Charlie leaves the room
- Alice sends Message 1
- Alice goes offline for a while
- Bob invites Charlie
- Charlie joins
- Charlie leaves
- Bob sends a bunch more messages
- Alice comes back online
- Alice sends Message 2
The point here is that, from Alice's point of view, Charlie is in the leave state at both Message 1 and Message 2, and she'll never even see the invite/join/leave stage unless she backfills. She should still discard the session because she'll see a different leave event for Bob, but it's a bit subtle.
There was a problem hiding this comment.
This exact scenario did occur to me, but I want to avoid walking back through all the state changes up until we sent the last message... I'm hoping the handler fires for us here - I'll test.
There was a problem hiding this comment.
I've implemented a test for this in 4a93def which should be passing, but I do think it's worth discussing the potential sliding sync a bit further.
02f3839 to
177f38a
Compare
This PR adds an event handler on start that discards (and hence rotates) the current session whenever we see a
leavemembership event.Part of element-hq/element-meta#3078
CHANGELOG.mdfiles.Signed-off-by: Skye Elliot [email protected]