Application security

Design refresh-token rotation

JWTs are a token format, not a complete session-security strategy. Safe systems define token purpose, issuer, audience, expiry, key rotation and revocation, then treat refresh-token reuse as a signal that requires an explicit response.

Separate access and refresh-token roles

Keep access tokens short-lived and narrowly scoped. Refresh tokens should be stored more carefully, rotated on use where appropriate, and bound to a server-side session record so they can be revoked independently.

  • Set explicit issuer, audience and expiry checks
  • Use least-privilege access-token scopes
  • Keep refresh-token state revocable

Rotate and detect reuse

On refresh, invalidate the presented token and issue a replacement. Record token-family relationships securely; if an already-used token appears again, revoke the family or session according to the risk policy and require reauthentication.

  • Persist token-family and rotation state securely
  • Make rotation atomic to avoid concurrent refresh races
  • Alert on reuse without logging bearer values

Plan signing-key lifecycle

Restrict algorithm choices, verify signatures against trusted keys, and use key identifiers only to select from a trusted key set. Rotate keys with an overlap window that allows valid tokens to expire while preventing indefinite acceptance of old keys.

  • Allow-list expected signing algorithms
  • Keep private keys in an appropriate secret manager
  • Document rotation, compromise and rollback procedures

Validate session behavior

Test expiry, logout, password reset, account disablement, refresh races and replay. A JWT can remain cryptographically valid after account state changes unless the application has an explicit revocation or short-lived-session strategy.

  • Test logout and administrative revocation
  • Test concurrent refresh requests
  • Monitor anomalous session reuse

Questions to keep in view

Does signing a JWT encrypt its contents?

No. A signed JWT is generally readable by anyone holding it; signing protects integrity, not confidentiality. Do not place secrets or unnecessary personal data in its claims.

Should every application use refresh-token rotation?

The design depends on client type, identity provider and threat model. Follow the provider's current guidance and ensure the chosen mechanism supports revocation, race handling and incident response.