Security & Certificates
Decode vs Verify JWT: What’s the Difference?
Decoding and verifying a JWT answer different questions. Decoding reveals the token's structure; verification determines whether protected content matches a trusted cryptographic key and policy.
Published
Decoding reads structure without a key
A decoder splits the compact token, Base64URL-decodes the readable segments and parses their JSON. This is useful for debugging, but an attacker can create equally readable header and payload values.
const [header, payload, signature] = token.split(".");Verification checks integrity with a trusted key
Verification recomputes or validates the cryptographic result over the protected header and payload. The key and accepted algorithms must come from trusted configuration or a validated issuer key set, not from arbitrary token data.
verify(signature, encodedHeader + "." + encodedPayload, trustedKey);Decode and verify answer different questions
| Operation | Needs a key | Establishes authenticity |
|---|---|---|
| Decode | No | No |
| Verify signature or MAC | Yes | Only when the key and algorithm policy are trusted |
A modified token can still decode successfully
Changing a payload and re-encoding it can produce valid JSON and a well-formed three-segment token. The stale signature should fail verification, which is why a decoded admin or role claim must never be trusted by itself.
Verification includes algorithm and key policy
- Allow only algorithms expected by the application.
- Choose keys from trusted issuer configuration.
- Reject unsecured alg=none tokens unless an explicitly designed closed system requires them.
- Handle key rotation and kid values without accepting attacker-controlled key locations.
A valid signature is necessary but not sufficient
After cryptographic verification, validate iss, aud, exp, nbf and the claims required by the current endpoint. A correctly signed token for a different audience or expired session must still be rejected.
Safe JWT handling workflow
- Decode for local inspection and debugging.
- Verify with a maintained JWT library in the application backend.
- Pin allowed algorithms and trusted issuer keys.
- Validate audience, issuer and time claims.
- Authorize the requested action from verified, scoped claims.
Try the example
Decode readable claims without treating them as verified
A well-formed token can expose valid JSON even when no trusted key has verified its signature.
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkFkYSBMb3ZlbGFjZSIsImFkbWluIjp0cnVlLCJpYXQiOjE3MDAwMDAwMDAsIm5iZiI6MTY5OTk5OTkwMCwiZXhwIjoyMTQ3NDgzNjQ3fQ.ZGVtby1zaWduYXR1cmUExpected result: Header and payload are readable, while the signature status remains unverified and the decoded claims remain untrusted.
See the boundary
Decode a token without claiming verification
Inspect a synthetic token and observe that readable header and payload data can coexist with an unverified signature status.