JWT expiration best practices - cover art

JWT and security 13 min read

JWT expiration best practices

November 6, 2026 · 13 min read

Without exp, a stolen JWT works until keys rotate - unacceptable for browser clients. Expiration is the primary revocation mechanism for stateless access tokens. This guide covers claim semantics, refresh pairing, and operational tolerance for clock skew.

The exp claim

exp is NumericDate seconds since epoch. Verifiers must reject tokens where exp is in the past unless within configured leeway. Always set exp at issuance; never rely on clients to discard tokens early.

nbf, iat, and not-before windows

nbf blocks use before a scheduled time - handy for staged rollouts. iat documents issuance; some policies reject tokens older than N hours regardless of exp to limit long-lived stolen tokens.

Choosing access token TTL

Refresh tokens and rotation

Refresh tokens are opaque, stored HttpOnly, rotated on each use, and revocable server-side. Detect reuse to spot theft. Access JWT expiry stays short; user sessions persist via refresh, not by setting exp years ahead.

Clock skew leeway

Allow small leeway (30–120 seconds) for exp and nbf across distributed hosts. Sync NTP on servers. Debug “token expired” reports with the JWT decoder to compare wall clock with claim timestamps.

FAQ

What happens when exp passes mid-request?
Validators should reject at check time. Long uploads may need refresh before starting or tolerate brief overlap.
Should refresh tokens be JWTs?
Often opaque random strings stored server-side. If JWT, still require rotation and revocation tracking.
Can I revoke before exp?
Requires denylist, short TTL, or session version claim checked against database.

Related: How JWT expiration works · JWT best practices for APIs · JWT storage in browsers · Debugging JWT signatures

Browse all tools