CVE-2022-29217
PyJWT allows an attacker to choose the signing algorithm
- CVSS 7.5
- CWE-327 Use of a Broken or Risky Cryptographic Algorithm
- Input Validation and Sanitization
- Remote
PyJWT is a Python implementation of RFC 7519. PyJWT supports multiple different JWT signing algorithms. With JWT, an attacker submitting the JWT token can choose the used signing algorithm. The PyJWT library requires that the application chooses what algorithms are supported. The application can specify `jwt.algorithms.get_default_algorithms()` to get support for all algorithms, or specify a single algorithm. The issue is not that big as `algorithms=jwt.algorithms.get_default_algorithms()` has to be used. Users should upgrade to v2.4.0 to receive a patch for this issue. As a workaround, always be explicit with the algorithms that are accepted and expected when decoding.
- CVSS base score
- 7.5
- Published
- 2022-05-24
- OWASP
- A06 Vulnerable and Outdated Components
- Orthogonal defect classification
- Checking
- Code defect classification
- Missing Check
- Category
- Input Validation and Sanitization
- Subcategory
- Insecure Parsing or Deserialization
- Accessibility scope
- Remote
- Impact
- Unauthorized Access
- Fixed by upgrading
- Yes
Solution
Upgrade to PyJWT version 2.4.0 or higher.
Vulnerable code sample
import jwt
SECRET_KEY = 'your_secret_key'
token = 'your_jwt_token_here'
try:
decoded_token = jwt.decode(token, SECRET_KEY)
print(decoded_token)
except jwt.InvalidTokenError as e:
print(f"Invalid token: {e}")Patched code sample
import jwt
SECRET_KEY = 'your_secret_key'
token = 'your_jwt_token_here'
try:
decoded_token = jwt.decode(token, SECRET_KEY, algorithms=['HS256'])
print(decoded_token)
except jwt.InvalidTokenError as e:
print(f"Invalid token: {e}")Cite this entry
@misc{vaitp:cve202229217,
title = {{PyJWT allows an attacker to choose the signing algorithm}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2022},
note = {VAITP Python Vulnerability Dataset, entry CVE-2022-29217},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-29217/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
