JWT Security: Common Vulnerabilities and How to Avoid Them
JWTs get misused in the same handful of ways across codebases, from trusting the algorithm header to skipping issuer and audience checks.
Key takeaways
- Most JWT vulnerabilities come from trusting the token's own header, weak HS256 secrets, missing expiry, and skipped issuer and audience checks.
- Pin the accepted algorithm on every verify call, use a random 256-bit or larger secret or RS256 keys, keep access tokens short-lived, and validate iss and aud against exact values.
On this page
The common JWT vulnerabilities are alg:none acceptance, RS256-to-HS256 algorithm confusion, brute-forceable HS256 secrets, tokens with no expiry, sensitive data in the payload, no revocation path, and missing iss/aud checks. Each has a one-line fix, and most come down to the same rule: never let the token's own header decide how it gets verified.
Verified against
jsonwebtoken 9.0.3 (npm), RFC 8725 (JWT Best Current Practices) and RFC 7518 (JWA), against the IETF RFC texts, the jsonwebtoken changelog and the OWASP JWT Cheat Sheet. Checked October 2026.
A JSON Web Token is a signed, self-contained credential made of three base64url segments (header.payload.signature) that a server can verify without a database lookup. JWTs are popular because they're stateless: sign a user ID and some claims, and any service holding the secret or public key can verify the token later without a session store. That convenience is also the source of most JWT bugs. A stateless token has no built-in way to check "has this been revoked" or "was this issued for me," and library defaults have historically been loose about which algorithm they'll accept. These are well-documented vulnerability classes, called out in RFC 8725, the IETF's JWT Best Current Practices (February 2020), and tracked for years across pentest reports and library CVEs.
What is the alg:none attack?
The JWT header includes an alg field naming the signing algorithm, and early JWT libraries read that field and used whatever it said, including none. A token with {"alg":"none"} and an empty signature would pass verification, since the library skipped the check the header told it to skip. An attacker who can see a valid token edits the payload, sets alg to none, drops the signature, and the server accepts a token it never validated.
Most current libraries reject none by default (the OWASP JWT Cheat Sheet still tells you to confirm your parser rejects "alg":"none"), but the pattern behind this bug (letting the token's own header decide how it gets verified) still shows up in other forms.
What is algorithm confusion?
RS256 uses a private key to sign and a public key to verify, so the public key is meant to be exposed. Algorithm confusion happens when a server expects RS256 but a naive verify call still trusts the alg field in the header. An attacker fetches the public key (often published at a .well-known JWKS endpoint), crafts a token with alg: HS256, and signs it using the public key as an HMAC secret. If the verify function follows the header, it hashes the public key against the token exactly as predicted, and a forged token comes back valid.
The root problem in both cases is the same: the header is attacker-controlled input, and letting it dictate verification behavior hands the attacker the keys to the check.
// Vulnerable pattern: trusts whatever algorithm the token claims.
// jsonwebtoken before 9.0.0 accepted an HS256 token signed with
// the public key here (CVE-2022-23540, CVE-2022-23541).
const payload = jwt.verify(token, publicKey);
// Fixed: pin the expected algorithm explicitly
const payload = jwt.verify(token, publicKey, {
algorithms: ['RS256'],
});
// Any token whose header says HS256, none, or anything
// other than RS256 is rejected before signature checking.
jsonwebtoken 9.0.0 (December 2022) closed that default by deriving allowed algorithms from the key type and rejecting keys that don't match the algorithm, and it is at 9.0.3 as of October 2026. Don't rely on that. RFC 8725 requires libraries to let callers specify the permitted algorithms, and every mainstream library exposes an option for it. Set it on every verification call, in every language, and never derive the expected algorithm from the token itself.
Weak or guessable HS256 secrets
HS256 uses one shared secret for both signing and verification. If that secret is short, a dictionary word, or copied from a tutorial and never rotated, an attacker with one valid token can brute-force it offline: try candidates, recompute the HMAC, compare against the signature. Once recovered, they can forge any token for any user.
RFC 7518 requires an HS256 key at least as large as the hash output, 256 bits (32 bytes), and RFC 8725 forbids using human-memorizable passwords as HMAC keys. Generate one with openssl rand -base64 32 and store it in a secrets manager, not a config file in the repository. Better still, use RS256 for anything beyond a single trusted service, since the signing key never has to leave the issuing server.
Tokens that never expire
A JWT with no exp claim, or one set to some far-future date "so users don't have to log in again," turns a single leaked token into a permanent credential.
Set short expiries, minutes to a couple of hours for access tokens, paired with a separate refresh token that has its own longer, still bounded, expiry, stored and transmitted more carefully (HttpOnly cookie, rotated on use). The access token stays cheap to reissue, and cheap to lose if it leaks.
Sensitive data in the payload
The payload is base64url-encoded, not encrypted. A browser extension, a proxy log, or a curious user pasting the token into jwt.io can decode it and read every claim. Storing a password, a full credit card number, or other PII directly in a JWT payload exposes that data to everyone the token passes through.
Keep the payload to non-sensitive identifiers: a user ID, a role, an expiry, an issuer. If a claim needs to stay confidential from the token holder, look it up server-side instead of embedding it, or use JWE (encrypted JWTs) for the rare case an opaque encrypted claim is genuinely required.
How do you handle JWT revocation?
JWTs are validated by signature and expiry alone, so a stolen but still-valid token keeps working until it naturally expires. There's no built-in way to say "this one token is dead now," because that requires a lookup, and a lookup defeats the point of a stateless credential.
Two approaches close the gap. First, keep access token lifetimes short so a leaked token has a small window of usefulness, and rely on the refresh flow for renewal. Second, maintain a denylist (or an allowlist of active session IDs) in a fast store like Redis, checked on each request for the tokens that matter most: admin sessions, password-reset tokens. That reintroduces a bit of state, but only for the highest-value tokens.
Missing issuer and audience validation
A JWT can carry iss (issuer) and aud (audience) claims stating who issued it and who it's meant for. If a service checks the signature and expiry but never validates iss or aud, a token issued for one API can be replayed against a different API that trusts the same signing key. This is common where a shared auth provider serves multiple internal services: a token minted for a low-privilege reporting service ends up accepted by billing, because nothing checked it was meant for billing.
RFC 8725 makes audience validation a MUST: reject the token if aud is missing or doesn't name the recipient. Validate both claims on every verification call, against the exact expected values for that service, not a wildcard. If you validate at the edge instead of in each service, verifying JWTs at the edge covers how to keep those checks intact.
To inspect a token's header and claims without sending it to a third-party site, use our JWT decoder, which runs entirely in the browser and flags alg: none and expired tokens.
The call we'd make
Pin the algorithm explicitly on every verify call, favor RS256 with keys in a secrets manager over HS256 with a shared string, keep access tokens short and paired with refresh tokens, keep the payload free of anything sensitive, and check iss/aud alongside the signature. None of these fixes are exotic, and together they cover the vulnerability classes that keep showing up in JWT security reviews. See application security best practices and secure authentication and session best practices for the wider picture.
Sources
Cite this article
Kiril Urbonas (2026). JWT Security: Common Vulnerabilities and How to Avoid Them. DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/jwt-security-vulnerabilities
[JWT Security: Common Vulnerabilities and How to Avoid Them](https://www.devopsness.com/blog/jwt-security-vulnerabilities) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)
More from DevOps
Explore more articles in this category
GitHub's September 13 Outage: One Cleanup Job, Many Services
A background cleanup job saturated a shared database behind GitHub, and the safeguard pacing it watched only replica lag. Throttle on more than one signal.
Drone vs Woodpecker CI: Lightweight Self-Hosted CI
Woodpecker forked Drone when the license changed. Here's how the two compare for small teams and homelabs that just want simple container-native CI.
Fix "Error Acquiring the State Lock" in Terraform
A stuck state lock stops every apply cold, and the fix is one command away once you confirm nobody else is actually running Terraform.
You might have missed
Evergreen posts worth revisiting.