JWT basics: compact does not mean secret
A JSON Web Token is a compact way to represent claims between systems. The official specification is IETF RFC 7519, and the most important practical lesson is simple: a normal signed JWT can be decoded by anyone who has it. Signing proves that the token has not been changed after issuance; it does not hide the payload.
We see the same debugging mistake repeatedly: a developer pastes a live access token into a random web tool, sees readable user claims, and assumes the tool “decrypted” something. It did not. The payload was Base64URL-decoded. If the token contains email addresses, tenant IDs, roles, or internal account references, that information was already exposed to anyone holding the token.
Try our JWT Decoder for local inspection when you need to understand structure, but use redacted or development tokens whenever possible. Helpful security understanding comes first; the tool is just a convenient viewer.
The three-part JWT structure
A JWT usually looks like three dot-separated strings: header.payload.signature. The header identifies the token type and algorithm. The payload contains claims. The signature is calculated over the encoded header and payload using the selected algorithm and key material.
Here is a simplified educational example. Do not use this token in production; it is intentionally fake.
{
"header": { "alg": "HS256", "typ": "JWT" },
"payload": {
"sub": "user_123",
"iss": "https://auth.example.test",
"aud": "https://api.example.test",
"exp": 1790880000,
"roles": ["editor"]
},
"signature": "base64url(hmac_sha256(header.payload, secret))"
}Registered, public, and private claims
Common registered claims include iss for issuer, sub for subject, aud for audience, exp for expiration, nbf for not before, and iat for issued at. Private claims are application-specific, such as roles or feature flags.
Do not overload claims. A token with 2 KB of authorization context can become a performance and security problem. It travels on every request where it is attached, and it can leak details if logged or copied.
| JWT part | What it contains | Can users read it? | Trust condition |
|---|---|---|---|
| Header | Algorithm and token type | Yes | Server allows only expected algorithms |
| Payload | Claims about subject and context | Yes | Claims validated after signature check |
| Signature | Integrity proof | Visible but not reversible | Verified with correct key |
Security checks that must happen server-side
JWT validation belongs on the server or trusted resource service. A browser can decode a token for display, but it cannot decide whether protected API access is valid. At minimum, verify the signature, reject unexpected algorithms, confirm issuer and audience, check expiration and not-before times, and handle key rotation correctly.
MDN’s session management guidance notes that signed objects are often represented as JWTs and warns about signature enforcement problems. See MDN on session management for broader session context.
Original observation from API audits: most JWT bugs we catch are not exotic cryptography failures. They are configuration mistakes—accepting the wrong audience, skipping expiration in a test path, or logging the Authorization header in a verbose debugging mode.
Storage and browser risks
Token storage is a tradeoff. Local storage is easy for JavaScript to access, which also means injected scripts can read it. HTTP-only cookies reduce direct JavaScript access, but they require CSRF-aware design and careful SameSite settings. There is no storage option that makes poor application security disappear.
We recommend minimizing token lifetime, limiting claims, avoiding sensitive PII in payloads, and separating debugging from production credentials. If you need to inspect JSON claims, copy only the payload into JSON Formatter after removing identifiers.
What to write down during a token incident
When a token-related bug reaches production, the response should be calm and specific. Record the token issuer, audience, algorithm, key ID, expiration, affected environment, and the exact validation error. Do not paste the full token into an issue tracker or chat thread. If a claim is relevant, copy only that claim and replace identifiers with placeholders.
A practical incident note might say: “The API rejected staging tokens because aud was api-staging while the production gateway expected api. No signature bypass was observed. Logs were checked for Authorization header exposure.” That note is reviewable without leaking credentials.
Teams should also separate decoding from verification in their vocabulary. “Decoded successfully” only means the token structure was readable. “Verified successfully” means a trusted service checked the signature and required claims. This language distinction prevents a surprising amount of confusion during onboarding and code reviews.
A safe JWT debugging workflow
- Use a development token or redact the production token first.
- Decode locally and read the header and payload.
- Confirm
iss,aud,exp, and role claims against the expected environment. - Never treat client-side decoding as proof of validity.
- Check server logs for validation errors without printing the full token.
A useful debugging note is short: “Token audience is staging API, request is production API.” That one sentence solves more than a screenshot of the entire token.
For code review, add one more check: confirm the library defaults. Some libraries require explicit audience or issuer options, and some examples online omit them for brevity. Production code should not copy a minimal demo without adding environment-specific validation. Keep a small unit test with an expired token, wrong audience token, and unsigned or incorrectly signed token so regressions are caught before deployment.
If a JWT is used for authorization, decide where role changes take effect. A user whose role is removed may still have an unexpired token with the old role until the token expires or the server checks a revocation or session state. Short-lived access tokens, refresh-token rotation, and server-side permission checks can reduce that window. The exact design depends on the application, but ignoring the window is a common mistake.
Do not store secrets in custom claims. A claim named plan or tenant may be fine if exposure is acceptable. A claim containing API keys, reset tokens, internal notes, or private billing details is not fine. Treat the payload as visible metadata.
Key Takeaways
- JWT payloads are readable; do not put secrets inside ordinary signed tokens.
- Validation must include signature, algorithm, issuer, audience, and time claims.
- Prefer redacted or development tokens for debugging.
- Keep token claims small and purposeful.
