JWT Debugging & Production Security Checklist
Debug expired, rejected, or malformed JSON Web Tokens safely in minutes: inspect header/payload claims locally, fix clock skew, and avoid critical alg:none and storage bugs.
1. Understand the Three Parts of Every Compact JWT
A compact JSON Web Token consists of three Base64URL-encoded strings joined by dots: Header.Payload.Signature. Because Base64URL is reversible encoding rather than encryption, anyone holding the token can decode its header and payload without any key. Start every troubleshooting session by inspecting the decoded JSON locally in our Local JWT Decoder so production session tokens never touch external logging servers.
- Header: Declares token type (
"typ": "JWT") and signing algorithm (such asHS256for symmetric HMAC orRS256/ES256for asymmetric public/private keys) plus optional Key ID (kid) for key rotation. - Payload (Claims): Carries identity and authorization claims including
sub(subject user ID),iss(issuer),aud(intended audience),iat(issued at),nbf(not before), andexp(expiration Unix timestamp in seconds). - Signature: Cryptographic MAC or asymmetric signature binding header + payload together so any tampered bit invalidates the token on the server.
2. Five Fastest Root Causes of 401 Invalid Token Errors
| Symptom | Most Common Cause | Fast Fix |
|---|---|---|
| Token rejected immediately after login | nbf or iat ahead of server clock (clock skew) | Sync NTP & allow 30–60s clock leeway |
| Token rejected as expired in 1970 | exp written in milliseconds instead of seconds | Divide JS Date.now() by 1000 |
| Signature verification fails across microservices | Wrong kid / stale cached JWKS key | Refresh JWKS cache on unknown kid |
| Rejected by one API but accepted by another | aud (audience) or iss mismatch | Match exact issuer URL (watch trailing slashes) |
| Malformed token parser exception | Leading Bearer prefix not stripped | Split Authorization header cleanly before verifying |
3. Non-Negotiable Production JWT Security Rules
- Pin allowed algorithms explicitly on the server: Never trust the token's own
algheader blindly. Whitelist only expected algorithms (e.g.,algorithms: ["RS256"]) to blockalg: noneand RS256-to-HS256 key confusion attacks. - Keep access tokens short-lived (5–15 minutes): Stateless JWTs cannot be revoked easily without a denylist; pair short-lived access tokens with rotating
HttpOnly; Secure; SameSite=Laxrefresh cookies. - Validate
iss,aud, andexpon every request: Skipping audience checks lets a token issued for a low-privilege service authenticate against an admin API sharing the same identity provider. - Never store secrets or PII in payload claims: Keep claims minimal (user ID, roles, expiry) because tokens frequently surface in browser memory or proxy diagnostics.
Verify timestamps quickly in JWT Expiry Checker, convert epoch integers via Unix Timestamp Converter, or test HMAC signatures locally in HMAC-SHA256 Generator.
Frequently Asked Questions
- Why is Date.now() a classic bug when signing JWTs in JavaScript?
- JavaScript Date.now() returns milliseconds, whereas RFC 7519 requires NumericDate timestamps (exp, iat, nbf) in whole seconds.
- Where should web apps store JWT tokens safely?
- Prefer HttpOnly, Secure, SameSite cookies managed by the backend to reduce XSS token-theft exposure compared to plain localStorage.
- Can I inspect a JWT safely without sharing it with third-party websites?
- Yes. Use a strictly client-side decoder like myonlinetools.top/tools/jwt-decoder/ where zero bytes leave your browser.