JWT
A JWT (JSON Web Token, RFC 7519) is a compact, URL-safe token format for representing claims between two parties as a signed — and optionally encrypted — JSON object.
Updated: 2026-08-11
Lookup
JWT | Definition |
|---|---|
Header | Base64URL-encoded JSON declaring alg (signing algorithm, e.g. "HS256") and typ (usually "JWT"). |
Payload | Base64URL-encoded JSON containing claims (registered, public, private) — encoded, not encrypted. See the JWT Claims reference. |
Signature | For HS256: HMACSHA256(base64url(header) + "." + base64url(payload), secret). For RS256: an RSA signature over the same input, verified with a public key. |
Examples
Structure of a compact JWT
text
eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyXzEyMyJ9.4Ptu2K5fBW9y3g...
└──── header ────┘.└──── payload ────┘.└── signature ──┘Decoded header
json
{
"alg": "HS256",
"typ": "JWT"
}Common Mistakes
!
Treating the payload as secret
The JWT payload is only base64url-encoded, not encrypted — anyone holding the token can decode and read every claim without a key.
!
Trusting the alg header from the token itself
A verifier that picks its algorithm from the incoming token (rather than a fixed allow-list) is vulnerable to algorithm-confusion attacks. See the JWT Decoding vs Verification guide.
!
Not checking exp / nbf on verification
Decoding a token never validates time-based claims — a verifier must check them explicitly.
!
Storing JWTs in localStorage
localStorage is readable by any script on the page, so an XSS bug can exfiltrate the token; an httpOnly cookie is safer for session tokens.
Related Concepts
JWT