Skip to main content

How JWT Works and Common Security Mistakes

Understand JWT header, payload, signature verification, Base64URL encoding, and how to prevent alg:none and key confusion.

Updated 2026-11-28

Anatomy of a signed JWT (JWS)

A compact JWS consists of three Base64URL-encoded segments separated by dots: header, payload, and signature. Because Base64URL is encoding rather than encryption, anyone holding the token can inspect its claims locally. Use JWE if the payload itself must stay confidential.

Decoding vs verifying

Decoding reads the header and payload claims without checking authenticity. Verification recomputes or checks the cryptographic signature against an expected HMAC secret (HS256/384/512) or asymmetric public key (RS256, ES256, EdDSA) and validates `exp`, `nbf`, `iss`, and `aud`.

Common production mistakes

Never accept `alg: none` in production. Pin the expected algorithm on the verifier so an attacker cannot trick an RS256 verifier into treating a public key as an HS256 shared secret. Keep access token lifetimes short and never place passwords or sensitive PII in standard JWT payloads.

Try the related tools