You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This outlines a race condition in the CSAPI which can cause UTDs.
Consider:
Alice is in a E2EE room and invites Bob. The request 200 OKs but has yet to come down /sync.
Alice tries to send a message in the room.
Alice should encrypt for Bob.
In practice, clients will not encrypt for Bob, causing a UTD if you very quickly send an encrypted message after inviting a user. This can happen due to:
A bot is using the SDK so message sending is very quick after an invite
DMs: for better UX a room is only made / user invited / message sent, when someone sends a message in a DM room rather than just selects the user's room. This means the message is already ready to go at the same time as invite time.
Rust SDK is slightly better than JS SDK on this, because Rust SDK will hit /members for the first message it sends, so it isn't reliant on /sync for that one request. In practice, this means it handles the DM case.
To fix this, we should be remembering that we, the client, have modified the membership state of the room, and invalidate the room member list (so we hit /members again). We can't assume that a 200 OK to /invite will guarantee that the user is in an invited state, so we still need to defer to the server.
This is needed to prevent the race condition where the invite request finished, the `/sync` one didn't fetch the new membership event yet and we send a message in the room. This message won't be encrypted for the newly invited user and will result in an UTD.
I added a new integration test and I can confirm this [complement-crypto test](matrix-org/complement-crypto#98) now passes instead of being skipped.
Fixes#3622.
---
* fix(sdk): force room member reload after inviting a user
This is needed to prevent the race condition where the invite request finished, the `/sync` one didn't fetch the new membership event yet and we send a message in the room. This message won't be encrypted for the newly invited user and will result in an UTD.
* Use `room.mark_members_missing()` instead, add integration test
* Abort syncing before the test ends
* Resolve nit: else after a return
* Fix race condition where bob may try to join the room before the invite is received
* Remove double sync
This outlines a race condition in the CSAPI which can cause UTDs.
Consider:
In practice, clients will not encrypt for Bob, causing a UTD if you very quickly send an encrypted message after inviting a user. This can happen due to:
Rust SDK is slightly better than JS SDK on this, because Rust SDK will hit
/members
for the first message it sends, so it isn't reliant on/sync
for that one request. In practice, this means it handles the DM case.To fix this, we should be remembering that we, the client, have modified the membership state of the room, and invalidate the room member list (so we hit /members again). We can't assume that a 200 OK to /invite will guarantee that the user is in an invited state, so we still need to defer to the server.
A test for this is in matrix-org/complement-crypto#98
The text was updated successfully, but these errors were encountered: