JWT Attacks: Forging the Token Itself

Day 11 broke timing. Today you break trust in a string the application never questions again once it sees a valid signature. A JSON Web Token, JWT, is a compact, self-contained way to carry identity and claims between parties, header, payload, and signature, each base64url encoded and joined with dots. Applications love it because the server does not need to look anything up, the token proves itself. That self-proving property is exactly what breaks when the verification logic has a gap, because once you forge a token the server trusts completely, you are whoever the token says you are.
This is the ninth injection-adjacent class in the series, and it connects back to Day 4’s IDOR and Day 5’s broken access control. Most JWT attacks are not really about cryptography. They are about getting the server to skip the one check that matters, does this signature actually prove what the algorithm claims it proves, and the payoff is almost always full authentication bypass or privilege escalation.
Inside scope only, using accounts you control. Forging a token that claims to be another real user is account takeover. Prove the forgery works using an account whose privilege boundary you own, an account you upgraded from low-privilege to admin claims yourself, never someone else’s real identity.
What a JWT actually is, and where the trust lives
A JWT has three parts: header.payload.signature. The header names the signing algorithm, the payload carries claims, like user ID and role, and the signature is a cryptographic proof that the header and payload were not altered since signing.
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0Iiwicm9sZSI6InVzZXIifQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
Decoded, the header says {"alg":"HS256","typ":"JWT"} and the payload says {"sub":"1234","role":"user"}. The server trusts that role field completely, because the signature supposedly proves nobody changed it after signing. Every JWT attack is some way of getting the server to accept a payload you changed, role included, while the server still believes the signature checks out.
Crucially, the header and payload are only base64url encoded, not encrypted. Anyone can decode and read them instantly at jwt.io. The entire security model rests on the signature, and nowhere else.
The attacks that still work
1. The none algorithm
The JWT specification allows alg: none, meaning the token is explicitly unsigned, intended for contexts where a token’s integrity is guaranteed some other way. Some JWT libraries, if the server does not explicitly reject it, will happily accept a token with alg: none and an empty signature, because the verification function sees the algorithm name and knows not to check a signature that was never claimed to exist.
header: {"alg":"none","typ":"JWT"}
payload: {"sub":"1234","role":"admin"}
signature: (empty)
Base64url encode the header and payload, join them with dots, and leave the signature segment empty, keeping the trailing dot. If the server does not enforce an algorithm allowlist, it accepts the forged claims outright. This is old, documented since at least 2015, and still turns up because developers inherit a library’s default behavior without auditing it.
2. RS256 to HS256 algorithm confusion
This is the single most consequential JWT attack, and it is worth understanding properly rather than just running a tool against it.
RS256 is asymmetric. The server signs tokens with a private key and verifies them with the matching public key. HS256 is symmetric. The same secret both signs and verifies. The vulnerability: if the server’s verification code does not strictly pin which algorithm it expects, and instead just reads the alg field from the token and uses whatever the token says, an attacker can take the server’s known public key, which is often not actually secret, published for SSO federation, embedded in a mobile app, or retrievable from a JWKS endpoint, and use it as the HMAC secret to sign a forged HS256 token.
The server then verifies using the same public key, but as an HMAC secret this time, and since the attacker signed with exactly that value, the signature checks out. The server believes it verified an RS256 token with its trusted public key. It actually just validated a token the attacker signed with that public key used as a symmetric secret.
This exact flaw, tracked as CVE-2015-9235, was found in the popular Node.js jsonwebtoken library and credited through HackerOne’s own bug bounty program, and it is explicitly called out as one of several critical vulnerabilities across JWT libraries documented by Auth0’s security team the same year. The fix on the defender’s side, and the thing to check for as a tester, is whether the verification call explicitly pins the expected algorithm rather than trusting the token’s own header.
3. kid parameter injection
The kid, Key ID, header parameter tells the server which key to use for verification when multiple keys are in rotation. Because kid has no fixed structure in the specification, poorly validated implementations are vulnerable to path traversal or SQL injection through it.
{"alg":"HS256","typ":"JWT","kid":"../../../../dev/null"}
If the server reads the file at the kid path and uses its contents as the HMAC key, and /dev/null reads as an empty string on many systems, you can sign your forged token with an empty string as the key, which the server will then also compute as empty, and the signatures match. Variants target SQL injection in a kid that gets used in a database lookup, or command injection in implementations that shell out based on it.
4. jku and x5u header injection
The jku, JWK Set URL, and x5u, X.509 URL, header parameters tell the server where to fetch the public key used to verify the token’s signature. If the server fetches this URL without restricting it to a trusted allowlist, an attacker generates their own key pair, signs a forged token with their own private key, and points jku at a JSON file they host containing their own public key.
{"alg":"RS256","typ":"JWT","jku":"https://attacker-controlled.com/keys.json"}
The server fetches the attacker’s key set, uses the attacker’s public key to verify, and of course it matches, since the attacker signed with the matching private key. This is both a JWT forgery technique and, notably, a specific flavor of the SSRF class from Day 9, since the vulnerable behavior is the server making an outbound fetch to a URL you control.
5. Embedded JWK header injection
A variant that avoids needing an externally hosted key entirely. Instead of pointing to a URL, the attacker embeds the public key directly inside the token’s own header, in a jwk field, and signs the token with the matching private key. If the server trusts an embedded key without checking it against a known, pinned key, it verifies the attacker’s self-signed token successfully using the attacker’s own embedded key.
6. Weak or default secrets
Symmetric HS256 tokens are only as strong as the secret behind them. Weak, short, default, or leaked secrets, found in public GitHub repositories, example configuration files, or guessed from a small wordlist, let an attacker brute force the key offline using tools built exactly for this, then sign any forged token they want.
Real disclosed cases and CVEs
- CVE-2015-9235, jsonwebtoken RS256-to-HS256 confusion. Credited through HackerOne’s bug bounty program, this flaw in the widely used Node.js
jsonwebtoken library let an attacker take a known RSA public key and resign a token as HS256 using it, with the library’s verification accepting the result. Auth0’s security research team documented this alongside several other critical JWT library flaws disclosed the same period, underlining how common the algorithm confusion mistake was across the ecosystem, not just one library.
- GitLab, path traversal leaking a JWT token, CVE-2021-22190. Reported by researcher ledz1996 through GitLab’s HackerOne bug bounty program as report #1040786, a path traversal flaw in GitLab Workhorse resulted in the leakage of a JWT token, which an attacker could then replay directly, a reminder that JWT attacks are not always about forging a signature, sometimes the token is simply exposed by an unrelated bug elsewhere in the stack and the impact is identical.
- CVE-2022-21449, “Psychic Signatures” in Java’s ECDSA implementation. While not HS256 or RS256 specific, this widely covered flaw in certain Java versions allowed an all-zero signature to be accepted as valid for ECDSA-signed JWTs, meaning an attacker could forge a token with literally no real signature at all, by exploiting a implementation bug in how the signature value of zero was handled during verification.
- HealthTrack, alg:none exploit in a bug bounty program (YesWeHack), reported February 2024. A researcher found that despite tokens normally being HS256-signed and valid, the server performed no explicit algorithm enforcement, meaning a forged
alg:none token with the signature stripped was still accepted, bypassing authentication entirely. The report was triaged within three days and paid a bounty, a smaller program example showing this class of bug is still found and still paid today, not only on flagship programs.
Read the GitLab report for how a completely unrelated bug class, path traversal, can deliver you a usable JWT without any forgery at all. Then study CVE-2015-9235 for the algorithm confusion mechanics in depth, since it is the attack most worth understanding at the implementation level rather than just running a tool against.
Where to look, pointed at your recon
- Any Authorization header carrying a Bearer token, or any cookie whose value decodes cleanly as three base64url segments separated by dots.
- SSO, OAuth, and OIDC flows, where JWTs are the standard currency for ID tokens and access tokens, and where
jku and jwk usage is especially common due to key rotation needs across identity providers.
- Mobile app API traffic, captured via proxy, since mobile backends often reuse the same JWT verification code as the web app but trail behind on patches, and public keys embedded in mobile app binaries are a common source of the exact key material algorithm confusion attacks need.
- Any endpoint that returns a JWKS document, typically at a path like
/.well-known/jwks.json, which hands you the server’s own public keys directly, exactly the material an RS256-to-HS256 confusion attack needs.
- Password reset and email verification links containing a token, since these are frequently JWTs with short-lived claims, and a forged or extended-expiry version can be a serious account takeover path.
How to hunt it, step by step
Step 1: find and decode the token. Capture any JWT in use, Authorization header, cookie, or URL parameter, and decode it at jwt.io or with jwt_tool. Note the algorithm and every claim in the payload, especially role, permission, or user ID fields.
Step 2: test the none algorithm. Change alg to none in the header, strip the signature entirely, keep the trailing dot, and resend. If the server accepts it, you have the simplest possible bypass.
Step 3: test algorithm confusion, if the token is RS256 or similar. Obtain the server’s public key, from a JWKS endpoint, an SSO metadata document, or embedded in a client application, and sign a forged HS256 token using that exact public key string as the HMAC secret. Tools like jwt_tool with the -X k flag, or Burp’s JWT Editor extension, automate this correctly, since getting the exact key formatting right by hand is error-prone.
Step 4: test kid injection. Try path traversal values like ../../../../dev/null, SQL-injection-style values if the kid plausibly feeds a database lookup, and observe whether the server’s error behavior or acceptance of your forged signature reveals anything.
Step 5: test jku and embedded jwk injection. Host a JSON Web Key Set on a server you control, sign a token with your own matching private key, point jku at your hosted key set, and send it. Separately, try the embedded jwk header variant, which needs no external hosting at all.
Step 6: test secret strength for HS256 tokens. Run the captured token through a dictionary and brute force tool built for this, since a successfully cracked secret means you can forge any claim at will going forward.
Step 7: whatever technique works, escalate the claim meaningfully. Change a role from user to admin, change a sub to another account’s ID you control for testing, or extend an expiry far into the future, and confirm the server actually honors the changed claim with real elevated access, not just that the token parses without error.
Writing the JWT report
Title: JWT [none algorithm / RS256-HS256 confusion / kid injection / jku injection]
allows authentication bypass / privilege escalation
Summary:
One sentence: which endpoint issues or verifies the token, which
technique forged a valid signature, and what claim was escalated.
Steps to Reproduce:
1. Capture a valid JWT issued to [low-privilege test account].
2. Decode it and modify [header field / payload claim] to
[forged value], using [technique: none algorithm / public key
as HMAC secret / kid path traversal / malicious jku].
3. Resend the request with the forged token in place of the
original.
4. Observe the server accepts the token and grants [elevated
access / another identity's claims].
(Exact original and forged tokens, decoded contents side by side,
the tool or script used to construct the forgery, and proof of the
elevated access obtained.)
Impact:
An attacker can forge a validly-accepted JWT without knowing the
server's actual signing secret or private key, by [specific
technique]. This allows [authentication bypass / privilege
escalation to admin / impersonation of any user ID]. State the
worst reasonably demonstrated outcome.
Remediation:
Explicitly pin and enforce the expected signing algorithm server
side; never trust the alg value from the token itself. Reject
alg:none outright. Validate kid against a fixed, server-controlled
key registry rather than using it to construct a file path or
query. Restrict jku and x5u to a strict allowlist of trusted
hosts, or disable them if not required. Use a long, randomly
generated secret for any symmetric algorithm, and rotate keys on
a defined schedule.
Strong JWT reports show the original and forged tokens decoded side by side, name the exact technique rather than a vague “JWT is insecure,” and demonstrate the escalated claim actually granted real access, not merely that a malformed token was accepted without erroring.
What programs often reject
- A none-algorithm or weak-secret finding against a token that carries no meaningful authorization claims, where forging it grants nothing beyond what an unauthenticated user already has
- Reports that show a forged token was accepted structurally but do not demonstrate it actually unlocked elevated access or another identity’s data
- Findings against a JWT library’s own known, already-patched CVE where the target is confirmed to be running a current, fixed version
- Theoretical algorithm confusion claims with no actual working forged token demonstrated end to end
The mindset: a signature is a claim about trust, not about data
Every class in this series has asked whether a boundary actually enforces what it claims to enforce. JWT attacks sharpen that question to its purest form: the token’s entire security model is one verification step, and every technique here is some way of making that one step pass without the server actually confirming what it thinks it confirmed. Once you internalize that a signature only means something if the verifier is strict about which algorithm, which key, and which source it trusts, you will read every token-based authentication system differently.
Homework for Day 12
- Capture a JWT from any application you are testing, decode it fully, and list every claim it carries, with special attention to role, permission, and ID fields.
- Test the none algorithm bypass first, since it takes seconds to try and still works against a surprising number of targets.
- If the token uses RS256, locate the server’s public key via a JWKS endpoint, SSO metadata, or a client-side source, and attempt the RS256-to-HS256 confusion forgery using a tool built for it.
- Test kid injection with a path traversal value, and jku or embedded jwk injection by hosting your own key set.
- Read the CVE-2015-9235 writeup and the GitLab CVE-2021-22190 report (hackerone.com/reports/1040786) end to end. For each, note the specific implementation mistake that made the forgery or leak possible, and how the fix changed the verification logic rather than just patching a symptom.
A confirmed JWT forgery leading to privilege escalation or authentication bypass is typically critical severity, since it usually grants complete account or administrative access with no further steps required. Document it with the decoded before and after tokens, the exact technique, and the algorithm-pinning remediation.
Day 13 moves to a bug that lives in how an application decides whether a file you uploaded is actually safe to store and serve, insecure file upload handling, and how it chains into remote code execution.