06 / 13

Why not make access tokens valid for 30 days?

Long-lived access tokens (e.g., 30 days) greatly increase security risks because they give attackers a wide window to misuse stolen tokens, are hard to revoke, and undermine the principle of least privilege.

Making access tokens valid for 30 days is considered a poor security practice because access tokens are typically sent with every API request, often over networks that may be compromised (e.g., through XSS, man-in-the-middle, or logging). If an attacker steals a 30‑day token, they can impersonate the user for an entire month without any further interaction. Additionally, because access tokens are stateless, revoking them requires a blacklist or a versioning mechanism, adding complexity. Short-lived access tokens (e.g., 15 minutes) limit the damage window, and refresh tokens (longer-lived but stored more securely and revocable) allow the system to reissue fresh access tokens while maintaining user convenience.

Key Reasons Against 30‑Day Access Tokens
  1. 1

    Increased blast radius: A stolen token remains valid for 30 days, giving attackers prolonged access.

  2. 2

    Difficult revocation: Without a stateful mechanism, you cannot invalidate the token once issued.

  3. 3

    Poor user experience: If a user logs out, the access token stays valid until expiration—they remain logged in unless you implement additional revocation logic.

  4. 4

    Violates least privilege: Access tokens should have the minimal necessary lifetime to perform the immediate task, not long-term authorization.

  5. 5

    Encourages bad patterns: Developers might skip implementing refresh token rotation, leading to security gaps.

Contrast with Refresh Token Architecture

In rare scenarios where offline access is required and the system cannot rely on refresh tokens (e.g., mobile apps with very limited connectivity), longer access token lifetimes might be considered, but they should be coupled with aggressive revocation strategies and shorter refresh windows. Even then, 30 days is extreme; 1–7 days is more common for such edge cases. The industry standard for OAuth2 and OpenID Connect is short-lived access tokens combined with refresh tokens for obtaining new ones, balancing security and usability.