A JWT debugging checklist for signature and claim failures
Most JWT failures fall into a small number of buckets: the token is malformed, the key is not the one the issuer used, the algorithm differs, the key format is wrong, the claims do not match this service, or the clocks disagree. Working through them in order is faster than changing code at random. The verifier on this page is built to make each step visible.
Step 1: is the token well formed?
Count the dots. A JWS has exactly two, giving three non-empty segments. A JWE has four dots and five segments, and a JWS verifier should reject it. Check for whitespace, line breaks, a leading Bearer prefix that was not stripped, or quotes around the value. Base64url must not contain +, / or =; padding is optional in some libraries and forbidden in others, so a token copied from a URL may need the padding removed.
Then check that both decoded parts are JSON objects. A payload that decodes to a bare string, an array or invalid UTF-8 is not a JWT. If the header parses but the payload does not, the token was probably truncated in a log or a header limit.
Step 2: which key and which algorithm?
Read alg and kid from the header, but do not let them override your configuration. If the verifier is configured for RS256 and the token says HS256, the correct outcome is rejection, not a switch to HMAC. If kid names a key you do not have, the token may be from a newer key than your cached JWKS; refetch once, rate-limited, and retry.
For HS256, confirm that both sides use the same bytes. A secret typed into a dashboard may include a trailing newline; a secret stored base64-encoded must be decoded before use or both sides must treat it as text consistently. For RS256, confirm that the verifier has the public key, not the private key with a missing header line, and that the PEM label is PUBLIC KEY rather than CERTIFICATE unless your library accepts certificates.
Step 3: is the signature encoding right?
RSA signatures are fixed-length byte strings and rarely cause encoding trouble. ECDSA is different: JOSE defines the signature as the concatenation of r and s, each padded to the curve size, while OpenSSL-style APIs often use DER. If a library returns a DER blob and you paste it into a JOSE verifier, the length will be wrong and verification fails. ES256 signatures are 64 bytes; ES384 are 96; ES512 are 132. A DER signature for P-256 is typically 70 to 72 bytes.
EdDSA signatures are 64 bytes. A common error is to treat Ed25519 as ECDSA and supply a curve parameter; the correct import is an OKP key with crv equal to Ed25519.
| Symptom | Likely cause | Check |
|---|---|---|
| Signature invalid, key looks right | Secret text differs by whitespace or encoding | Compare byte length and hex of the key material |
| Signature invalid only for ES* | DER versus raw r||s | Signature length: 64/96/132 bytes for raw |
| Unknown kid | Key rotation or wrong environment | Refetch JWKS once; check issuer and environment |
| alg not allowed | Verifier allowlist is narrower | Align issuer and verifier configuration |
| Token expired immediately | Milliseconds used for exp or iat | Values should be around 1.8 billion, not 1.8 trillion |
| Works locally, fails in production | Clock skew or different secret store | Compare NTP status and secret version |
Step 4: do the claims match this service?
A valid signature with the wrong audience is still a failure. Compare aud exactly, including scheme and trailing slash if your identifier has one, and confirm that the issuer is in the configured list. Check exp and nbf with the allowed skew. If the token comes from a browser, remember that the browser's clock is irrelevant to server-side validation; only the server's clock matters.
Step 5: reproduce outside the application
Take the exact token string and the exact key bytes out of the application and verify them in a separate tool. If the separate tool succeeds, the failure is in how the application loads or selects the key. If it fails too, the token and key genuinely do not match. This one step separates configuration bugs from cryptographic mismatches faster than any amount of logging.
When you log a token for debugging, log a hash or the last few characters, not the whole value, and never log a private key or a client secret. A token can carry personal data and is a bearer credential while it lasts. The verifier on this site keeps everything in page memory so that this kind of experiment does not create a copy on a server.
Change one variable at a time. Replacing the key, the algorithm and the library together may fix the problem but will not tell you which one was wrong.
Sources
- RFC 7515 §3.3 — Signing input and signature
- RFC 7518 §3.4 — ECDSA signature encoding
- RFC 8725 §3 — Best practices for validation
Questions
The token works in one service but not another. Where do I look first?
Compare the configured algorithm allowlist and the key set, then the audience. A token accepted by service A and rejected by B usually differs in aud, in the key version selected by kid, or in whether B allows the algorithm at all.
Why does my ECDSA signature fail even with the right key?
JOSE uses the raw fixed-width r||s form, while many crypto libraries produce or expect DER-encoded ECDSA signatures. Re-encoding one as the other is required. Also check the curve: ES256 means P-256 with SHA-256, not any 256-bit curve.
The secret is definitely right. Why is HS256 still failing?
Check what the secret actually is: text versus base64-decoded bytes, trailing newline, quotes copied from a password manager, or an environment variable that was not set. A trailing newline is invisible in most configuration screens and changes the HMAC key.
Work through the checklist directly in the verifier: decode, then verify with the key you expect.
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