A JWT (JSON Web Token) is a small signed note that says who you are, and in almost every case it is not encrypted. Anyone who gets hold of the token can read everything inside it. The signature only proves that nobody changed the contents since the server issued them.
That surprises a lot of people, because a JWT looks like random gibberish. It's encoded, which is a reversible formatting step, not encryption.
What a JWT looks like
A JWT is three pieces of text joined by dots:
eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI0MiIsIm5hbWUiOiJBbGV4In0.k1m2...
| Part | Contains | Readable by anyone? |
|---|---|---|
| Header | The signing algorithm, like HS256 |
Yes |
| Payload | The claims: user ID, name, roles, expiry | Yes |
| Signature | A cryptographic seal over the first two parts | It's not meant to be read |
The header and payload are JSON written in Base64URL, a way of turning data into URL-safe characters. Decoding it takes no key and no password. Paste a token into a decoder and the claims appear immediately.
What the claims mean
The payload holds claims, which are statements about the user and the token. A few names are standard, defined in RFC 7519:
sub: the subject, usually a user ID.iss: the issuer, the service that created the token.aud: the audience, the service the token is meant for.exp: the expiry time, after which the token must be rejected.iatandnbf: when the token was issued, and the time before which it's not valid.
Times are Unix timestamps, counted in seconds since 1 January 1970. Apps add their own claims too, such as roles or a plan name.
Is a JWT encrypted?
Usually not. The JWT you meet in a login flow, an API request or a cookie is almost always a signed token, known in the specs as a JWS. Signing protects integrity: if anyone changes a single character of the payload, for example to turn "role":"user" into "role":"admin", the signature no longer matches and the server rejects the token.
An encrypted JWT, called a JWE, exists, but it's much rarer. It has five dot-separated parts instead of three, and its contents are unreadable without the key. If your token has three parts and the middle one decodes to readable JSON, it isn't encrypted.
So the rule for developers is simple: treat everything in a signed JWT's payload as public.
What should never go in a JWT
Since the payload is readable, leave out anything you wouldn't show to whoever holds the token, or to anyone who finds it in a log file or a browser's storage:
- Passwords or password hashes.
- API keys, secrets and tokens for other services.
- Personal details the client doesn't need, such as home addresses, ID numbers or health data.
- Internal information that helps an attacker, like database hostnames or internal user flags.
Put a user ID in the token and look up the sensitive details on the server when you need them.
How the signature keeps a JWT honest
The server creates the signature with a key. Two families are common:
1. HMAC (HS256, HS384, HS512)
One shared secret both signs and verifies. Only servers that hold the secret can make valid tokens, so the secret must be long and random. A short or guessable secret can be cracked offline from a single token, after which an attacker can sign any claims they like.
2. Public key (RS256, ES256 and others)
A private key signs, and a public key verifies. Any service can check tokens with the public key, but only the holder of the private key can create them. This suits setups where several services check tokens issued by one sign-in service.
The mistakes that break JWT security
Most JWT attacks exploit the verifying code, not the cryptography. The JWT best current practices, RFC 8725, list the ones that keep recurring:
- Trusting the token's own
alg. A token can claim"alg":"none", meaning unsigned. Some libraries once accepted that and skipped the check. Fix the allowed algorithm on the server and reject anything else. - Decoding without verifying. Reading the payload is not the same as checking it. Use your library's verify function, not its decode function, before trusting a claim.
- Ignoring expiry and audience. A valid signature on an expired token, or on a token meant for another service, should still fail. Check
exp,issandaud. - Weak HMAC secrets. A secret like
secret123turns the signature into a formality. Use at least 32 random bytes.
Frequently asked questions
Is it safe to paste a JWT into an online decoder?
Only into one that decodes in your browser and doesn't send the token anywhere. A live token works like a temporary password until it expires: anyone who copies it can act as that user. For production tokens, prefer a local tool, or wait until the token has expired before inspecting it.
Can someone change a JWT and still use it?
Not if the server verifies it properly. Changing the payload breaks the signature, and the server should reject the token. The risk comes from servers that skip verification, accept alg: none, or use a secret weak enough to guess, since then an attacker can produce a new valid signature.
Should I store a JWT in localStorage or a cookie?
A cookie marked HttpOnly, Secure and SameSite keeps the token out of reach of page scripts, which protects it if an attacker injects JavaScript. Tokens in localStorage are readable by any script on the page. Cookies bring their own work, such as protecting against cross-site requests, so follow your framework's recommended setup.
How do I log someone out if JWTs can't be revoked?
A signed token stays valid until exp, even after logout. Keep access tokens short-lived, minutes rather than days, and pair them with a refresh token the server can revoke. For immediate lockout, the server can also keep a short list of revoked token IDs and check it on each request.
Inspect a token safely
Paste a token into the JWT decoder to read its header and claims and see whether it has expired. Everything happens in your browser. For HS256, HS384 and HS512 tokens it can also check the signature with your secret, and the HMAC generator shows how such a signature is made.