Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

Invalidate access tokens when session id changes#1142

Merged
eritbh merged 2 commits into
masterfrom
fix/oauth-token-account-switching-hack
Feb 5, 2026
Merged

Invalidate access tokens when session id changes#1142
eritbh merged 2 commits into
masterfrom
fix/oauth-token-account-switching-hack

Conversation

@eritbh
Copy link
Copy Markdown
Member

@eritbh eritbh commented Feb 5, 2026

Previously we didn't bother caching our OAuth access token because we grabbed it directly out of a cookie in new Modmail, and that was cheap. Modmail went away and #1138 lets us get a token from Shreddit by exchanging a CSRF token for an access token, but this means making a request to Shreddit in order to use an access token, so we now cache the token. Caching the token without being aware of when the Reddit session changes causes issues where Reddit invalidates the token when the user logs out, but Toolbox doesn't know and continues to make requests with the bad token until it was originally supposed to expire.

This PR hacks around this by using part of the reddit_session cookie as the storage key for the cached access token, meaning that a new access token will be retrieved whenever the session changes. This makes Toolbox work again when switching accounts.

Also fixes the per-user cache logic to decode the new reddit_session format and get the current user's base36 ID from it (it's now a JWT and not just a random string of values, with the user's fullname as the JWT subject).

@eritbh eritbh added bug something isn't working core: background labels Feb 5, 2026
@eritbh eritbh merged commit e250ab4 into master Feb 5, 2026
2 of 3 checks passed
@eritbh eritbh deleted the fix/oauth-token-account-switching-hack branch February 5, 2026 07:07
eritbh added a commit that referenced this pull request Feb 5, 2026
* invalidate access token when session id changes

* also update cache logic to decode new jwt format of reddit_session
@eritbh
Copy link
Copy Markdown
Member Author

eritbh commented Feb 5, 2026

backported to 6.1 as e90b135

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug something isn't working core: background

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant