Identity and access
What is a JWT?
Definition
A JWT is a compact token of three base64url parts — header, payload and signature — carrying claims a receiver can verify without a database lookup.
Also known as: JSON Web Token
JWT in more detail
A JWT looks like three dot-separated blobs. The header names the signing algorithm, the payload holds claims such as sub (the subject), exp (expiry), iss (issuer) and aud (audience), and the signature covers the first two parts. Anyone holding the key can confirm the token was issued by the expected party and has not been altered, which is what makes stateless verification possible across many services.
The most important thing to understand is that signed does not mean secret. The payload is encoded, not encrypted, and anyone with the token can read it — paste one into a decoder and every claim is visible. Never put anything private in a JWT unless you are using JWE, the encrypted variant, which is far less common.
The historical vulnerabilities all come from trusting the token to describe how to check itself. Accepting alg: none, or letting a token declare HS256 when the server holds an RSA public key so the public key gets used as an HMAC secret, both let an attacker mint their own tokens. Verify with an algorithm your code chose, not one the token proposed, and always check exp, iss and aud.
The operational cost is revocation. A stateless token is valid until it expires, so logging a user out or disabling an account does not stop a token already issued. Real systems keep access tokens short-lived — minutes — and pair them with a revocable refresh token or a deny-list, which quietly reintroduces the state JWTs were supposed to avoid.
JWT example
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
eyJzdWIiOiIxMiIsIm5hbWUiOiJBZGEiLCJyb2xlIjoiZWRpdG9yIiwiaXNzIjoi
aHR0cHM6Ly9hdXRoLmV4YW1wbGUuY29tIiwiYXVkIjoiaHR0cHM6Ly9hcGkuZXhh
bXBsZS5jb20iLCJleHAiOjE3MTAwMDAwMDB9.
2s9Kx7T4Gv...
Decoded:
header { "alg": "HS256", "typ": "JWT" }
payload { "sub": "12", "name": "Ada",
"role": "editor",
"iss": "https://auth.example.com",
"aud": "https://api.example.com",
"exp": 1710000000 }
signature HMAC-SHA256(base64(header) + "." + base64(payload),
secret)
The payload is base64url, NOT encrypted. Assume the holder
can read every claim in it.JWT — common questions
- Is a JWT encrypted?
- A standard signed JWT is not. The payload is base64url-encoded and readable by anyone holding the token; the signature only proves it has not been tampered with. Encryption requires the separate JWE format.
- Should I use JWTs instead of sessions?
- Only when statelessness genuinely helps, such as verifying tokens across many independent services. For a single web application, a server-side session with an opaque cookie is simpler, revocable instantly, and avoids the token-storage problem in the browser.
- How do I invalidate a JWT before it expires?
- You cannot, purely with the token — that is the trade-off of stateless verification. The workarounds are short expiry with refresh tokens, a server-side deny-list of revoked token IDs, or a per-user token version that invalidates every earlier token at once.
Keep reading
Every definition in the set is indexed A-Z in the developer glossary, and the cheat sheets cover the syntax once you know what you are looking for.
Browse the A-Z glossary