·9 min read
ByDaniel A·Kraftwire Software

JWT Security: How to Read a Token and Catch the Red Flags

Illustration for JWT Security: How to Read a Token and Catch the Red Flags

This guide covers signed JWTs (JWS). Their header and payload are readable without a key. JWTs can also be encrypted (JWE). For the signed tokens discussed below, decoding reveals data but does not establish authenticity or permission to access a resource.

Is a JWT Encrypted or Just Signed?

A JWT can carry claims in a signed form (JWS) or an encrypted form (JWE). Signing provides integrity protection when correctly verified; it does not hide the claims. This guide focuses on signed JWTs without an encryption layer. Treat their header and payload as readable by anyone who obtains the token.

Secure use depends on trusted keys, server-side signature and claim validation, safe handling of tokens, and authorization checks. Inspecting a token can highlight issues to investigate, but it cannot establish that an authentication system is secure.

What Is a JWT, Actually?

A JSON Web Token represents claims exchanged between parties. It can support authentication designs where the server validates a self-contained token, but applications can also maintain session or revocation state. A signed JWT in compact form has three dot-separated parts:

header.payload.signature
  1. The Header: Contains metadata such as the signing algorithm (alg) and, when present, the token type (typ).
  2. The Payload: Contains claims about an entity and other application data.
  3. The Signature: Protects the encoded header and payload using a shared secret for an HMAC algorithm or a private key for an asymmetric signing algorithm.

The header and payload are base64url-encoded JSON. Base64url is reversible encoding, not encryption. No key is needed to decode these two parts. Decoding them does not verify the signature.

How Do You Read a Signed JWT?

Use a test token when possible. Depending on how your application stores tokens, your browser's developer tools may show them under local storage or cookies. Split the token at the dots and base64url-decode the first two parts. A header might look like this:

{ "alg": "HS256", "typ": "JWT" }

The header declares an algorithm; the server must check that it matches its configured policy. A payload might look like this:

{
  "sub": "user_123",
  "email": "user@example.com",
  "role": "admin",
  "exp": 1751500000
}

These are example claims, not proof of identity or permission. The third part is a base64url-encoded signature or MAC value, not JSON. Our JWT Debugger decodes the header and payload in your browser and flags selected structural issues, such as missing expiration and recognized sensitive claim names. It also offers an optional HS256 signature check with a supplied secret. Its output does not establish that your backend validates tokens correctly; prefer test tokens and test secrets.

Which JWT Security Red Flags Should You Review?

1. The alg is "none" or the token is unsigned

An unsecured JWT uses alg: none and has no signature protection. An authentication endpoint that requires signed tokens must reject it. If a server trusts attacker-edited claims without verifying their integrity, an attacker may be able to impersonate a user or gain privileges. The actual access depends on how the application uses those claims.

2. Algorithm Confusion (HS256 vs RS256)

HS256 and RS256 illustrate symmetric and asymmetric approaches:

  • HS256: The same secret is used to produce and verify an HMAC.
  • RS256: A private key signs, and a public key verifies.

An algorithm-confusion vulnerability can arise when a verifier accepts HS256 while treating an RSA public key as an HMAC secret. An attacker who knows that public key can then produce a matching HMAC. Configure the permitted algorithm and key type on the server, reject mismatches, and use trusted key-selection rules. Do not let an untrusted header determine the verification policy.

3. Sensitive Data in the Payload

In the signed, unencrypted tokens covered here, anyone holding the token can read the payload. Include only necessary claims and keep passwords, credit card numbers, and private API keys out of it. Personal data such as email addresses also needs careful handling.

4. Missing or Far-Future Expiration (exp)

The exp claim expresses an expiration time as seconds since the Unix epoch. If it is absent, the token itself supplies no expiration deadline; the server may still impose a lifetime or reject it under its own policy. A stolen bearer token may be reusable while the server accepts it, subject to expiration, revocation, and other controls. Require and validate expiration for access tokens under your authentication policy, and choose a lifetime appropriate to your application.

5. Weak HMAC Secrets

A weak HS256 secret can be vulnerable to offline guessing using a captured token. Anyone who obtains the signing secret can create matching HMACs. Use cryptographically random key material with sufficient entropy: for HS256, at least 256 bits. Keep signing keys server-side in protected secret storage and out of source control and browser bundles. Review how environment variables are exposed in your stack; see our guide on environment variables security.

6. Storing Tokens in localStorage

Scripts running in your application's origin can read its local storage. XSS can therefore expose tokens in an affected browser session. An HttpOnly cookie prevents JavaScript from directly reading that cookie, but injected scripts may still make authenticated requests. For cookie-based authentication, use Secure, an appropriate SameSite policy, and CSRF defenses suited to your application. Storage settings do not replace XSS prevention.

JWT Security Checklist

If you are building with tools like Lovable, Bolt.new, or Replit, review these controls in your auth flow:

  • Algorithm and Key Policy: Configure allowed algorithms and trusted keys on the server. Reject token headers that do not match that policy.
  • Validation: Before accepting a token, verify its signature and required claims, including expiration, issuer, and audience. Enforce authorization for each protected operation.
  • Payload Hygiene: Include only necessary claims and avoid secrets in readable payloads.
  • Browser Storage: Evaluate HttpOnly cookies, HTTPS, SameSite policy, CSRF defenses, and XSS prevention together.
  • Lifetimes and Revocation: Choose access-token lifetimes and define how logout, account changes, and stolen tokens affect acceptance. Protect refresh tokens if used.
  • Key Management: Use appropriate key sizes and cryptographically random HMAC secrets, protect signing keys, and plan rotation.

How SimplyScan Helps

Use our vibe coding security checklist alongside source review and tests of protected operations. The JWT Debugger helps inspect individual tokens; a public URL scan cannot establish that a backend verifies every token or enforces all authorization rules.

SimplyScan's free scan reports site health scores across 8 dimensions, including security and GDPR signals, with detailed findings subject to plan limits. Review the supported findings as part of a broader assessment.

Wrapping Up

Decode signed tokens to understand their contents, then review the server code that validates and uses them. Use our JWT Debugger with test values to inspect headers and claims. A readable payload or a successful signature check alone does not establish that a token should be accepted.

For additional supported public-site checks, run a scan at.1 Combine findings with application-specific authentication and authorization testing.

Related Free Tools

Browse all our free tools.

FAQ

Can someone hack my app if they see one of my JWTs?

For the signed JWTs covered here, anyone holding the token can read its header and payload. JWTs can also be encrypted (JWE). A stolen bearer access token can allow impersonation while the server accepts it, even without forgery. Weak keys, compromised signing keys, or validation bugs can also allow forged tokens; these are not the only possible authentication failures.

Is decoding a JWT the same as verifying it?

No. For a signed JWT, decoding makes the base64url-encoded header and payload readable without a key. Signature verification checks their integrity using a trusted shared secret or public key, depending on the algorithm. The server must also validate claims such as expiration, issuer, and audience according to its token policy and enforce authorization. Decoding alone establishes none of these checks.

Should I store JWTs in localStorage or cookies?

For browser applications, consider HttpOnly cookies with Secure and an appropriate SameSite policy. Same-origin scripts can read localStorage; HttpOnly prevents JavaScript from directly reading a cookie. It does not stop injected scripts from making authenticated requests. Cookie-based authentication also needs CSRF defenses appropriate to the application, and neither storage choice replaces XSS prevention.

How long should a JWT access token last?

Choose a short lifetime based on the application’s risk and session requirements, and enforce expiration on the server. A self-contained token can remain acceptable until expiration unless the server also checks revocation or session state. If you use refresh tokens to extend sessions, protect them and define rotation and revocation behavior; there is no universally safe access-token lifetime.

What is the difference between HS256 and RS256?

HS256 uses a shared secret for both signing and verification. RS256 uses a private key to sign and a public key to verify. Public-key verification lets services verify tokens without giving them signing authority. Neither choice is automatically more secure; both require suitable keys and correct validation.

Is it safe to put a user's email or role in a JWT payload?

Include only claims the application needs. In a signed JWT without encryption, anyone holding the token can read the payload; email addresses and identifiers may be personal data. Keep passwords, private API keys, and other secrets out of these payloads. Trust a role only after token validation, and enforce authorization against the application’s current policy.

Sources

  1. simplyscan.io
  2. redsentry.com › jwt-vulnerabilities-list-2026-security-risks-mitigation-gui…

Frequently asked questions

For the signed JWTs covered here, anyone holding the token can read its header and payload. JWTs can also be encrypted (JWE). A stolen bearer access token can allow impersonation while the server accepts it, even without forgery. Weak keys, compromised signing keys, or validation bugs can also allow forged tokens; these are not the only possible authentication failures.
No. For a signed JWT, decoding makes the base64url-encoded header and payload readable without a key. Signature verification checks their integrity using a trusted shared secret or public key, depending on the algorithm. The server must also validate claims such as expiration, issuer, and audience according to its token policy and enforce authorization. Decoding alone establishes none of these checks.
For browser applications, consider HttpOnly cookies with Secure and an appropriate SameSite policy. Same-origin scripts can read localStorage; HttpOnly prevents JavaScript from directly reading a cookie. It does not stop injected scripts from making authenticated requests. Cookie-based authentication also needs CSRF defenses appropriate to the application, and neither storage choice replaces XSS prevention.
Choose a short lifetime based on the application’s risk and session requirements, and enforce expiration on the server. A self-contained token can remain acceptable until expiration unless the server also checks revocation or session state. If you use refresh tokens to extend sessions, protect them and define rotation and revocation behavior; there is no universally safe access-token lifetime.
HS256 uses a shared secret for both signing and verification. RS256 uses a private key to sign and a public key to verify. Public-key verification lets services verify tokens without giving them signing authority. Neither choice is automatically more secure; both require suitable keys and correct validation.
Include only claims the application needs. In a signed JWT without encryption, anyone holding the token can read the payload; email addresses and identifiers may be personal data. Keep passwords, private API keys, and other secrets out of these payloads. Trust a role only after token validation, and enforce authorization against the application’s current policy.

Is your app secure? Run a free security scan in 30 seconds · free account required.

Scan your app free →