Read a JWT without trusting it
A JWT's claims are readable by anyone holding it. What decoding proves and what it does not, the alg:none and algorithm-confusion failures, and why exp keeps looking expired.
Ashish S Kumar5 min read
A JWT arrives, something rejects it, and you need to know why. The instinct is to paste it into a decoder and read the claims — which is fine, and is most of what debugging a token involves. The thing worth being precise about is that reading a token and trusting a token are entirely separate operations, and only one of them can be done in a web page.
Three segments, two of them plain text
A JWT is three base64url segments joined by dots. The first is a JSON header naming the signing algorithm. The second is the payload — the claims. The third is the signature over the first two.
That follows directly from the encoding: base64url is reversible by anyone, as covered in base64 is not encryption. The practical rule is to put nothing in a token you would not be comfortable showing its bearer — no internal flags, no other users' identifiers, no reasoning you would rather not explain.
Read a token's header and claims
Runs in your browser — nothing is uploaded. Open the full jwt decoder
Decoding is not verifying
Decoding splits the string and base64url-decodes two JSON objects. It requires nothing but the token. Verifying recomputes the signature over the header and payload using a key, and compares it to the third segment. It requires the key, and it is the only step that establishes the token was issued by who it claims and has not been altered.
A decoder that shows you claims has told you what the token says. It has not told you the token is genuine. Those are different sentences and conflating them is how tokens get trusted in the wrong place.
- 1Verification belongs on the server, against a key that never leaves it.
- 2A client may decode a token to read an expiry or a display name. It must never decide permissions from one.
- 3Any page offering to verify a signature is asking for your signing secret. Do not give a production secret to a web page, including this one — which is why the decoder here does not ask.
The two failures worth knowing
alg: none
The specification permits an unsecured JWT whose header declares `"alg": "none"` and whose signature segment is empty. It exists for cases where integrity is already guaranteed by the transport. A library that honours that header when it should be demanding a signed token will accept a forged payload from anyone. If you see `none` in a header on a token that is supposed to be authenticating something, that is the bug.
Algorithm confusion
The other classic is a verifier that reads the algorithm out of the token rather than deciding it in advance. Given an endpoint expecting RS256, an attacker changes the header to HS256 and signs the token using the RSA public key as an HMAC secret. The public key is public; the verifier obligingly checks it the way the token asked. The fix is the same in both cases: the server decides which algorithm and which key are acceptable, and the token's header is input to be validated, not instruction to be followed.
Reading the claims that actually matter
Most registered claims are self-explanatory. The three that cause real confusion are the time-based ones, because they are NumericDate values — seconds since the Unix epoch, not milliseconds.
| Claim | Means | Common mistake |
|---|---|---|
| exp | Expires at — reject at or after this | Comparing against Date.now(), which is in milliseconds |
| nbf | Not before — reject until this | Ignoring it, so an early token is accepted |
| iat | Issued at | Treating it as expiry |
| aud | Intended audience | Not checking it, so a token for another service is accepted |
| iss | Issuer | Not checking it against an expected value |
A token that "expired immediately" is very often a thousand-fold unit mismatch rather than a clock problem. If you want to sanity-check a raw exp value by hand, the timestamp converter will read it in both units and make the error obvious.
The second most common cause is genuine clock skew between the issuing and verifying machines. Most libraries allow a small leeway — thirty to sixty seconds is typical — and enabling it removes a class of intermittent failures that are otherwise very hard to reproduce.
Handling a token you are debugging
A bearer token is a credential. Until it expires, anyone holding it is you. That has a few practical consequences when something is broken and you are pasting tokens around.
- Do not paste a production token into a chat thread, a ticket or a pull request. It will outlive the conversation.
- Prefer a token from a staging environment or a throwaway account when reproducing a problem.
- If a real one has been shared, revoke the session rather than waiting for expiry.
- Check where a decoder does its work. One that runs in your browser and sends nothing is fine; one posting to a server is a credential leak with a friendly interface.
Frequently asked questions
- Can I decode a JWT without the secret?
- Yes, entirely. The header and payload are base64url-encoded JSON and need no key to read. The secret is required only to verify the signature, which is a separate step proving the token has not been altered.
- Is it safe to paste a JWT into an online decoder?
- Only if the page does the work locally and sends nothing. Even then, the safe habit with a production token is to assume any page might transmit it and use a local command instead. Never paste a signing secret anywhere.
- Why does my token look expired when it is not?
- Usually a units mismatch. `exp` is in seconds since the epoch, while JavaScript's `Date.now()` is in milliseconds. Comparing them directly makes every token look long expired. The other cause is clock skew between servers, which a few seconds of configured leeway fixes.
- What does alg: none mean?
- It declares an unsecured JWT with no signature. It is valid in the specification for contexts where integrity is guaranteed elsewhere, but a verifier that accepts it on an authentication token will accept anything a caller invents.
- Should I store a JWT in localStorage?
- It is readable by any script running on the page, so a single cross-site scripting flaw exposes it. An HttpOnly cookie is not reachable from JavaScript and is the safer default for a session credential, at the cost of needing CSRF protection.
Sources
Tools from this guide
More on developer tools
- UUID v4 or v7 for database keysRandom v4 keys scatter writes across a B-tree and slow inserts as tables grow. v7 sorts by time and fixes that, but leaks creation time. Use v7 internally, v4 in public.5 min
- Base64 is not encryptionBase64 is a transport encoding with no key and no secrecy. What the padding means, why base64url exists, the Unicode trap in btoa, and when to reach for a hash instead.5 min