JWT Algorithm Confusion

The application lets a token's own header choose how it is verified, so an attacker can sign tokens using the public key as an HMAC secret, or send them with no signature.

SeverityCritical
CVSS 3.19.1 CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N Open in the calculator
CVSS 4.09.3 CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:N/SC:N/SI:N/SA:N Open in the calculator
CWECWE-347: Improper Verification of Cryptographic Signature
OWASP Top 10A04:2025 Cryptographic Failures
MITRE ATT&CKT1606 Forge Web Credentials, T1190 Exploit Public-Facing Application
CategoryCryptographic Failures

Description

Each JSON Web Token names its signing algorithm in the alg field of its header. The application, or the library it uses, takes that field at face value when verifying the token instead of enforcing the algorithm its key is meant for. An attacker can then forge tokens with any claims and have them accepted, so they can impersonate any user, including administrators, without credentials. The result is normally a complete bypass of the authentication the tokens provide, across every service that shares the vulnerable verification. Two forms are common:

  • Key confusion: the application expects tokens signed with an asymmetric algorithm such as RS256 and verifies them with its public key. If an attacker changes the header to HS256, a vulnerable verifier uses that public key as an HMAC secret. This needs only the public key, which is usually available to anyone: it is often published at a JWKS endpoint, and can otherwise be recovered from two signed tokens, so the attacker can sign tokens that pass the check.
  • Unsigned tokens: the verifier accepts the none algorithm, which is defined for unsecured tokens, and so accepts a token with an empty signature, which needs nothing at all. Some filters block only the lower-case value, so variants such as None or NONE succeed.

The same root cause, trusting the token to say how it should be verified, appears in the header parameters that select the key: a jwk header carrying the attacker's own public key, a jku or x5u address pointing to a key set the attacker hosts, or a kid value used unsafely in a file path or database query. These injected key forms also need nothing at all, and where kid is used in a file path or query, the attacker may also be able to read files or inject into the database. The weakness is confirmed by forging a token by each of these routes and observing that it is accepted. Tools such as jwt_tool and the JWT Editor extension for Burp Suite support these tests.

Remediation

Decide the algorithm and key on the server, never from the token:

  • Configure each verifier with an explicit allowlist containing only the expected algorithm, for example algorithms: ['RS256'] in the Node.js jsonwebtoken package or algorithms=['RS256'] in PyJWT, and bind each key to a single algorithm.
  • Reject none in any capitalisation, and any token whose algorithm does not match the key it is checked with.
  • Ignore the jwk, jku, x5u and x5c header parameters unless they are needed; where they are, accept only keys from a trusted, preconfigured key set or allowlisted addresses.
  • Use kid only to look up a key in a fixed set held by the server, never as a file path or in a query.
  • Keep the JWT library up to date, as several libraries have corrected defects in algorithm handling, and follow the JSON Web Token Best Current Practices (RFC 8725).

If forged tokens may already have been accepted, rotate the signing keys and review logs for tokens with unexpected headers or claims. Confirm the fix by repeating the key confusion, unsigned token and header injection tests and checking that every forged token is rejected.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Authentication and Sessions Findings

Every Authentication and Sessions finding