JWT Without Expiry or With an Excessive Lifetime

JSON Web Tokens have no expiry or stay valid for a long time and cannot be revoked, so a stolen token remains usable for days, months or indefinitely.

SeverityLow
CVSS 3.13.7 CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:N/A:N Open in the calculator
CVSS 4.06.3 CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:L/VI:N/VA:N/SC:N/SI:N/SA:N Open in the calculator
CWECWE-613: Insufficient Session Expiration
OWASP Top 10A07:2025 Authentication Failures
MITRE ATT&CKT1550.001 Application Access Token
CategorySecurity Misconfiguration

Description

A JSON Web Token is normally accepted on the strength of its signature and claims alone, without a lookup on the server, so it remains valid until the time in its exp (expiry) claim. The application issues tokens with no exp claim, or with an expiry days, months or years after issue, or verifies tokens without enforcing the expiry. Long lifetimes are often chosen to avoid building a refresh mechanism, and are common in mobile applications and in single-page applications that keep the token in browser storage.

Because most implementations keep no record of the tokens they have issued, logging out, changing the password or disabling the account does not stop an issued token from working, so the user cannot end an attacker's access that way. The weakness does not expose tokens by itself, but it greatly lengthens the time for which a stolen token can be used: a token taken through cross-site scripting, from browser storage on a shared or compromised device, from logs or from a leaked request remains usable long after the theft. The impact therefore depends on how easily tokens could be obtained and what the account can do, and is greater for administrative accounts and for tokens accepted by several services.

The weakness is identified by decoding a token and reading its iat (issued at) and exp claims, and by testing whether the token is still accepted after its stated expiry, after the user logs out and after the password is changed.

Remediation

Keep access tokens short-lived and provide a way to end sessions:

  • Include an exp claim in every token, keep access token lifetimes short (minutes rather than hours or days), and require and enforce exp on verification, rejecting tokens without one. Allow only a small clock skew.
  • Keep users signed in with refresh tokens rather than long-lived access tokens. Hold refresh tokens on the server or in an HttpOnly cookie, replace them each time they are used, and give them an absolute maximum lifetime.
  • Provide revocation: invalidate refresh tokens at logout, password change, account disablement and on request, and where access tokens must stop working at once, check a denylist of revoked token identifiers (jti) or a per-user token version on each request.
  • Where the application needs server-side control over every request, consider opaque session identifiers or reference tokens instead of self-contained JWTs.

Confirm the fix by checking that new tokens carry a short expiry, that expired and revoked tokens are rejected, and that logging out and changing the password end access through existing refresh tokens.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Authentication and Sessions Findings

Every Authentication and Sessions finding