JWT pitfalls: decoding a token is not verifying it

Try it in the tool

JWT Decoder

Decode JWTs, check expiry and verify HMAC signatures — privately.

JWT Encoder

Sign JWTs with an HMAC secret or a PEM private key — locally.

Unix Timestamp Converter

Epoch ↔ human dates in any time zone, units detected automatically.

A JSON Web Token looks like three chunks of gibberish joined by dots. Paste it into a decoder and you see readable JSON: who the user is, which roles they have, when the token expires. That readability is the root of most JWT mistakes. Reading a token and trusting a token are different operations, and only the second one needs a key.

What is inside a token

A JWT is header.payload.signature. The first two parts are JSON encoded as Base64URL, and the third is a signature over the first two. Open the JWT decoder with this token:

eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJzdWIiOiIxMjM0IiwiYWRtaW4iOnRydWUsImV4cCI6MTYwMDAwMDAwMH0.

It decodes to a header of {"alg": "none", "typ": "JWT"} and a payload of {"sub": "1234", "admin": true, "exp": 1600000000}. The signature part after the last dot is empty. The decoder flags two problems at once: the token is unsigned, and it has expired. A server that accepted this token would be accepting a claim of admin: true that anyone could have typed.

Pitfall 1: alg: none

The alg header tells the verifier how the token was signed, and the value none means it was not. The token above takes seconds to forge: encode a header, encode a payload, leave the signature empty. Some early libraries honoured the header and skipped verification when they saw none.

The fix is in your server code, not in the token: decide the allowed algorithms yourself and reject everything else. Never let the token choose how it is checked.

Pitfall 2: algorithm confusion

A server expecting RS256 (asymmetric) has a public key that is not secret. If it passes that key to a verifier which then trusts the header and sees HS256, the verifier treats the public key as the shared secret of an HMAC. An attacker who knows the public key can sign a token that passes. The cure is the same as above: pin the algorithm per key, and use a library version that requires you to name it.

Pitfall 3: seconds, not milliseconds

exp, nbf and iat are NumericDate values, defined in RFC 7519 as seconds since 1970-01-01T00:00:00Z. JavaScript’s Date.now() returns milliseconds. A token with exp: 1760000000000 is not “valid for a long time” in the way you want; it is a bug. Convert with the Unix timestamp converter when a value looks off: 1600000000 is 2020-09-13 12:26:40 UTC, and the decoder shows that date next to the claim, plus how long ago it was.

Allow a small clock skew when checking exp and nbf, a minute or two. Servers’ clocks drift, and a token issued “now” by one machine can be “in the future” for another.

Pitfall 4: verifying the signature and nothing else

A valid signature proves only that someone with the key signed these bytes. It does not prove the token is meant for you. Check:

  • iss: the issuer is the one you trust, not another tenant or environment.
  • aud: the audience contains your service, so a token minted for the billing API cannot be replayed against the admin API.
  • exp and nbf: the token is inside its validity window.
  • typ or a custom claim if you issue different kinds of tokens (access, refresh, email-verification).

Pitfall 5: putting secrets in the payload

Because the payload is only encoded, a mobile app, a browser extension, a proxy log and the user themselves can read it. Keep identifiers and roles in there, not emails you promised to protect, not internal flags you would not want a user to see. If you need confidentiality, use an encrypted token or keep the data on the server and put only a reference in the token.

Building test tokens

When you write tests for a verifier, you need tokens that are valid, expired, signed with the wrong key and signed with the wrong algorithm. The JWT encoder builds them from a payload and a secret, so you can check that your server rejects each bad case instead of testing only the happy path.

Debugging checklist

  1. Decode the token and read the header. Is alg what you expected?
  2. Compare exp with the current time in seconds.
  3. Check iss and aud against your configuration, character for character.
  4. Re-verify with the key from the right environment: production keys do not verify staging tokens.
  5. Make sure your code names the allowed algorithms.

Tokens you paste here are decoded in your tab and never uploaded. Still, treat real production tokens as passwords.

Frequently asked questions

Is it safe to paste a JWT into an online decoder?

Only if the decoder never sends it anywhere. A JWT is a credential: until it expires, whoever holds it can act as the user. The decoder on this site runs in your browser and uploads nothing, but treat tokens from production like passwords either way and prefer expired or test tokens.

Is the payload of a JWT encrypted?

No. A normal signed JWT (JWS) is only Base64URL-encoded JSON, so anyone can read it. The signature proves it was not changed; it does not hide anything. Never put passwords, secrets or personal data in the payload unless you use an encrypted token (JWE).

Why does my token expire immediately or never?

The exp, nbf and iat claims are NumericDate values: seconds since 1970, not milliseconds. A value like 1760000000000 is a date thousands of years away, so a library that treats it as seconds will accept it as valid practically forever.

Which claims should a server check besides the signature?

At least exp, nbf, iss (who issued it) and aud (who it is for), plus the algorithm. A correctly signed token for another service or another environment is still the wrong token for yours.

More guides