Local-first tools. Your files and text stay in your browser.

data guide

JWT structure and common mistakes

A JWT has three Base64URL parts and is signed, not encrypted. Learn claims, expiry checks, algorithm pitfalls and safe session storage.

Reviewed December 3, 2026 · TinkerFern editorial

A JSON Web Token (JWT) is a compact way to carry claims between parties. It is widely used for API access and single sign-on, and it is also widely misread. The most important fact is simple: a JWT is signed, not encrypted. Anyone holding the token can read its payload.

The three parts

A JWT looks like header.payload.signature. Each part is Base64URL-encoded, and the first two are JSON objects.

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
.
eyJzdWIiOiIxMjMiLCJleHAiOjE3MDAwMDAwMDB9
.
signature-bytes
  • Header names the signing algorithm and token type, for example {"alg":"HS256","typ":"JWT"}.
  • Payload contains claims: statements about the subject, issuer, audience and validity window.
  • Signature lets a verifier detect modification when it knows the right key.

Base64URL is an encoding, not a security control. Decoding the payload is a single step, so never put passwords, API keys, personal data or internal notes in a JWT payload.

Registered claims worth checking

The JWT specification defines a small set of registered claims. A verifier should check the ones that apply to its use case:

Claim Meaning Typical check
iss Issuer Must match the expected identity provider
sub Subject Identifies the user or entity
aud Audience Must include this service
exp Expiration time Reject after this time
nbf Not before Reject before this time
iat Issued at Useful for freshness and auditing
jti Unique token ID Supports replay detection and revocation lists

exp, nbf and iat are NumericDate values: seconds since the Unix epoch, not milliseconds. A token with an expiration in milliseconds will appear valid for tens of thousands of years, which is rarely the intent.

Signature verification, not decoration

Decoding a token and looking at exp is not verification. A verifier must:

  1. Parse the token and reject malformed segments.
  2. Read the header only to select a key, never to trust an arbitrary algorithm.
  3. Verify the signature with an algorithm allowlist and the correct key.
  4. Check exp, nbf, iss and aud against expected values.
  5. Apply the authorization decision only after all checks pass.

Two classic failures are worth naming because they still appear in the wild:

  • alg: none. Some libraries historically accepted an unsigned token when the header said none. Reject it explicitly.
  • Algorithm confusion. A server expecting RS256 may be tricked into verifying an HS256 token using the public key as an HMAC secret. Pin the expected algorithm and key type.

Use a maintained library rather than hand-rolling verification. The library should make the safe path the default, and you should still test expired, wrong-audience and wrong-issuer tokens.

Expiry is not revocation

Short-lived access tokens limit the damage of a leaked credential, but a signed token remains valid until it expires unless the verifier keeps additional state. If you need immediate logout or revocation, combine short access tokens with refresh-token rotation, a server-side session record, or a jti deny list.

Do not shorten expiry to a few seconds and call it security. Users will refresh constantly, and clock skew will create intermittent failures. A small leeway, typically under a minute, is common when validating exp and nbf.

Where to store a token

For browser sessions, an HttpOnly, Secure, SameSite cookie is usually safer than localStorage, because JavaScript cannot read it and an XSS bug cannot simply exfiltrate it. Cookies bring CSRF considerations, so pair them with SameSite and, where needed, a CSRF token.

localStorage is readable by any script on the origin. One compromised dependency can copy the token. Session storage has the same exposure. If you must keep a token in JavaScript, keep its lifetime short and treat XSS prevention as a hard requirement.

Debugging safely

When a token fails, inspect the header and payload, then compare the timestamps with a known clock. The JWT decoder decodes locally in the browser and does not send the token anywhere. That matters: pasting a production token into an unknown website hands that site a valid credential.

The Base64 tool is useful for individual segments, and the hash generator helps verify checksums when you are testing a signing pipeline. Neither tool can validate a signature without the key, and no online decoder should ask for one.

A short review checklist

  • Is the payload free of secrets and unnecessary personal data?
  • Is the algorithm pinned on the server?
  • Are exp, nbf, iss and aud all validated?
  • Is the signing key rotated and kept out of source control?
  • Is the token stored where XSS cannot read it?
  • Is there a revocation plan for logout and incident response?

Further reading: RFC 7519 for JWT, RFC 8725 for JWT best practices, and the OWASP guidance on session management and password storage.

Tools mentioned in this guide

Apply the advice with a tool that runs locally.

Continue with a related explainer from the same topic.

All guides →

← All guides · RSS feed

Privacy and cookie settings

This build loads no advertising scripts and no analytics vendor. If analytics is enabled by the owner, it sends only allowlisted event names and tool IDs, never your text, files or generated output.

Analytics
Disabled in this build
Advertising
Disabled in this build
Local storage
Theme, favorite tool IDs, recent tool IDs