Short-lived 15-minute access tokens limit damage only if the long-lived refresh token behind them cannot be silently replayed for weeks. When SPAs or mobile apps issue static, reusable refresh tokens, a single XSS exfiltration or compromised device backup gives attackers persistent, invisible access alongside the legitimate user without ever tripping an alert.
Key Takeaways
- Refresh Token Rotation issues a brand-new refresh token on every /oauth/token refresh call and immediately invalidates the predecessor.
- Automatic Reuse Detection tracks every rotated token inside a shared token family so replaying any already-spent refresh token triggers instant revocation of the entire family.
- Concurrent refresh calls from multiple browser tabs or flaky mobile retries will falsely trigger reuse detection unless serialized via Web Locks or bounded retry leeway.
- Always pair rotation with both an idle inactivity timeout and an absolute maximum session lifetime so stolen tokens cannot self-renew indefinitely.
Why Static Refresh Tokens Create Silent Account Takeover
To keep users signed in across days without forcing repeated MFA prompts, OAuth 2.0 and OIDC pair short-lived access tokens (5–60 minutes) with long-lived refresh tokens (days or weeks via the offline_access scope). If a refresh token is static and reusable, both the legitimate client and an adversary who copied that token can call POST /oauth/token indefinitely to mint fresh access tokens. Neither the authorization server nor the user sees any error, because every refresh call succeeds cleanly.
For confidential server-side backends, client authentication (client_secret or private_key_jwt) partially raises the bar because a leaked refresh token alone cannot be redeemed without the client's credentials. Public clients—such as browser SPAs and native mobile apps—have no confidential secret, meaning a static refresh token acts as an unguarded skeleton key. OAuth 2.1 therefore requires every refresh token issued to a public client to be either sender-constrained (via DPoP or mTLS) or strictly single-use with rotation and reuse detection.
- Static refresh tokens decouple attacker persistence from the victim's normal activity—even when the victim keeps working, the attacker stays undetected.
- Password changes alone often fail to terminate stolen sessions unless the authorization server explicitly revokes all active refresh token families.
- Public clients cannot rely on client_secret to protect refresh token exchanges, making cryptographic rotation mandatory under OAuth 2.1.
- Refresh tokens should be opaque high-entropy random strings (stored hashed via SHA-256 on the server) rather than self-contained JWTs so state transitions are authoritative.
Token Families and Automatic Reuse Detection: Both Attack Orders
With Refresh Token Rotation, an initial interactive login creates a Token Family identified by a family_id (or root session_id) and mints refresh token RT_1. When the client exchanges RT_1 at /oauth/token, the server atomically marks RT_1 as used and returns a fresh access token plus successor RT_2 in the same family. Crucially, the server retains the hashed identifier of RT_1 (rather than deleting it) so it can distinguish between an unknown garbage string and a previously legitimate token being replayed.
Consider what happens when an attacker steals RT_1 from a browser or device. In Scenario A (attacker moves first), the attacker exchanges RT_1 and receives RT_2; minutes later, when the victim's browser attempts its scheduled refresh using RT_1, the server sees RT_1 is already marked used, recognizes a replay breach, and immediately revokes the entire family—killing the attacker's RT_2 too. In Scenario B (victim moves first), the victim rotates RT_1 into RT_2; when the attacker later attempts to redeem RT_1, the server detects reuse on RT_1 and kills the entire family (RT_1 and RT_2), forcing the victim to re-authenticate cleanly and locking the attacker out permanently.
- Store each refresh token record with token_hash, family_id, parent_id, status (active | consumed | revoked), consumed_at, and absolute_expires_at.
- Perform the status check and transition (active -> consumed) inside an atomic database transaction or Redis Lua script to prevent race-condition double minting.
- When any consumed token is presented outside an explicit grace policy, update the entire family_id to revoked and emit a high-severity security audit event.
- Never tell the caller 'reuse detected' in the public error body—return standard 400 invalid_grant externally while logging full forensic context internally.
# Step 1: Legitimate client rotates RT_1 -> receives RT_2
POST /oauth/token HTTP/1.1
Host: auth.sso.id
Content-Type: application/x-www-form-urlencoded
grant_type=refresh_token&client_id=cp_crm_prod_99182&refresh_token=rt_fam81_gen1_9f2a
HTTP/1.1 200 OK
Content-Type: application/json
{
"access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6InNzb2lkLTIwMjYta2V5LTAxIn0...",
"refresh_token": "rt_fam81_gen2_4c7e",
"token_type": "Bearer",
"expires_in": 900
}
# Step 2: Attacker replays stolen RT_1 -> reuse detected, entire family (including RT_2) revoked
POST /oauth/token HTTP/1.1
Host: auth.sso.id
Content-Type: application/x-www-form-urlencoded
grant_type=refresh_token&client_id=cp_crm_prod_99182&refresh_token=rt_fam81_gen1_9f2a
HTTP/1.1 400 Bad Request
Content-Type: application/json
{
"error": "invalid_grant",
"error_description": "The refresh token is invalid or has been revoked."
}
Solving Multi-Tab Race Conditions and Flaky Network Retries
The number-one engineering complaint after enabling strict Refresh Token Rotation is unexpected user logouts caused by benign race conditions. Imagine a user who has three dashboard tabs open simultaneously: when the shared access token expires at 10:15:00, Tab A and Tab B both fire POST /oauth/token with RT_1 within 20 milliseconds of each other. Tab A wins the race and receives RT_2; Tab B's in-flight request arrives 15 milliseconds later with the now-consumed RT_1, triggering reuse detection and nuking the entire session across all three tabs.
Preventing false positives requires coordination on both the client and server. On the browser side, serialize every refresh attempt across all open tabs using the Web Locks API (navigator.locks) and broadcast the newly minted access token over BroadcastChannel so waiting tabs reuse the fresh token instead of calling /oauth/token again. On the mobile side, where a cellular drop can cause a client to never receive the HTTP 200 response containing RT_2 and retry RT_1 two seconds later, many IdPs configure a tight reuse leeway window (e.g., 3–10 seconds) bound to the exact client/IP fingerprint before escalating to full family revocation.
- Use navigator.locks.request('ssoid_token_refresh', ...) in browser SDKs so only one tab executes the refresh exchange while sibling tabs await the new token.
- Persist the rotated refresh token atomically before returning the new access token to callers—crashing mid-write loses the successor token.
- Configure a narrow server-side leeway window only when mobile network loss is measurable, and keep it under 10 seconds to minimize the replay exposure window.
- Implement single-flight deduplication inside HTTP interceptors so ten parallel API calls receiving 401 trigger exactly one refresh request.
const authChannel = new BroadcastChannel("ssoid_auth_sync");
let cachedTokens: { accessToken: string; expiresAt: number } | null = null;
authChannel.onmessage = (event) => {
if (event.data?.type === "TOKEN_REFRESHED") {
cachedTokens = event.data.tokens;
}
};
export async function getFreshAccessToken(
refreshFn: () => Promise<{ accessToken: string; expiresAt: number }>
): Promise<string> {
if (cachedTokens && Date.now() < cachedTokens.expiresAt - 60_000) {
return cachedTokens.accessToken;
}
// Serialize refresh across all open browser tabs to avoid false reuse revocation
return navigator.locks.request("ssoid_refresh_lock", async () => {
if (cachedTokens && Date.now() < cachedTokens.expiresAt - 60_000) {
return cachedTokens.accessToken;
}
const fresh = await refreshFn();
cachedTokens = fresh;
authChannel.postMessage({ type: "TOKEN_REFRESHED", tokens: fresh });
return fresh.accessToken;
});
}
Never wrap POST /oauth/token?grant_type=refresh_token inside a generic Axios or fetch auto-retry library that retries on 4xx or ambiguous 502/504 timeouts without checking whether rotation already succeeded. Only retry on deterministic pre-request network failures, and immediately route 400 invalid_grant responses to interactive re-login.
Layering Rotation with Idle Timeouts, Absolute Caps, and DPoP
Rotation with reuse detection catches replay whenever two parties race for the same token family, but what if an attacker steals a refresh token from a dormant device that the victim never powers on again? Without lifetime boundaries, the attacker could rotate that family once a day forever. Always configure dual expirations: a sliding idle timeout (for example, 7 or 14 days without refresh) and an immutable absolute session cap (for example, 30 days from original authentication) that forces fresh interactive MFA regardless of rotation count.
For high-assurance financial, healthcare, or enterprise administration apps, layer DPoP (Demonstrating Proof-of-Possession, RFC 9449) or a Backend-for-Frontend architecture on top of refresh rotation. DPoP cryptographically binds both the refresh token and every minted access token to a non-extractable WebCrypto private key stored in IndexedDB on the originating browser, rendering exfiltrated token strings useless on an attacker's machine even before reuse occurs.
- Enforce an absolute session lifetime that never resets on rotation, guaranteeing periodic re-verification of user posture and MFA.
- Stream reuse-detection events straight into your SIEM and alerting pipeline—a confirmed reuse outside a multi-tab race is a high-fidelity indicator of token theft.
- Invalidate all active refresh token families automatically whenever a user resets their password, disables an account, or triggers admin session revocation.
- Combine short access token TTLs (5–15 minutes) with rotating refresh tokens so revoked families lose API access rapidly even on stateless resource servers.
How SSO.ID Protects Sessions with Rotating Refresh Tokens and Live Revocation
SSO.ID issues rotating opaque refresh tokens tied to tracked server-side session records, giving security teams instant visibility and kill-switch control across every browser and mobile device.
- ✓Rotating opaque refresh tokens issued via the offline_access scope at https://auth.sso.id/oauth/token with configurable idle and absolute lifetimes.
- ✓Built-in multi-tab session coordination inside @sso-id/spa-js so concurrent browser tabs never collide during silent token renewal.
- ✓Real-time per-device session inspection (GET /api/users/{userId}/sessions) and instant single-session or tenant-wide revocation (DELETE /api/users/{userId}/sessions/revoke-all).
- ✓Structured authentication and revocation audit telemetry accessible via /api/audit-logs and /api/users/{userId}/activity for SIEM alerting.
Frequently Asked Questions
Stateless JWT access tokens remain valid until their exp claim unless your API gateway checks a revocation denylist or uses token introspection. Keeping access token lifetimes short (5–15 minutes) ensures that once the refresh token family is killed, the attacker's remaining access window closes quickly.
Any XSS script or compromised third-party dependency running on your origin can synchronously read localStorage and exfiltrate the refresh token. If you cannot use a Backend-for-Frontend (BFF) HttpOnly cookie, keep tokens strictly in memory or bind them with non-extractable WebCrypto DPoP keys.
Legitimate multi-tab collisions originate from the exact same IP address, TLS fingerprint, and User-Agent within a few hundred milliseconds. Real replay attacks typically show distinct source ASNs, geolocations, or User-Agent strings—or occur minutes to hours apart.