You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Security: Algorithm confusion via optional algorithms parameter (CWE-327) #419
python-jose: Algorithm confusion via optional algorithms parameter
Summary
jwt.decode() accepts algorithms=None (the default) without raising an error or warning. When algorithms is not specified, the verification algorithm is taken from the JWT header, which is attacker-controlled. This enables algorithm confusion attacks where an attacker signs a token with HS256 using the server's RSA public key as the HMAC secret.
PyJWT (the most widely used Python JWT library) fixed this class of issue by making algorithms a required parameter in version 2.x, raising DecodeError when it is omitted.
Affected versions
All versions through current (3.4.0). Tested on 3.4.0.
The gap
PyJWT (since 2.x):
importjwtjwt.decode(token, key) # DecodeError: algorithms must be specifiedjwt.decode(token, key, algorithms=["HS256"]) # OK
python-jose:
fromjoseimportjwtjwt.decode(token, key) # Silently accepts — algorithm from headerjwt.decode(token, key, algorithms=["HS256"]) # Also works
Proof of concept
fromjoseimportjwt# Attacker scenario: server uses RSA public key for verification# Attacker signs with HS256 using the public key as HMAC secrettoken=jwt.encode({'admin': True}, 'rsa_public_key_pem', algorithm='HS256')
# Server decodes without specifying algorithmsclaims=jwt.decode(token, 'rsa_public_key_pem') # No error# claims == {'admin': True}
Applications using python-jose that do not explicitly pass algorithms to jwt.decode() are vulnerable to authentication bypass via algorithm confusion. The attack requires knowledge of the server's public key, which is often publicly available (JWKS endpoints, certificate transparency, etc.).
Note on project status
This repo appears unmaintained (no SECURITY.md, no PVRT, last release Feb 2025, security issues filed as public issues). Filing as a public issue per the established pattern for this project (#398, #403).
Suggested fix
Make algorithms a required parameter, or emit a deprecation warning when it is omitted, and default to rejecting the token.
Activity