The scanner says the API accepted a forged JWT. Did it accept the token, or ignore it? JWT validation as a DAST finding: alg none, algorithm confusion, decode without verify, weak HMAC secrets, kid and jku, exp, aud and logout, and how the finding gets confirmed

DedSec Security Research ·

Here is a hypothetical. A dynamic scan of a web application's JSON API returns four results from its token checks. The first, titled "JWT signature not verified: alg none accepted" and rated critical, is on /api/catalog. The scanner rewrote the session token's header to {"alg":"none"}, dropped the signature and got a 200. The second, titled "JWT signed with a weak secret" and rated medium, is on /api/account. The scanner took the token from the login response, found its HMAC secret in a wordlist, and stopped there. The third, titled "Session token valid after logout" and rated low, is on /api/orders. The fourth is /api/billing. There the scanner sent an HS256 token keyed with the service's published RSA public key, got a 401 and reported the endpoint clean.

The critical gets an incident channel. The medium goes to a developer. The low goes into the backlog, and nobody looks at the clean result. As in the earlier posts in this series, each call rests on the title and the rating rather than on what the scanner observed and what that observation can prove. A 200 shows that the server answered, not that it believed the token, and a public catalogue answers everyone. The cracked secret is the strongest evidence of the four, because the proof is arithmetic, yet it is rated below the one that proves nothing. The logout finding is how a stateless token behaves unless someone built revocation, so it is a question about design and about how long the token lives. The clean result tested one variant out of eight.

This post is for whoever is holding a JWT finding from a dynamic scan, or a clean result they are about to rely on. It covers:

It is the fourteenth post in a series about confirming DAST findings. The earlier ones cover reflected XSS, SQL injection, OS command injection, Nuclei template matches, ffuf content discovery, path traversal, open redirect, SSRF through URL-fetch parameters, XXE, CRLF header injection, Host header injection, HTTP request smuggling and CORS misconfiguration. The nearest neighbour is the BOLA and IDOR post. A forged token that changes sub asks the same question from the token's side: can this caller get another user's data?

Sources, and how each was checked. We made the measurements below on our test machine on 3 November 2026. It runs Ubuntu 24.04 on a virtual machine with two vCPUs of an AMD EPYC 9354P, and every server was bound to 127.0.0.1. The software was:

We generated a 2048-bit RSA key pair and a P-256 EC key pair for the run, and built every test token by hand, so that no library's encoder decided what a forged token looked like. Library behaviour below is what we measured. Where we explain it from source, we read the installed copy on disk.

We downloaded the texts of RFC 7519 (JWT), RFC 7515 (JWS), RFC 7518 (JWA) and RFC 8725 (the JWT best current practice) from the RFC Editor on the same day, and checked every section number cited here against those texts. We checked the CWE entry names on MITRE's site the same day. The wordlist is SecLists' Passwords/scraped-JWT-secrets.txt, 103,979 lines, copied from a copy already on the machine.

We did not test any Java, Go, .NET, Ruby or PHP library. We also did not test older versions of the five libraries, encrypted tokens (JWE) or nested tokens, or a verifier that follows jku or x5u. Nor did we test an embedded jwk header, a kid used in an SQL query, ECDSA-specific signature bugs, GPU or dedicated cracking tools, any identity provider, or any scanner. The opening scenario is hypothetical, and no number in this post measures any scanner, ours included.

What a verifier has to check

A JWT in compact form is three base64url segments separated by dots: a JOSE header, a claims set and a signature. RFC 7519 section 7.2 lists the steps for validating one and, for a signed token, hands the signature check to RFC 7515 section 5.2. The work splits into two layers, plus one question neither layer answers.

The cryptographic layer. The verifier checks the signature or MAC with a key it trusts, using an algorithm it chose. The header's alg (RFC 7515 section 4.1.1) is the token's own claim about how it was signed, and it arrives from whoever sent the token. RFC 8725 section 3.1 says libraries must let the caller specify the allowed algorithms and must not use any others. It also says each key must be used with exactly one algorithm. RFC 7519 section 7.2 ends on the same point: even a token that validates should be rejected unless its algorithms are acceptable to the application.

The claims layer. Once the signature holds, the claims say whether this genuine token is valid here and now. exp and nbf (RFC 7519 sections 4.1.4 and 4.1.5) bound it in time, aud (section 4.1.3) names its intended recipients, and iss (section 4.1.1) its issuer. Section 4.1.3 is strict: if the token has an aud and the recipient does not identify itself with a value in it, the token must be rejected. RFC 8725 section 3.9 adds that when one issuer issues tokens for more than one relying party, the token must carry an audience and each relying party must check it. RFC 8725 section 3.8 says the application must check that the signing keys belong to the issuer the token names.

Whether a once-valid token should still be accepted. A signed token is a bearer credential that carries its own validity, and nothing in the format tells the server that the user has logged out.

The claim a finding must support

The usual classification for the signature variants is CWE-347 (Improper Verification of Cryptographic Signature), with CWE-345 (Insufficient Verification of Data Authenticity) as the broader entry. Reports about tokens that survive logout often cite CWE-613 (Insufficient Session Expiration). When we checked MITRE's site on 3 November 2026, that entry was titled as deprecated as of CWE 5.0, and CWE-1462 (Improper Session Management) is the entry to look at instead.

Whatever the label, an exploitable token-validation finding is a conjunction of three things:

  1. The attacker can produce the token. It may be forged, altered, issued for another context, or stale.
  2. The server used it for an authorisation decision. The response is one that only an accepted token gets.
  3. The identity or scope it granted is one the attacker should not have.

Scanner evidence is usually thinnest on point 2. A 200 is not "the response only an accepted token gets". The evidence needs three baselines from the same endpoint, taken close together:

A forged token was accepted when its response differs from both failure baselines and matches the authenticated one. A forged token that changed identity is proved when the response belongs to the identity the forged token claimed, which should be a second test account and not the one the scanner logged in as. We measured why each of those conditions matters below.

The variants, in mechanism

alg none. RFC 7519 section 6 defines an Unsecured JWT: "alg": "none" and an empty signature. RFC 7518 section 3.6 says implementations must not accept unsecured tokens by default, and that applications must not signal acceptance of them globally. RFC 8725 section 2.1 lists the attack: change alg to none, and some libraries will "validate" the token without checking any signature. The evidence should be an unsigned token whose sub names a second test user, answered with that user's data. Scanners also send None and NONE, in case one part of the code compares the value case-sensitively and another part does not.

Signature never verified. This is the decode-without-verify bug: the code calls the function that parses a token instead of the one that verifies it. Every library has a parse-only function, for good reasons, such as reading kid to choose a key or displaying claims in a client. The evidence is the cheapest of any variant: the valid token with one signature byte changed gets the authenticated response. If that baseline succeeds, every other variant on that endpoint is moot.

Algorithm confusion. A service signs with RS256 and verifies with its public key. Suppose the verifier lets the token choose HS256 and hands the same key material to the HMAC code. The attacker already has the public key, because it is public, so they compute an HMAC over a forged token using the public key's bytes as the secret. RFC 8725 section 2.1 describes the attack and cites CVE-2015-9235 as an instance. One detail matters for testing: the HMAC key is the exact byte string the server holds. The attacker has to match the encoding, the header lines and the trailing newline. The evidence is an HS256 token keyed with the service's published public key, accepted with a changed sub.

Weak HMAC secret. HS256 is a MAC, so anyone who holds the secret can sign. If the secret is guessable, one captured token is enough to test candidates offline. You compute HMAC-SHA256 of the token's header and payload under each candidate and compare the result with its signature. The standards cover this from three directions:

Here the scanner's proof is strongest and needs least from the server. A candidate that reproduces a 256-bit HMAC over the token's own content is, for any practical purpose, the key. The only server traffic is the request that obtained the token, and one forged token accepted completes the confirmation.

kid, jku and x5u. RFC 7515 section 4.1.4 defines kid as a hint whose structure is unspecified. Sections 4.1.2 and 4.1.5 define jku and x5u as URLs for a key set and a certificate. All three arrive in a header nobody has verified yet. RFC 8725 section 3.10 names the consequences. A kid used in a lookup can carry SQL or LDAP injection. Following jku or x5u blindly can be server-side request forgery, so the RFC recommends matching the URL against an allow-list of locations. The rest of this paragraph is general practice rather than RFC text. For jku, the worse outcome is key injection: a verifier that fetches the key set from the URL in the token checks the attacker's token with the attacker's key. When kid is used as a file path, the classic move is to point it at a file whose contents the attacker knows. /dev/null is the shortest choice: the key becomes empty, and anyone can compute an HMAC with an empty key. We measured that case, and what each library does with an empty key.

We also searched the installed source of all five libraries. None of them fetches a URL taken from a token's header. joserfc only checks that jku and x5u header values are URLs. So in these five, jku and x5u injection would be a bug in application or framework code, and we did not build or measure such a verifier.

exp and nbf not enforced. The library supports the checks, but the claim is missing, the check is turned off, the leeway is large, or a parse-only path skipped validation. RFC 7519 section 4.1.4 allows leeway of "usually no more than a few minutes". The evidence needs a genuinely issued token that has expired. A scanner cannot make one by editing exp, because editing breaks the signature, so that test checks the signature instead.

aud and iss not checked. A token issued by the same identity provider for a different service is genuine, so its signature verifies. RFC 8725 section 2.7 calls this a substitution attack. The evidence needs a real token issued for another audience by the same issuer, which a scanner usually does not have.

Accepted after logout. In a stateless design, logout deletes the client's copy of the token, and the server accepts the token until exp unless it keeps state. The options are a denylist of jti values (RFC 7519 section 4.1.7), a per-user "issued before" cut-off, or short-lived access tokens with refresh tokens the server can revoke. The evidence is the same token accepted after the logout response. Whether that is a vulnerability depends on how long the token lives and what logout is supposed to guarantee.

What five libraries did, measured

A script ran every token through PyJWT 2.7.0, python-jose 3.5.0 and joserfc 1.8.0, and a second script through jsonwebtoken 9.0.2 and jose 6.2.15.

alg none

None and NONE were rejected by every library in every verifying configuration. We tested nOnE against the three Python libraries only, and it was rejected there too.

Algorithm confusion

We built HS256 tokens claiming an admin identity, each HMAC'd with the exact bytes of one public-key encoding: RSA as SPKI PEM, PKCS#1 PEM and OpenSSH, and EC as SPKI PEM and OpenSSH. For the Node libraries we added RSA as DER. Each verifier was then given that same key material.

At these versions, with key types left for the library to decide, the confusion did not happen through the PEM path in any of the five. It happened where the code, or a key format the library could not classify, took the decision away from the library.

Decode without verifying

jsonwebtoken's decode, jose's decodeJwt, python-jose's get_unverified_claims and PyJWT's decode with verify_signature off each returned the tampered sub of a token whose payload we had edited. Each was doing its job, but the two Python libraries behaved differently when the bug was in place:

So the same bug has a different blast radius in each library.

exp and nbf

aud and iss

This is where the libraries differed most.

CaseAccepted byRejected by
Token has aud: "billing-api"; verifier given no audiencejsonwebtoken, jose, joserfc's registry configured without audPyJWT ("Invalid audience"), python-jose
Token has no aud; verifier configured with "orders-api"python-josePyJWT, jsonwebtoken, jose, joserfc with aud marked essential

With no issuer configured, all five accepted a token naming https://other-idp.example. We configured an issuer in four of them, all but joserfc, and each of those four rejected both a mismatched iss and a missing one.

PyJWT's rejection follows the RFC 7519 section 4.1.3 rule. It also means a service that starts receiving tokens with an aud gets an InvalidAudienceError the first time, and options={"verify_aud": False} makes the error go away. Our lab's /noaud endpoint is written that way. The python-jose case is the one RFC 8725 section 3.9 rules out when an issuer serves several relying parties.

Empty key

We built an HS256 token HMAC'd with an empty key, with kid set to a traversal path to /dev/null.

LibraryEmpty stringEmpty bytes
PyJWTacceptedaccepted
python-joseacceptedaccepted
joserfc—refused ("oct key material must not be empty")
jsonwebtokenrefused ("secret or public key must be provided")accepted, with or without algorithms: ["HS256"]
jose—refused, zero-length Uint8Array ("Zero-length key is not supported")

In Node, fs.readFileSync("/dev/null") returns an empty Buffer of length 0 (checked with Node v22.22.2). So a jsonwebtoken service with a kid-as-path bug lands on the accepting branch, while a lookup that returns an empty string does not.

A six-byte secret

All five signed and verified HS256 with the key "secret". joserfc emitted "SecurityWarning: Key size should be >= 112 bits". None refused.

Cracking one HS256 token, measured

The script took one token and the 103,979-line SecLists list of JWT secrets. It ran in a single Python 3.12.3 process on one thread, using hmac and hashlib, and made no network requests.

We did not try a GPU or a dedicated cracking tool. The cost of the list is negligible. What matters is whether the secret is in some list or reachable by some rule, and a random 256-bit key is in neither. A scanner that reports a weak secret has the secret, so ask for it. A scanner that reports "not cracked" has shown only that the secret is not in its list.

A scanner's view of the lab API, measured

The lab API was a Python standard-library HTTP server on 127.0.0.1. It served the same /me resource behind different token checks:

A /public/news endpoint ignored the Authorization header entirely. The probe logged in as alice and took the three baselines. It then sent seven forged tokens: six claimed sub: "bob", a second real user, so that acceptance would show bob's data, and one unsigned token claimed admin, a user who does not exist. Where the endpoint took RS256 tokens, it also sent two genuine tokens from the lab issuer: one issued for billing-api, and one that had expired 60 seconds earlier. The naive verdict was "status 200". The careful verdict was "body differs from both failure baselines and shows bob", or, for the two genuine tokens, "body equals the valid response".

That is eighteen false positives from two endpoints that never trusted a token. On the forged tokens sent to /decode-only, /confused, /weak and /kid, which did accept forged tokens, the two verdicts agreed. On /decode-only's two genuine tokens they did not: the naive verdict accepted both, and the careful one did not count either as proof. They agreed because the forged tokens claimed bob, a user who exists. Both verdicts missed the one forged token that claimed a user who does not exist.

Logout. On /strict, a fresh token was accepted, the logout call returned 200, and the same token was accepted again with 600 seconds of its lifetime left. On a /revocable endpoint that adds the token's jti to a server-side denylist at logout, the same sequence ended in a 401.

A shared cache. We put nginx 1.24.0 in front of /strict with a proxy cache keyed on the request URI alone, holding 200 responses for 60 seconds. Alice's valid request was a cache MISS and got her data. The next three requests were all cache HITs answered with alice's data: one with no token, one with an unsigned token claiming bob, and one with the string x.y.z. With the Authorization header added to the cache key, the requests with no token and with the forged token were MISSes answered with 401, and alice's second request was a HIT.

The forged token's "acceptance" was the cache, and the no-token baseline gave it away by getting the same body. That baseline is itself a worse finding than the one the scanner reported: any anonymous caller gets alice's data for as long as the entry lives. It also depends on order. If the baselines run before anyone's authenticated response is in the cache, they come back clean.

What scanners flag that is not exploitable

What scanners miss

Confirming a finding by hand

The procedure below is general practice. Use two test accounts, never real users' identities.

  1. Read the token. Decode the header and payload, for example cut -d. -f1 <<<"$T" | basenc --base64url -d. You may need to add = padding first. Note alg, kid, jku, aud, iss, exp and jti.
  2. Take the three baselines on the endpoint in the finding, with every other credential stripped: no token, the token with one signature character changed, and the valid token. If the changed-signature request succeeds, stop there: the signature is not checked.
  3. Forge as the second test user. Copy the claims, change sub (or whatever field carries identity) to user B, and build each variant: none with an empty signature; HS256 keyed with the public key exactly as the service publishes it, and with its final newline both present and absent; and HS256 keyed with an empty string. A few lines of Python with hmac and base64 are enough, and building the token by hand avoids a library refusing to produce it.
  4. Decide on the body. The forged request is accepted if it returns user B's data, and only then.
  5. For a weak secret, reproduce the HMAC with the reported secret over the token's first two segments. If it matches, sign a token for user B and send it.
  6. For exp, aud and iss, get genuine tokens: one that has expired, one issued for another service by the same issuer, and one from another issuer if your environment has one. Send each.
  7. For logout, log in, call logout, and replay the same token. Record how long the token had left.
  8. Check caching by sending the valid request and then the no-token request through the same front end, and read any cache-status header.
  9. Keep the evidence: each token, the request and response pairs for the baselines and the forged requests, and the library and version if you can read them from the code.

The fix

All of this is general practice, except where it says it was measured.

The static side

Most of these bugs are visible in source. Parse-only calls on an authorisation path are easy to find: jwt.decode with verify_signature off, get_unverified_claims, and jsonwebtoken's decode followed by a role check. So are configuration flags such as verify_aud off, ignoreExpiration: true, "none" in an algorithms list, and an algorithms list that mixes HS with RS or ES.

Header-driven choices are taint problems. The source is the unverified header. The sinks are an algorithms argument, a file open, an SQL query or an HTTP fetch. That is the same source-to-sink machinery as any injection. A hard-coded HMAC secret is a secrets-scanning finding, and it stays one in history after it is deleted from the code.

The SAST false-positive post describes a sanitiser credited against a sink it does not sanitise, and the token version is a rule that treats any function named verify as making the claims trustworthy. Our hand-rolled /confused verifier was called "verify" and accepted a forged token.

What source does not show:

Those are the parts of the confirmation that needed the running system.

A triage checklist for a DAST JWT finding

  1. Did the evidence compare bodies against the no-token and the flipped-signature baselines, or only status codes?
  2. Does the flipped-signature token succeed? If it does, the finding is "signature not verified", and the other variants are moot on that endpoint.
  3. Did the forged token claim a second real user, and did the response show that user's data?
  4. Is the endpoint public, a soft-200 endpoint, or behind a cache keyed without credentials?
  5. For a weak secret, what is the secret, and does a token signed with it for another user get accepted?
  6. For algorithm confusion, which exact key bytes were used, and from where?
  7. For exp, aud and iss, were genuine tokens used?
  8. For kid, which paths and depths were tried? For jku and x5u, did the server make a request?
  9. For logout, how long did the token have left, and what is logout supposed to guarantee?
  10. Retest after the fix with the variant that raised the finding, plus the others, and confirm that the scan reached the handler and not a login redirect. The scan-passed post covers how that goes wrong.

The hypothetical findings, resolved

Back to the four hypothetical findings.

/api/catalog. In the scenario, the "alg none accepted" critical was on a public catalogue. The unsigned token's response was byte-for-byte the no-token response. The same unsigned token, claiming a second test user against /api/account, got a 401. The finding was closed as a false positive, with the comparison attached.

/api/account. In the scenario, the weak-secret medium was the real critical. The secret the scanner found reproduced the token's signature. A token signed with it for a second test user returned that user's profile, and the secret had been committed to the repository two years earlier. The fix was a random 256-bit key, invalidating every outstanding session, and removing the secret from configuration in code. The old key stays in history, so rotating it was the actual fix.

/api/orders. In the scenario, the logout finding was confirmed: tokens lived for twelve hours and logout cleared only the browser's copy. The team shortened access tokens and added revocable refresh tokens. They also added a jti denylist for explicit logout, kept until each token's exp.

/api/billing. In the scenario, the clean result on billing was a false negative of a different variant. The confusion probe was correctly rejected. However, the verifier had verify_aud turned off after an InvalidAudienceError, and it accepted a genuine token that the same identity provider had issued for the reporting service. The fix configured the audience and the issuer. The retest used genuine tokens for both.

Where AppSecD fits

AppSecD's dynamic and API testing runs Nuclei, Dalfox, SQLMap, Commix, Katana, Arjun, FFuf and Interactsh for out-of-band detection, plus 150+ native checks and API discovery across 50+ web frameworks. Its secret detection runs TruffleHog and Gitleaks, deduplicated, over the working tree and the full git history, for API keys, tokens, private keys, database and cloud credentials, because a credential deleted in the latest commit is still in the repository. Its static analysis includes dataflow taint analysis that traces source to sink across functions. Its findings are deduplicated across scans and tracked through new, reopened and fixed states, and they need maker-checker approval to close, so a finding cannot be closed unilaterally.

That is the whole claim. data/products.ts is the single source of truth for what these products do, and it does not mention JWTs, JSON Web Tokens, signatures, token validation, OAuth, sessions or revocation at all. So this post does not claim that AppSecD tests JWT validation. Nor does it claim anything about:

The measurements, the confirmation procedure, the fixes and the checklist above are general practice, not a description of how AppSecD works internally, and they apply to any scanner's output, ours included. The scenario in this post is hypothetical and does not describe any AppSecD deployment, user or finding.

More about AppSecD · All posts