-
Notifications
You must be signed in to change notification settings - Fork 378
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
fix: add reuse interval for token refresh #466
Conversation
3e2d14b
to
e1359ad
Compare
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.
LGTM 🎉
Reuse interval should preferably be set to a value greater than the refresh token interval in gotrue-js
I'm currently defaulting to retrying failed requests after 5s: https://github.com/supabase/gotrue-js/pull/278/files#diff-8c943ccfb5928fff63708e99eaafa93f8845c9405ed8e4b32afed23e5003025aR6 So maybe the default interval should be larger than that? Or we shorten the retries to every second and make the default server interval 5s? Wdyt
@thorwebdev Hmm i think there are 2 cases we need to consider:
I was thinking somewhere between 10-30s to also account for potential delay in network or clock skew. |
🎉 This PR is included in version 2.6.28 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
@kangmingtay can you post here when this version is deployed to hosted Supabase instances? |
hey everyone, we've deployed this update to all hosted Supabase instance already! |
It looks like this solution is mostly just kicking the can down the road. We've handled one specific case i.e. when several clients have the same refresh token and there's a race to refresh them. However, we're not handling the situation where a client refreshes their token twice before another client refreshes theirs once. Client 1 has Token A Client 2: Refresh (Token A)
Client 2: Refresh (Token B)
Client 1: Refresh (Token A)
I'm seeing this in practice. Rather than |
* add reuse interval to config * add test for refresh token reuse detection * fix: add reuse interval to refresh token grant * add tests for reuse interval * refactor token test * ignore reuse interval if revoked token is last token * add test case * refactor query to get child token * remove unnecessary check in refresh token grant * update readme * update example env file
* add reuse interval to config * add test for refresh token reuse detection * fix: add reuse interval to refresh token grant * add tests for reuse interval * refactor token test * ignore reuse interval if revoked token is last token * add test case * refactor query to get child token * remove unnecessary check in refresh token grant * update readme * update example env file
* add reuse interval to config * add test for refresh token reuse detection * fix: add reuse interval to refresh token grant * add tests for reuse interval * refactor token test * ignore reuse interval if revoked token is last token * add test case * refactor query to get child token * remove unnecessary check in refresh token grant * update readme * update example env file
What kind of change does this PR introduce?
.env
underGOTRUE_SECURITY_REFRESH_TOKEN_REUSE_INTERVAL
Assuming the refresh token requests are being made within the reuse interval:
bar
in the request will returnbaz
since it's the previous revoked token.foo
in the request will not returnbaz
since it's the second-last previous revoked token. This will trigger the reuse detection and causebar
andbaz
to be revoked.baz
in the request will create a new refresh token.Other considerations