-
Notifications
You must be signed in to change notification settings - Fork 39
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
Scope the connections to devices and not to a hash of the access token #51
Comments
native SS implementations will treat it however homeservers do it today. Native SS doesn't modify the event in any special way. That being said, the proxy implementation DOES edit the transaction ID because that's how it can de-duplicate room data as it's multi-tenant with other users. It currently does use the access_token as a device ID, and this assumption is baked into most of the proxy as it predates the ability to get the device ID from /whoami
it would be treated as a new device for the same user, causing a new poller to be created and an initial sync to be performed. The proxy will still be able to serve up data for the user's account instantly due to having some data from the previous token, so in theory it should Just Work with the caveat that it might take fractionally longer to sync the first time you use the new token, though I have not tested this. I assume the old token will 401/403, which will then cause the old poll loop to terminate which will then tear down the old connection. ah, though the to-device table is keyed off SHA256(access_token) so there will be a race condition where if a new to-device event arrived and before it got delivered to the client the token was invalidated, then it will be permanently lost. which isn't great. We'd need to key off a static identifier e.g SHA256(user_id $DELIMITER device_id) |
Note that this is an internal-only change, transparent to downstream clients and upstream homeservers.
Alternatively we could just store For this to work, the homeserver must consistently return a user_id with the same capitalisation (legacy mxids etc grrr). We also want the user id and device ids to have bounded length. Not sure if device ids have a maximum length in the spec? If not, we can truncate the device ID to a sensibly-sized prefix. |
We'd have to choose DELIMITER to be something compatible with the historical user ids, which means it'll need to be a nonprinting ascii character.
Not that I can see. A quick look on Matrix.org shows that almost all ( |
Useful for #51, small enough to include in isolation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Notes:
Could do:
|
@sandhose pointed out to me that matrix-org/matrix-spec-proposals#3970 has landed---transaction IDs are scoped to devices (meaning userID + deviceID) and not "client session". I think the proxy was already effectively doing this, but will need to check and probably write a test for this. |
Problem: how do we distinguish between a device expiry and a token expiry? If we don't, we'll end up keeping device-scoped data forever, in particular, to-device messages. This will be A Problem. |
I think one potential solution would be to make the proxy OIDC-native. The MAS side is not really ready for that though, so it depends how much of a problem this ends up being? We could also imagine a (temporary) hacky solution, where MAS calls some special endpoint on the proxy when a device gets deleted? |
Maybe it's sufficient to look for soft or hard logouts, and expire entire devices on hard logouts? |
Long story short: soft-logout is not really usable in your case (and with Matrix refreshing tokens) and for a simple reason: the client should be able to track whenever their access tokens is about to expire, and the soft-logout would happen when it tries to refresh the token, which of course the proxy doesn't know about. The old, expired access tokens won't have a |
Some alternatives that we can suggest for determining when device state can be purged:
In the future OIDC model we have discussed where the proxy would exchange the access token received from the client with its own access/refresh token it would be handled nicely: when the original client is logged out the corresponding (exchanged) access token would also be invalidated. So, the proxy could purge data once its own access/refresh token is no longer valid. |
Why is this issue still open? We do scope to devices now. Anything else should be a separate issue (e.g cleaning up stale devices) |
#127 was already made, so closing this. |
It looks like some stuff is scoped to a hash of the access token, which will become a problem when we have refreshing access tokens, either via MSC2918 or with OIDC.
sliding-sync/internal/request.go
Lines 11 to 24 in 2c91fcb
It should be using the device_id instead, which are stable even when the token refreshes
Maybe related to #22?
Some (internal) discussions about that:
The text was updated successfully, but these errors were encountered: