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.

2. Five Fastest Root Causes of 401 Invalid Token Errors

SymptomMost Common CauseFast Fix
Token rejected immediately after loginnbf or iat ahead of server clock (clock skew)Sync NTP & allow 30–60s clock leeway
Token rejected as expired in 1970exp written in milliseconds instead of secondsDivide JS Date.now() by 1000
Signature verification fails across microservicesWrong kid / stale cached JWKS keyRefresh JWKS cache on unknown kid
Rejected by one API but accepted by anotheraud (audience) or iss mismatchMatch exact issuer URL (watch trailing slashes)
Malformed token parser exceptionLeading Bearer prefix not strippedSplit Authorization header cleanly before verifying

3. Non-Negotiable Production JWT Security Rules

  1. Pin allowed algorithms explicitly on the server: Never trust the token's own alg header blindly. Whitelist only expected algorithms (e.g., algorithms: ["RS256"]) to block alg: none and RS256-to-HS256 key confusion attacks.
  2. 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=Lax refresh cookies.
  3. Validate iss, aud, and exp on every request: Skipping audience checks lets a token issued for a low-privilege service authenticate against an admin API sharing the same identity provider.
  4. 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.