
JWT decoding is not JWT verification
A JWT can be read without being trusted. Verification requires the correct key, algorithm policy, issuer, audience, and application rules.
That sentence is the whole point of this guide, and it is easy to get wrong in practice. A JSON Web Token looks secure. It has three segments, a signature, and a structured payload. Pasting it into a decoder produces a readable JSON document with a user id, a role, and an expiry time. It is natural to conclude that because the token decodes cleanly, it must be genuine. It does not. Decoding only changes the encoding. Verification is the separate process that checks whether the token was issued by someone you trust, whether it is still valid, and whether it is allowed for the use you are about to make of it.
This guide explains what decoding does, what verification adds, how to verify a token correctly, and which mistakes turn a working login system into an open door. It includes a worked example, a verification checklist, limitations, and answers to common questions.
What a JWT is
A JSON Web Token, defined by RFC 7519, is a compact way to carry claims between two parties. The most common form is a JSON Web Signature, or JWS, which has three base64url-encoded segments separated by dots: header, payload, and signature. Written out, it looks like this: base64url(header).base64url(payload).base64url(signature). The header says how the token was signed. The payload carries the claims. The signature lets a recipient check that the header and payload have not been changed since they were signed.
A decoded header usually looks like this:
{"alg": "HS256", "typ": "JWT", "kid": "key-2026-01"}
A decoded payload, sometimes called the claim set, usually looks like this:
{"sub": "user_123", "role": "reader", "iss": "https://example.com", "aud": "demo-app", "iat": 1700000000, "exp": 1700003600}
Each claim has a meaning. The subject, sub, identifies the principal the token is about. The issuer, iss, says who created the token. The audien
What verification adds
Verification answers the questions decoding ignores. A verifier must, at minimum: confirm the token is well formed with three segments and valid JSON; confirm the algorithm in the header is one the application explicitly allows; obtain the correct verification key for that issuer and key id; recompute the signature over the exact header and payload bytes that were received and compare it with the presented signature in constant time; and then check the claims against policy, including issuer, audience, expiry, and not-before times, plus any application rules about subject, scope, or role.
Only if every one of those checks passes should the application treat the claims as authenticated. If any check fails, the token must be rejected as a whole. There is no partial trust: a token with a valid signature but the wrong audience, or a valid signature but an expired timestamp, is not usable for that request. Logging the reason for rejection, without logging the token itself, helps debugging with
Attacks and mistakes that bypass verification
The none algorithm
Some verifiers historically accepted tokens with alg set to none and an empty signature. Such a token is unsigned by definition, and anyone can create one. A verifier must reject none unless the application has a specific, documented reason to accept unsigned tokens, which is rare, and must never accept it merely because the library allows it.
Algorithm confusion
In algorithm confusion, an attacker takes a token that should be verified with an asymmetric algorithm such as RS256, changes the header to HS256, and signs it with the issuer’s public key, which is often public. A verifier that honours the header’s algorithm and uses the public key as an HMAC secret will accept the forgery. The fix is an allowlist: the verifier decides which algorithms are acceptable, independent of what the token claims, and uses the key type that matches that allowlist.
Trusting the key id blindly
The kid header is a hint for choosing among keys. It is not a trusted instruction to load a key from an arbitrary location. Verifiers have been tricked by key ids that point to attacker-controlled URLs, to files on disk, or to database queries. Treat kid as a lookup key into your own trusted key store. If it does not match a key you already trust, reject the token.
Ignoring expiry, audience, or issuer
A signature proves the token was signed. It does not prove the token is still valid, was issued for your service, or was issued by the issuer you expect. Tokens that skip expiry checks stay useful to an attacker long after they should have expired. Tokens that skip audience checks can be replayed against a different service that shares a verification key. Tokens that skip issuer checks can be accepted from any issuer whose key the verifier happens to trust. Check all three, every time.
Treating verification as authorisation
Verification proves the token is authentic and within policy. It does not prove the user is still allowed to do the requested action. Accounts get disabled, roles change, subscriptions lapse, and tokens get stolen. If your system needs immediate revocation, short-lived access tokens plus refresh-token rotation, a denylist, or a server-side session check may be needed. A verified token alone cannot tell you that the user’s permission has not changed since the token was issued.
Handling tokens safely
- Never paste a live bearer token into a public website, a decoder hosted by a third party, a chat log, a screenshot, or a bug report. Anyone who sees the token can replay it until it expires. Use a redacted or synthetic token for documentation and debugging, and rotate any token that was exposed.
- Do not put tokens in URLs, where they end up in browser history, server logs, and referrer headers. Send them in an
Authorizationheader over HTTPS. - Prefer HttpOnly, Secure, SameSite cookies for browser-based sessions where that fits your architecture, rather than storing tokens in local storage where a cross-site scripting flaw can read them. Whatever storage you choose, protect the application against XSS and keep dependencies patched.
- Keep tokens short-lived. A five- to fifteen-minute access token limits the damage from theft, and a refresh flow lets legitimate users continue without a long-lived bearer token lying around.
- Do not log tokens. Redact the
Authorizationheader and token fields in logs, error reports, and analytics, and treat any log that contains a live token as a secret that must be rotated and cleaned up. - Protect signing keys as secrets. Rotate them on a schedule, support overlapping key ids during rotation, and revoke a key promptly if it may have been exposed. A leaked signing key lets an attacker mint valid tokens for any user.
Limitations
Verification is necessary, but it is not a complete security story. It proves that a token was signed by the holder of a trusted key and that its claims pass the checks you configured. It does not prove that the claims are true in the real world, that the issuer’s own authentication was strong, or that the user behind the token is the person you think they are. It does not stop replay within the token’s lifetime if the token is stolen, unless you add sender binding, replay detection, or short lifetimes. It does not fix a weak key, a compromised issuer, an insecure transport, or an application that trusts claims it should not. Treat JWT verification as one control in a larger system that also needs HTTPS, secure key management, sound authorisation logic, input validation, logging, and monitoring.
Use the related tool carefully
This guide is paired with a browser-only utility. The tool is a practical aid for small examples and inspection; it is not a substitute for application testing, a formal data pipeline, or professional review where the decision has higher consequences.
Open the related JWT Payload Decoder
When you use a decoder, use a synthetic or expired test token, not a live credential. If a token grants access to a real account, decoding it on any site other than your own trusted tooling risks exposing it.
Frequently asked questions
If a token decodes correctly, does that mean it is valid?
No. Decoding only reverses base64url encoding and parses JSON. It does not check the signature, the issuer, the audience, or the expiry. A forged, expired, or tampered token decodes just as cleanly as a genuine one. Treat decoder output as untrusted data until a verifier has checked the signature and the claims.
Can I verify a token without the key?
No. Verification requires the key that corresponds to the signing key: the shared secret for a symmetric algorithm, or the public key for an asymmetric algorithm. Without it, you can decode the token and inspect its claims, but you cannot tell whether the signature is genuine. If someone tells you a token is verified, ask which key and which algorithm policy were used.
Is the signature the same as encryption?
No. A signature proves integrity and authenticity: the token has not been changed since it was signed, and it was signed by the holder of the signing key. It does not hide the contents. Anyone with the token can read the header and payload. If the payload must stay confidential, use encryption (JWE) or keep the sensitive data on the server.
Does checking expiry mean a stolen token is harmless?
No. Expiry limits the window, but a stolen token can be replayed until it expires. That is why short lifetimes, secure transport, safe storage, refresh-token rotation, and revocation matter. Expiry is one check among several, not a substitute for protecting the token and verifying the signature and claims.
Related tools in this category
Sources
out creating a new leak.
Verification also has a key-management side. For symmetric algorithms such as HS256, the same secret is used to sign and to verify, so the verifier must hold that secret securely and never expose it. For asymmetric algorithms such as RS256 or ES256, the issuer signs with a private key and verifiers check with the corresponding public key, often fetched from a JSON Web Key Set (JWKS) endpoint. In both cases the verifier must be sure it has the right key for the right issuer. Accepting a key supplied by the token itself, or fetched from a URL taken from an untrusted header, defeats the purpose of verification.
Worked example: a forged role change
Imagine a demo application issues this payload after login:
{"sub": "user_123", "role": "reader", "iss": "https://example.com", "aud": "demo-app", "exp": 1700003600}
A reader opens the token in a decoder, copies the payload, changes reader to admin, re-encodes the payload as base64url, and sends the modified token with the original signature. The token still decodes cleanly. The payload now says admin. If the server only decodes the token and reads the role claim, the attacker has just promoted themselves.
A verifying server behaves differently. It takes the modified header and payload bytes, recomputes the signature with the issuer’s key, and compares the result with the signature in the token. Because the payload changed, the recomputed signature does not match. The server rejects the token, even though the JSON looks well formed and the expiry is still in the future. That comparison is the entire difference between decoding and verification. It is also why the signature must cover the header and the payload, and why the verifier must use the exact bytes received, not a re-serialised version that might normalise whitespace or key order.
The same reasoning applies to subtler changes. Changing the issuer, the audience, the subject, or the expiry all change the signed bytes, so a correct verifier will reject the tampered token. The protection only holds, however, if the verifier actually checks the signature and the claims. A verifier that checks the signature but ignores expiry will accept a stolen token long after it should have died. A verifier that checks expiry but skips the signature will accept a forgery. Every check matters.
How to verify a token, step by step
- Split the token into three segments. Reject it if there are not exactly three, or if any segment fails base64url decoding or JSON parsing.
- Read the header, but do not trust it yet. Check that
algis in your explicit allowlist, such as RS256 only. Rejectnoneand any algorithm you did not configure. - Select the verification key from your own trusted configuration: a stored secret for a symmetric algorithm, or the public key for the
kidin your trusted JWKS for an asymmetric algorithm. Do not fetch a key from a URL in the token unless that URL is itself in your allowlist and you understand the risk. - Recompute the signature over the received header and payload segments, using the stated algorithm and the selected key. Compare it with the presented signature in constant time. Reject the token on any mismatch.
- Check the time claims. The current time must be at or after
nbfif present, and beforeexp. Allow only a small, configured clock-skew tolerance, such as a few minutes, for differences between servers. - Check
issagainst your expected issuer, exactly. Checkaudagainst your expected audience. A token issued for another service is not valid for yours, even if the signature is genuine. - Apply application rules. Check that the subject exists, that the role or scope permits the requested action, and that the token has not been revoked, if your system supports revocation. A verified token is still only as trustworthy as the authorisation logic around it.
Use a well-maintained JWT library for your platform and let it perform these steps. Do not write your own signature comparison or base64url handling unless you have a specific reason and the expertise to test it. Libraries differ in defaults, so read the documentation for yours: confirm that it rejects none by default, that it requires you to pass an allowlist of algorithms, and that it validates exp, iss, and aud when you supply expected values, rather than silently ignoring them.
ce, aud, says who the token is for. The issued-at, iat, and expiry, exp, bound the token in time. Other claims, such as nbf (not before), jti (a unique token id), and application-specific claims such as role, add further rules. None of these claims is trustworthy until the signature has been verified and the claims have been checked against policy.
What decoding does
| Check | What it proves |
|---|---|
| Decoding | Shows the claims inside the token |
| Verification | Checks the signature is valid |
| Decoding without verification | Nothing about trust |
Decoding a JWT is an encoding operation, not a security operation. The header and payload are encoded with base64url, a URL-safe variant of base64 that omits padding and uses different characters for two values. Decoding reverses that encoding and returns the underlying bytes, which are then parsed as JSON. Anyone can do this to any token, with no key, no password, and no permission from the issuer. That is by design. A signed JWT is not encrypted. Its contents are readable by anyone who holds the token.
That readability is why you must never put secrets in a JWT payload: no passwords, no password-reset codes, no personal data beyond what the application needs, and nothing you would be unwilling to show to anyone who intercepts the token. If confidentiality is required, the token needs to be encrypted as a JSON Web Encryption (JWE), or the sensitive data must stay on the server and be looked up by an opaque reference instead.
A decoder is still useful. It helps you inspect a token during development, see which claims are present, check whether an expiry looks wrong, and understand why a request failed. The mistake is treating the decoder output as evidence. A decoder will happily decode a token that was forged, expired, issued by someone else, or signed with the wrong key, because decoding never asks any of those questions.
Try a Tool
Free, in your browser — no sign-up.
- .htaccess Generator Open tool →
- Age Calculator Open tool →
- Angle Converter Open tool →
- API Tester Open tool →
- ASCII Converter Open tool →
- Base64 Encoder and Decoder This tool converts text to the Base64 representation used in many transport and test contexts, and it reverses Base64 text back into Unicode text when the input is valid. Open tool →
Related Articles
How to Tell If a Link Is Safe Before You Click It
Learn how to tell if a link is safe before you click it. Hover to preview, check the domain, treat shorteners with…
Read article →How to Spot a Phishing Email Before You Click
Learn how to spot a phishing email before you click: check the sender, urgency, and links, hover before clicking, skip attachments, and…
Read article →How to Choose a Password Manager (Without Overthinking It)
Learn how to choose a password manager without overthinking it: vault, master password, 2FA, and a simple setup that keeps every account…
Read article →