API security

API refresh token rotation and replay detection

Access lifetime: key, clock, server arranged to illustrate api refresh token rotation and replay detection.

Refresh token handling determines how long a stolen session can be extended. Understanding API refresh token rotation and replay detection helps establish which security property the feature needs and where that property is actually enforced.

What does this involve?

Session and token controls preserve an authentication decision over time. They need a defined scope, lifetime and invalidation policy. A token should be accepted because a trusted service has verified the relevant properties, not simply because its structure looks familiar.

Why it matters

Consider a realistic failure: a previously rotated refresh token still creates new access tokens.

A reusable credential can let someone continue acting as an account after the intended access should have ended. Long-lived access, excessive token contents and inconsistent revocation can increase the exposure beyond the initial event.

An API review follows the server-side behaviour behind the interface. Direct requests, alternate methods and background operations can reveal boundaries that the normal frontend journey does not exercise.

How penetration testers check for it

Check reuse detection, concurrent refreshes, revocation and logout behaviour.

  • Confirm that the authorisation server validates redirect URIs based on a client-specific allowlist of pre-registered URIs using exact string comparison.
  • Verify that, if the authorisation server returns the authorisation code in the authorisation response, it can be used only once for a token request. For the second valid request with an authorisation code that has already been used to issue an access token, the authorisation server must reject a token request and revoke any issued tokens related to the authorisation code.
  • Confirm that the authorisation code is short-lived. The maximum lifetime can be up to 10 minutes for L1 and L2 applications and up to 1 minute for L3 applications.
  • Confirm that for a given client, the authorisation server only allows the usage of grants that this client needs to use. Note that the grants 'token' (Implicit flow) and 'password' (Resource Owner Password Credentials flow) must no longer be used.
  • Confirm that the authorisation server mitigates refresh token replay attacks for public clients, preferably using sender-constrained refresh tokens, i.e., Demonstrating Proof of Possession (DPoP) or Certificate-Bound Access Tokens using mutual TLS (mTLS). For L1 and L2 applications, refresh token rotation may be used. If refresh token rotation is used, the authorisation server must invalidate the refresh token after usage, and revoke all refresh tokens for that authorisation if an already used and invalidated refresh token is provided.
  • Verify that, if the code grant is used, the authorisation server mitigates authorisation code interception attacks by requiring proof key for code exchange (PKCE). For authorisation requests, the authorisation server must require a valid 'code_challenge' value and must not accept a 'code_challenge_method' value of 'plain'. For a token request, it must require validation of the 'code_verifier' parameter.
  • Confirm that if the authorisation server supports unauthenticated dynamic client registration, it mitigates the risk of malicious client applications. It must validate client metadata such as any registered URIs, ensure the user's consent, and warn the user before processing an authorisation request with an untrusted client application.
  • Confirm that refresh tokens have an absolute expiration, including if sliding refresh token expiration is applied.
  • Confirm that refresh tokens and reference access tokens can be revoked by an authorised user using the authorisation server user interface, to mitigate the risk of malicious clients or stolen tokens.
  • Confirm that confidential client is authenticated for client-to-authorised server backchannel requests such as token requests, pushed authorisation requests (PAR), and token revocation requests.
  • Confirm that the authorisation server configuration only assigns the required scopes to the OAuth client.
  • Confirm that for a given client, the authorisation server only allows the 'response_mode' value that this client needs to use. For example, by having the authorisation server validate this value against the expected values or by using pushed authorisation request (PAR) or JWT-secured Authorisation Request (JAR).
  • Confirm that grant type 'code' is always used together with pushed authorisation requests (PAR).
  • Confirm that the authorisation server issues only sender-constrained (Proof-of-Possession) access tokens, either with certificate-bound access tokens using mutual TLS (mTLS) or DPoP-bound access tokens (Demonstration of Proof of Possession).
  • Verify that, for a server-side client (which is not executed on the end-user device), the authorisation server ensures that the 'authorisation_details' parameter value is from the client backend and that the user has not tampered with it. For example, by requiring the usage of pushed authorisation request (PAR) or JWT-secured Authorisation Request (JAR).
  • Confirm that the client is confidential and the authorisation server requires the use of strong client authentication methods (based on public-key cryptography and resistant to replay attacks), such as mutual TLS ('tls_client_auth', 'self_signed_tls_client_auth') or private key JWT ('private_key_jwt').
  • Test logout, permission changes and credential replacement.
  • Inspect replay and concurrent use according to the documented design.

How to fix it

Rotate safely, detect reuse where required and revoke the intended session chain.

  • Use appropriately scoped credentials with bounded lifetimes.
  • Validate trusted issuance and relevant claims consistently.
  • Rotate and revoke according to the session model.
  • Keep credentials out of unnecessary URLs, logs and persistent copies.

Some designs intentionally use short-lived credentials without immediate global revocation. Assess the complete lifetime and access model before calling that design a failure.

Recheck the changed behaviour against the original failure conditions and the legitimate user journey. Keep enough evidence to show which release and configuration were verified, and include related entry points that depend on the same security decision.

Read about our methodology or contact pentested.com to discuss your APIs and integrations.

See your first test report this week.

Book a 30 minute demo. We will verify one of your targets with you and run a test against it, so you can judge the results on your own systems.

Book a demo