opyebJWTlab

Validating exp, nbf, iat, aud and iss, and handling clock skew

Validation · 6 min read

In one line: The order for validating time claims, audience and issuer, how to set a leeway, and what to do about a token without exp.

A valid signature does not make a token usable. The signature only says the content was produced by the issuer; whether this service should accept it now is a matter of claims.

Time claims

ClaimMeaningRule
expExpirationReject when now is at or after exp
nbfNot beforeReject when now is earlier than nbf
iatIssued atA future value suggests clock drift; far in the past suggests a stale token

All three are Unix epoch seconds. If a string such as "1893456000" arrives, some libraries silently compare wrong or pass the value through, so check the type.

Clock skew

Issuer and verifier clocks always differ slightly. Most libraries accept a clockTolerance or leeway of 60 to 120 seconds. Without a leeway, network delay alone can reject valid tokens; with too much, expired tokens live longer than intended. Start at 60 seconds and tune to the drift you observe.

Audience and issuer

aud names who must accept the token and may be an array, so check that your service identifier is in it. iss names the issuer and must match the trust list exactly. Compare both for exact equality rather than "contains", which avoids prefix and subdomain bypasses.

Missing claims and long lifetimes

  • Without exp, denying by default is safer. An unlimited token cannot be recalled after a leak.
  • An access token living longer than 30 days deserves review; the usual shape is a short access token plus a refresh token.
  • When jti is present, add it to a replay-prevention list so the same token cannot be used twice.

Validation order

  1. Check the structure and Base64URL decoding.
  2. Check alg against the allowlist and select a key.
  3. Verify the signature.
  4. Check iss, aud, exp and nbf with the leeway applied.
  5. Apply service-specific rules such as permissions and the jti revocation list.
leeway = 60  # seconds
if "exp" in claims and now >= claims["exp"] - leeway: reject("expired")
if "nbf" in claims and now + leeway < claims["nbf"]: reject("not yet valid")
if "iat" in claims and claims["iat"] > now + leeway: reject("clock skew")
if claims.get("aud") and "my-service" not in claims["aud"]: reject("audience")
if claims.get("iss") not in trusted_issuers: reject("issuer")

Decoding and signature checks run right here in your browser. The token you paste is not stored.

Open the JWTlab decoder

Frequently asked questions

How should a token without exp be handled?

Denying it by default is safest. If you must accept one, revalidate it against a server-side session at short intervals and fix the issuing policy so exp is always present.

What leeway should I use?

Sixty seconds suits most services. Systems spanning regions or running batch jobs sometimes use 120. Remember that leeway keeps expired tokens alive for exactly that long.

Sources

Read next