fix: Make OAuth access token refreshing idempotent #2587
Labels
No labels
Abandoned
Blocked
Bug
Changelog
Added
Changelog
Missing
Changelog
None
Cherry-picking
Compliance
Database
Dependencies
Dependencies/Renovate
Difficulty
Easy
Difficulty
Hard
Difficulty
Medium
Documentation
Enhancement
Good first issue
Help wanted
Inherited
Matrix/Administration
Matrix/Appservices
Matrix/Auth
Matrix/Client
Matrix/Core
Matrix/E2EE
Matrix/Federation
Matrix/Hydra
Matrix/MSC
Matrix/Media
Matrix/T&S
Merge
Merge/Manual
Merge/Squash
Meta
Meta/CI
Meta/Packaging
Priority
Blocking
Priority
High
Priority
Low
Security
Status
Confirmed
Status
Duplicate
Status
Invalid
Status
Needs Investigation
Support
bob the builder
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
continuwuation/continuwuity!2587
Loading…
Reference in a new issue
No description provided.
Delete branch "ginger/oauth-idempotency"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This pull request fixes #2406.
Pull request checklist:
mainbranch, and the branch is named something other thanmain.myself, if applicable. This includes ensuring code compiles.
@ -708,0 +756,4 @@session_info.previous_refresh_token = Some(refresh_token);} else if Some(&refresh_token) == session_info.previous_refresh_token.as_ref() {// The client is refreshing with their previous refresh token,unfortunately this comment sounds like complete word salad because there are four different tokens involved here
it's fine it just about makes sense
remove_session and remove_device need to clean up previous tokens. Think there are more issues with the logic, will look this evening
@ -249,0 +265,4 @@device_id: &DeviceId,session_info: &SessionInfo,) {if session_info.previous_refresh_token.is_some() {Forgot to clean up
refreshtoken_refreshtokeninfoI think? Which could be badrefresh_session could panic I think
@ -189,0 +188,4 @@// Save the previous token only if we don't already have one saved// for this device.if !self.db.userdeviceid_previoustoken.contains(&key).await {If you refresh with a current refresh token without having first made a valid API call this breaks:
@ -247,2 +259,4 @@}/// Clear a session's previous refresh token, if it has one.pub fn clear_previous_refresh_token(refresh_session/clear_previous_refresh_token don't have sync. This leaves a race condition when there are two requests with the same refresh token. I think there's also a way to clobber sessioninfo too.
@ -708,0 +777,4 @@panic!("refresh token is not current or previous for its session");}let scope = session_info.scope_string(&refresh_token_info.device_id);This is immediately cleared after? (794)
I'm not sure what this is referring to?
I'm being dumb, ignore me
@ -635,0 +636,4 @@// isn't expired.self.db.userdeviceid_previoustoken.del((&user_id, &device_id));Hmm, calling this unconditionally probably will produce unneeded flushes and stuff
that can't possibly cost more than a couple microseconds of compute time for an operation that is astronomically uncommon relative to the tasks the software spends most of its time doing
@ -210,0 +216,4 @@/// before a token refresh, and therefore should cause a soft-logout.pub async fn is_previous_token(&self, token: &str) -> bool {self.db.userdeviceid_previoustokenPerformance ⚠️ - this can be spammed by an unauthed client and even an invalid token bypasses rate limits
this is not an issue. there will be at most one entry in this keyspace per oauth device, and not making this a bijective map makes the logic vastly simpler.
5c07e7ae323d3b6b2c743d3b6b2c74eb9e09d53b