Skip to main content
LowAPIOWASP A07:2021CWE-613

How to fix: JWT with a lifetime measured in months

A JWT reachable from this response stays valid for more than 90 days after it was issued. The decoded payload's exp claim is more than 90 days after its iat or nbf.

Why it matters

Expiry is the only revocation a stateless JWT has. A token that lives for months means a copy taken from a log, a browser profile, a crash report, or an old backup keeps working long after the account it belongs to has changed password, lost a role, or been deleted, unless a separate denylist is consulted on every request.

The claims are read by base64url-decoding the payload; no signature verification and no network request is involved, so this says nothing about whether the token is currently valid. Long-lived JWTs are sometimes deliberate, refresh tokens and machine-to-machine credentials are the usual cases, which is why this is Low rather than higher. What it is worth checking is that the long-lived token is a refresh credential held server-side, not an access token being sent to a browser.

How to fix it

  1. 1Keep access-token lifetimes in the minutes-to-an-hour range and use a refresh token for continuity.
  2. 2Give refresh tokens a jti and check it against a server-side store on use, so revocation is possible.
  3. 3Rotate refresh tokens on each use and invalidate the previous one, so a stolen copy stops working after the legitimate client next refreshes.

Code examples

Short access token, revocable refresh token

JavaScript
const accessToken = await new jose.SignJWT({ sub: user.id, scope })
  .setProtectedHeader({ alg: 'RS256' })
  .setIssuedAt()
  .setExpirationTime('15m')
  .sign(privateKey);

const refreshToken = await new jose.SignJWT({ sub: user.id, jti })
  .setProtectedHeader({ alg: 'RS256' })
  .setIssuedAt()
  .setExpirationTime('30d')
  .sign(privateKey);

await db.storeRefreshJti(jti, user.id);   // makes revocation possible

Inspect a token's lifetime

bash
echo "$JWT" | cut -d. -f2 | base64 -d 2>/dev/null | jq '{iat, exp, days: ((.exp - .iat) / 86400)}'

References

Detected automatically by VulnRadar. The check id is api-jwt-long-lived-token, stable across every scan so you can filter or diff on it.

See every api check

Questions

How severe is JWT with a lifetime measured in months?
VulnRadar rates this low severity in the api category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id api-jwt-long-lived-token, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does JWT with a lifetime measured in months map to?
It maps to CWE-613. In the OWASP Top 10 it falls under A07:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for jwt with a lifetime measured in months

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

JWT with a lifetime measured in months fix | VulnRadar