Behavior of OAuth 2.0 clients when using restored refresh tokens without prior validation
0 reputation · 12 Sept 2024, 10:30 UTC
0 reputation · 12 Sept 2024, 10:30 UTC
Determine whether an OAuth 2.0 client may safely use a refreshed token restored from backup without first confirming its validity with the authorization server.
The OAuth 2.0 specification does not define token storage or backup procedures, leaving validation after restoration to the client implementation. Token introspection (RFC 7662) offers a standardized check but is optional, may be rate‑limited, or unavailable in some deployments. Consequently, designers must weigh the security risk of using a possibly revoked token against the latency and reliability costs of performing an introspection call.
What trade‑offs should guide the decision to skip validation, and under what circumstances is it acceptable to rely on a protected‑resource request to infer token validity?
An OAuth 2.0 client can safely use a restored refresh token only if it is prepared to handle the possible error response from the token endpoint. The specification does not guarantee token validity after restoration; the server will reject a stale or revoked refresh token with an error (typically invalid_grant) and will not issue a new access token. Therefore, skipping pre‑validation is acceptable only when the client can gracefully recover from a failed refresh (e.g., by prompting the user to re‑authenticate) and when the latency or reliability cost of an introspection call outweighs the risk of a failed request.
invalid_grant.The decision to skip validation hinges on two factors:
Relying on a protected‑resource request to infer token validity is only partially reliable. A successful (2xx) response indicates the access token was valid at that moment, but it does not tell you whether the refresh token is still usable for future refreshes. Conversely, a 401 could stem from an expired access token, network issues, or server‑side problems, not solely from a bad refresh token.
invalid_grant), discard the stored refresh token and fall back to a full authentication flow (e.g., redirect to the authorization endpoint).Whether the authorization server implements refresh‑token rotation and returns distinct error codes for revoked vs. expired tokens would affect how granular the client’s error handling can be. If you can confirm this behavior, you may tailor recovery steps (e.g., differentiate between a temporary expiry and a permanent revocation).
Use comments to ask for clarification. Post a solution as an answer.
33,275 reputation · 12 Sept 2024, 15:14 UTC
Restoring a backup rolls client state backwards while the authorization server state has moved forward. With refresh-token rotation enabled, presenting a previously issued token that was already rotated looks like reuse to the server. Current security guidance expects the server to treat reuse as a compromise signal and revoke the whole token family, which can kill a session that would otherwise be healthy.
This is distinct from a simple expiry case. A protected-resource 2xx only confirms the current access token, not the refresh token, so a successful API call does not make a restored refresh token safe to use. A practical check is to compare the backup timestamp against the server’s rotation window and maximum refresh-token lifetime before attempting a refresh, and to treat any token-endpoint error as terminal by discarding stored credentials.