-
Notifications
You must be signed in to change notification settings - Fork 562
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
Contributor
issuedat
left a comment
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
issuedat
pushed a commit
that referenced
this pull request
Nov 4, 2025
🤖 I have created a release *beep* *boop* --- ## [2.181.0](v2.180.0...v2.181.0) (2025-10-31) ### Features * add `.well-known/openid-configuration` ([#2197](#2197)) ([9a8d0df](9a8d0df)) * add `auth_migration` annotation for the migrations ([#2234](#2234)) ([b276d0b](b276d0b)) * add advisor to notify you when to double the max connection pool ([#2167](#2167)) ([a72f5d9](a72f5d9)) * add after-user-created hook ([#2169](#2169)) ([bd80df8](bd80df8)) * add support for account changes notifications in email send hook ([#2192](#2192)) ([6b382ae](6b382ae)) * email address changed notification ([#2181](#2181)) ([047f851](047f851)) * identity linked/unlinked notifications ([#2185](#2185)) ([7d46936](7d46936)) * introduce v2 refresh token algorithm ([#2216](#2216)) ([dea5b8e](dea5b8e)) * MFA factor enrollment notifications ([#2183](#2183)) ([53db712](53db712)) * notify users when their phone number has changed ([#2184](#2184)) ([21f3070](21f3070)) * **oauthserver:** add OAuth client admin update endpoint ([#2231](#2231)) ([6296a5a](6296a5a)) * properly handle redirect url fragments and unusual hostnames ([#2200](#2200)) ([aa0ac5b](aa0ac5b)) * store latest challenge/attestation data ([#2179](#2179)) ([01ebce1](01ebce1)) * support percentage based db limits with reload support ([#2177](#2177)) ([1731466](1731466)) * webauthn support schema changes, update openapi.yaml ([#2163](#2163)) ([68cb8d2](68cb8d2)) ### Bug Fixes * gosec incorrectly warns about accessing signature[64] ([#2222](#2222)) ([bca6626](bca6626)) * **openapi:** add missing OAuth client registration fields ([#2227](#2227)) ([cf39a8a](cf39a8a)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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