Decoding is not verification: what a JWT can and cannot prove
A JWT is often described as self-contained, and that is true in a narrow sense: it carries claims and a signature in one string. It is not self-authenticating. The first two segments are base64url, which is a reversible encoding, not encryption and not a signature. Anyone who can type can produce a syntactically perfect token with any subject, role or expiry they like. The only thing that separates their token from a real one is the third segment.
Decoding answers the question what does this token say? Verification answers who could have written it, and may I act on it now? These are different questions, and confusing them is one of the most common JWT mistakes in production code. A log line that prints a decoded payload is fine; an authorisation decision based on it is a vulnerability.
What decoding gives you
Decoding splits the token, base64url decodes the header and payload, and parses JSON. It is deterministic and needs no key. It is useful to display claims during debugging, to read iss and kid so you can choose the right key, and to detect malformed tokens before verification. It can also show that a token is expired, which explains a 401 without any cryptography.
What it cannot give you is any assurance of origin. A payload of {"sub":"admin","scope":"write"} looks exactly as convincing whether it came from your identity provider or from an attacker's text editor. The decoded text is data, not evidence.
What verification establishes
Verification recomputes the signature over the exact header.payload bytes and compares it with the third segment using the algorithm named in your configuration, not the algorithm named in the token. For HMAC it uses a shared secret; for RSA, ECDSA and EdDSA it uses a public key. If the comparison succeeds, the holder of the corresponding private key or secret produced these bytes and nobody has changed them since.
That is a strong statement, but it is also narrow. It does not say the key belongs to your issuer. It does not say the token is current. It does not say the subject exists, is enabled, or may delete the record in the request. Those are separate checks, and skipping them turns a valid signature into an authorisation bypass.
The five checks a server should make
| Order | Check | What it prevents |
|---|---|---|
| 1 | Parse the token and read the header without trusting it | Malformed input, wrong token type |
| 2 | Select a key by kid or issuer from a trusted set | Use of an attacker-supplied key |
| 3 | Reject algorithms outside a fixed allowlist and verify the signature | alg none, RS256→HS256 confusion |
| 4 | Compare iss and aud with expected values | Token replay across services or tenants |
| 5 | Check exp, nbf and iat with a small clock skew | Expired or not-yet-valid tokens |
The order matters less than the fact that all five happen before any business logic. A common failure is to verify the signature correctly and then forget aud, so a token minted for a staging API is accepted by production. Another is to trust iss from the token instead of comparing it with a configured value.
A worked example of tampering
Load the sample token in the verifier and change one character of the payload, for example the last digit of sub. The header and payload still decode, the claim table still renders, and the audit may still look clean. The signature check fails immediately, because the signing input changed. This is the experiment to run whenever someone claims that a token was forged: decoding alone will never show it, verification will.
The reverse experiment is also useful. Take a token signed with a different secret and verify it with the wrong one: the bytes are all valid base64url and the JSON is perfect, yet the result is a mismatch. That is what a wrong key looks like in production, and it is why the error message should distinguish malformed from signature invalid from expired.
Where decoding is legitimately used
Libraries expose decode-only paths for good reasons: choosing a key from kid, showing a token's issuer in a support tool, or reading the expiry to decide whether to refresh before a call. The safe pattern is to make such a function return a value that cannot be mistaken for an authenticated principal — a separate type, a name such as peek, or a flag in the result. If the codebase has one function called decode that sometimes verifies and sometimes does not, eventually someone will use the wrong branch.
A JWT you have not verified is user input. Treat it with the same suspicion as a query parameter named admin=true.
Sources
Questions
If the payload looks correct, can I trust it?
No. Anyone can write any payload and base64url encode it. Correct-looking claims are evidence only after a signature check with a key you trust, followed by issuer, audience and time validation.
What does a valid signature prove?
That the holder of the signing key produced this exact header and payload. Nothing about whether the key belongs to your issuer, whether the token is current, or whether the subject is allowed to perform the requested action.
Why do some libraries have a decode function that skips verification?
Decoding is useful for reading a token's metadata, for example to find its issuer or key ID before verification. The danger is calling decode and treating the result as authenticated, which several real incidents have done. Make the unverified path obvious in code and never return it from an authorisation check.
Decode a token, then change one character and verify again to watch the signature fail.
Open the verifierWritten against the JOSE specifications (RFC 7515–7519), RFC 7636 and RFC 8037; every example can be reproduced in the verifier linked above.
Back to the guides