Validating exp, nbf, iat, aud and iss, and handling clock skew
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
| Claim | Meaning | Rule |
|---|---|---|
exp | Expiration | Reject when now is at or after exp |
nbf | Not before | Reject when now is earlier than nbf |
iat | Issued at | A 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
jtiis present, add it to a replay-prevention list so the same token cannot be used twice.
Validation order
- Check the structure and Base64URL decoding.
- Check
algagainst the allowlist and select a key. - Verify the signature.
- Check
iss,aud,expandnbfwith the leeway applied. - Apply service-specific rules such as permissions and the
jtirevocation 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 decoderFrequently 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
- JWT structure and Base64URL: reading the three parts correctlyWhat the header, payload and signature parts carry, how Base64URL differs from Base64, and where people go wrong when reading a token.
- HS256, RS256, ES256, EdDSA: choosing a signature algorithmSymmetric HMAC versus asymmetric RSA, ECDSA and EdDSA, key and signature sizes, and when to prefer PS256 or ES256.
- alg=none and algorithm confusion: why the header alg is not trustworthyHow alg=none skips signature checking, how algorithm confusion uses a public key as an HMAC secret, and how to defend against both.