-
Notifications
You must be signed in to change notification settings - Fork 558
feat: introduce v2 refresh token algorithm #2216
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hf
commented
Oct 17, 2025
2cabb9f to
fdcf9ab
Compare
hf
commented
Oct 22, 2025
hf
commented
Oct 22, 2025
cemalkilic
reviewed
Oct 23, 2025
Pull Request Test Coverage Report for Build 18907392822Details
💛 - Coveralls |
issuedat
approved these changes
Oct 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work 👏 Some great test coverage too! Left a few comments but nothing majorly blocking on my end.
staaldraad
approved these changes
Oct 28, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Introduces v2 of a refresh token algorithm.
Goals
refresh_tokenstable is that it's huge and difficult to clean up without impacting IO performance.Configuration Options
GOTRUE_SECURITY_REFRESH_TOKEN_ALGORITHM_VERSIONGOTRUE_SECURITY_REFRESH_TOKEN_ALLOW_REUSEImplementation
Refresh tokens now encode the session ID + counter value, which is then signed by a per-session HMAC key. By comparing the state in the session and the counter in the refresh token, we can identify whether a refresh token is being used properly or it's being reused. We can also identify what type of reuse is going on.
If the refresh token counter is the previous refresh token, it means the client failed to save the last response. This is always allowed.
If the refresh token counter is older than the previous refresh token, then it's being reused. Reuse is allowed only if the client is refreshing the same session within the
GOTRUE_SECURITY_REFRESH_TOKEN_REUSE_INTERVAL.To ensure a non-synchronized client synchronizes to the correct refresh token state, the session's refresh token counter is incremented only on valid refresh token use.
Please check the massive suite of tests (>700 LOC) which exercise every possible combination to ensure correctness of the algorithm. The coverage here is above 95% (of the lines that can be covered).
Observability and Debuging
Requests that create a session and refresh a session will now receive these response headers:
sb-auth-user-idsb-auth-session-idsb-auth-refresh-token-countersb-auth-refresh-token-prefixsb-auth-refresh-token-reuse-causesb-auth-refresh-token-rotation