Refresh tokens
| Type | Credential |
|---|---|
| Defined in | RFC 6749, section 1.5 (IETF, October 2012) |
| Security practice | RFC 9700, section 4.14 (January 2025) |
| Sent to | The authorization server's token endpoint only |
| OWASP Top 10 | A07:2025 Authentication Failures |
| Used by | OAuth 2.0 clients, Supabase Auth |
A Supabase app signs a user in and receives two strings. The first, an access token in the form of a JWT, goes with every request to the API and usually stops working after 5 minutes to an hour. The second, a refresh token, goes nowhere until the first one is about to expire. Then the client library sends it to the sign-in server and gets a fresh pair back. By default the session built on this pair never ends.1
The split lets the server give access tokens a short life and a narrow scope, so a leaked one does limited harm. The refresh token carries the full access the user granted, and whoever replays it can mint new access tokens for as long as it stays valid.2
The exchange
In OAuth 2.0, issuing a refresh token is optional and left to the authorization server, the service that signs users in and hands out tokens. When it does issue one, the token arrives together with the first access token. It is usually an opaque string, and it is only ever sent back to the authorization server, never to the APIs that accept access tokens.3
A client that can keep a secret (a server-side app) proves who it is on the same request:3
POST /token HTTP/1.1
Host: server.example.com
Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
Content-Type: application/x-www-form-urlencoded
grant_type=refresh_token&refresh_token=tGzv3JOkF0XG5Qx2TlKWIAThe server checks that the token was issued to that client and is still valid. The client may ask for a narrower scope than the user granted, never a wider one. The server may answer with a new refresh token as well, and the client then has to throw the old one away. The token must travel only over TLS, be kept secret at rest, and be impossible to guess or forge.3
Public clients and rotation
A browser app or an installed mobile app is a public client: it runs on the user's device, cannot keep a secret, and so cannot prove who it is when it sends a refresh token.3 Browser apps receive refresh tokens all the same, with little or no safe place to keep them.4 RFC 9700 makes it a requirement that a public client's refresh tokens are either bound to that client by a key or rotated.2
Binding means the server ties the token to a key held by one client instance, through mutual TLS or DPoP, so a copied token is useless without that key. Rotation means every refresh returns a new refresh token and retires the one just used, while the server remembers which tokens belong to the same chain. If an attacker and the real app both use the same token, one of them presents a retired one. The server cannot tell which party that was, so it revokes the active token, and the user has to sign in again.2
Supabase Auth uses single-use refresh tokens with reuse detection and two exceptions. A token may be used again within 10 seconds, so a server-rendered page and the browser can both refresh with it. If a client presents the parent of the current token, which happens when a response was lost on the network, the server returns the current token instead of ending the session. Any other reuse revokes every refresh token in the session. The check is aimed at tokens that leak through logs (of cookies, request bodies or URL parameters) or through vulnerable third-party servers. It does not cover a session stolen from the device itself.1
Rotation does not stop script that stays on the page. Such script, arriving through cross-site scripting or a compromised third-party file, can take the newest token, then clear the app's copy or wait until the user goes offline. The real app never presents a retired token, and no reuse is detected. The same script can also start a hidden sign-in flow and get a separate set of tokens that rotation and DPoP do nothing about.4
Lifetime and revocation
A stolen refresh token works until it expires, is rotated out or is revoked. In browser apps, lifetimes of hours or days are common.4 Supabase refresh tokens never expire, and a session ends on its own only if the project sets a limit in the Auth settings: Time-box user sessions, Inactivity timeout and Single session per user. The server checks these limits only at the next refresh, so a session can last the configured time plus the life of one access token.1 Refresh tokens should expire once the client has been inactive for some time, and a server may revoke them after a password change or a sign-out at the authorization server.2
Every server that implements token revocation must support revoking refresh tokens, which is how access that outlives its owner gets cut off. Where it can also revoke access tokens, it should cancel those issued from the same grant; where it cannot, the access tokens already handed out keep working until they expire.5 In supabase-js, supabase.auth.signOut() defaults to the global scope and revokes the refresh tokens of every session the user has; signOut({ scope: 'local' }) ends only the current one.6
From as early as 8 August to at least 18 August 2025, an attacker used compromised OAuth tokens of the Salesloft Drift app to export data from Salesforce customers. On 20 August, Salesloft and Salesforce revoked every active access and refresh token of the Drift application.7
Where the token is kept
localStorage is open to every script on the origin, and none of the browser storage APIs (localStorage, sessionStorage, IndexedDB) can keep a token from a script that runs on the page.4 One pattern keeps refresh tokens out of the browser altogether, the backend for frontend: a small server-side part of the app acts as the OAuth client, holds the tokens, and gives the browser only a session cookie marked Secure, HttpOnly and SameSite=Strict.4 The cookie flags are covered in Cookie attributes.
Prompt for a coding agent
Find where this app stores and refreshes sign-in tokens. List every place a refresh token or session is written to localStorage, sessionStorage, IndexedDB, AsyncStorage, a log line or a URL. If all the app logic runs on the server, move the tokens into HttpOnly, Secure, SameSite cookies set by the server; otherwise tell me what stands in the way. Make sign-out revoke the refresh token on the server, not only delete it in the browser. If the app uses Supabase, tell me which session limits (time-box, inactivity timeout) are set. Do not change the sign-in flow itself; list what you changed and what you left alone.
In SecFlash
A sign-in token kept in browser storage shows as SF-SEC-503 on the Security page. In a mobile app, a token saved to unencrypted storage such as AsyncStorage or SharedPreferences is SF-SEC-730, also on the Security page.
See also
- Session management
- Session hijacking
- OAuth 2.0
- Stolen OAuth tokens
- Orphaned access tokens and OAuth grants
- JSON Web Token
- Responding to an administrator account takeover
References
- a b c "User sessions". Supabase Docs. Supabase.
- a b c d IETF (January 2025). "Best Current Practice for OAuth 2.0 Security". RFC 9700. IETF.
- a b c d Hardt, D., ed. (October 2012). "The OAuth 2.0 Authorization Framework". RFC 6749. IETF.
- a b c d e IETF OAuth Working Group (July 2026). "OAuth 2.0 for Browser-Based Applications". draft-ietf-oauth-browser-based-apps-27, work in progress. IETF.
- back Lodderstedt, T., Dronia, S. and Scurtescu, M. (August 2013). "OAuth 2.0 Token Revocation". RFC 7009. IETF.
- back "Signing out". Supabase Docs. Supabase.
- back Google Threat Intelligence Group and Mandiant (26 August 2025, updated 28 August 2025). "Widespread Data Theft Targets Salesforce Instances via Salesloft Drift". Google Cloud Blog.
External links
- Refresh Token Protection, RFC 9700, section 4.14
- User sessions, Supabase Docs