Skip to content

0001: Stateless JWTs with per-user token versioning

Status: Accepted

Context

Pure stateless JWTs cannot be revoked before they expire. That makes logout, password changes and deactivation ineffective until the token times out. A server-side session store would fix this, but it adds infrastructure (for example Redis) and a lookup on every request.

Decision

  • Issue short-lived access tokens and longer-lived refresh tokens, both HS256 JWTs carrying typ, iss, aud, jti and ver.
  • ver must equal user.token_version, which is checked on every request (the user row is loaded anyway).
  • Incrementing token_version revokes every token for that user. This happens on logout, password change or reset, deactivation and role change.
  • Password-reset tokens are a separate typ and become invalid after one use (the reset increments token_version).

Consequences

  • Revocation is per user ("sign out everywhere"), not per device. Per-device sessions would need a session table keyed by jti.
  • Refresh tokens rotate (each refresh returns a new pair), but old refresh tokens stay valid until expiry or the next version bump; there is no reuse detection.
  • Rotating SECRET_KEY invalidates every token. Asymmetric keys (RS256/EdDSA with a JWKS endpoint) are the upgrade path if other services need to verify tokens.