A JSON Web Token looks like a block of random characters, and that appearance leads people to treat it as a sealed envelope. It is not. The first two parts of a typical JWT are readable by anyone who has the token, with no key and no effort. Reading a token and trusting a token are two different operations, and confusing them is behind a great many authentication bugs.
What is inside
A JWT is three parts separated by dots: header.payload.signature. Take this well-known example token:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
The first two parts are JSON, encoded with Base64URL. Decoded, the header is:
{ "alg": "HS256", "typ": "JWT" }
and the payload is:
{ "sub": "1234567890", "name": "John Doe", "iat": 1516239022 }
Nothing was needed to read them except a decoder. Base64URL is the URL-safe variant of Base64 that uses - and _ and drops the trailing = padding (the padding article explains why). It is an encoding, not encryption, and as Base64 is not encryption puts it, if a tool can reverse it with no key, so can everyone else.
The JWT decoder on this site does exactly this decode, in the browser, and shows the claims in readable form.
The third part, the signature, is the only thing that provides any guarantee. It is computed from the header and payload using a secret or a private key. Changing a single character of the payload invalidates it, but only if someone checks.
Why a decoded token proves nothing
Because anyone can decode a token, anyone can also build one. An attacker can write a header and payload of their choosing, encode them, and attach any signature. A system that decodes the token and believes what it finds has authenticated nothing. Decoding answers "what does this token claim?" Verification answers "can I trust that claim?"
The decoder here makes this explicit: it does not verify signatures, because that requires your secret or public key, which should not be pasted into any web page.
What verification actually involves
A server that accepts a JWT needs to do all of the following. Skipping any of them is a known way to be compromised.
- Verify the signature, with a key you chose. The key must come from your own configuration, never from the token. Header fields such as
jkuorjwkcan point at attacker-controlled keys if a library honours them blindly. - Insist on the algorithm you expect. Do not let the token choose. The infamous
alg: noneattack worked against libraries that accepted a token declaring it had no signature, and a related confusion attack tricked servers into treating an RSA public key as an HMAC secret. Allow a fixed list of algorithms and reject everything else. - Check the time claims.
expis when the token stops being valid, andnbfis when it starts. Both are timestamps in seconds, a detail covered in Unix timestamps. Allow a small clock skew rather than none. - Check the audience and issuer.
audsays who the token is for andisssays who issued it. A perfectly valid token from one service should not be accepted by another that it was never meant for.
In Node with the jsonwebtoken library, all four checks are options to a single call:
const claims = jwt.verify(token, publicKey, {
algorithms: ["RS256"], // fixed list, chosen by you
audience: "my-api", // who the token must be for
issuer: "https://login.example.com",
});
The key and the algorithm list come from your configuration, and exp and nbf are checked automatically. If any check fails the call throws, and the request must be rejected rather than carried on with the unverified claims.
The IETF's JSON Web Token Best Current Practices (RFC 8725) collects these and more. The base specification is RFC 7519.
Keep secrets out of the payload
Because the payload is readable by anyone holding the token, it must not contain anything you would not show the token's holder. That includes the person using the browser, who can open their own storage and read it. Put identifiers and permissions in a token, not passwords, personal data or internal details. If a token genuinely needs encrypted contents, the standard has a separate form for that, JSON Web Encryption (JWE), and it is a different thing from the signed tokens above.
Tokens are credentials
A live token is a bearer credential: whoever holds it can act as the user until it expires. That is why you should think twice before pasting one into an unfamiliar website. A decoder that sends your token to a server has just handed that server a working key.
This site's decoder runs entirely in your browser and sends nothing, and you can confirm that in the Network tab of your developer tools. Even so, a sensible habit is to decode test tokens or expired ones. If you must inspect a real token, treat it as compromised afterwards if it was long-lived.
The short version
- Decoding shows what a token claims. It proves nothing.
- Trust comes only from verifying the signature with your own key, a fixed algorithm, and the time, issuer and audience checks.
- Never put anything secret in the payload.
- Treat live tokens like passwords.
For the time claims, the JWT decoder converts exp and iat to dates and tells you whether a token has expired. If you need to produce a hash while debugging, the hash generator handles SHA-256 and others in the browser.