CVE-2026-102271
PyJWT uses DER public key as HMAC secret, enabling token forgery.
- CVSS 7.4
- CWE-347
- Authentication, Authorization, and Session Management
- Remote
PyJWT is a Python implementation of JSON Web Token standards. From 2.4.0 until 2.14.0, PyJWT HMACAlgorithm.prepare_key is affected because asymmetric-key guard relies on textual markers that are absent from DER encoding. This occurs when an application mixes HMAC and asymmetric algorithms and supplies a DER public key as the shared verification key. As a result, PyJWT uses public DER bytes as an HMAC secret. Consequently, an attacker who knows the public key can forge authenticated HMAC tokens. This issue is fixed in version 2.14.0.
- CWE
- CWE-347
- CVSS base score
- 7.4
- Published
- 2026-09-28
- OWASP
- A02 Cryptographic Failures
- Orthogonal defect classification
- Interface
- Code defect classification
- Incorrect Interface
- Category
- Authentication, Authorization, and Session Management
- Subcategory
- Insecure Authentication Mechanisms
- Accessibility scope
- Remote
- Impact
- Unauthorized Access
- Affected component
- PyJWT
- Fixed by upgrading
- Yes
Solution
Upgrade PyJWT to version 2.14.0 or later.
Vulnerable code sample
import jwt
def verify_token(token: str, verification_key: bytes, alg: str) -> dict:
"""
Verify a JWT using the supplied key and algorithm.
"""
# VULNERABLE: using DER public key as HMAC secret
return jwt.decode(token, verification_key, algorithms=[alg])Patched code sample
import jwt
def verify_token(token: str, verification_key: bytes, alg: str) -> dict:
"""
Verify a JWT using the supplied key and algorithm.
"""
# FIX: reject DER public keys for HMAC algorithms
if alg.startswith('HS') and b'BEGIN' not in verification_key:
# Assume raw HMAC secret; allow
pass
elif alg.startswith('HS'):
raise ValueError('HMAC algorithms require a raw secret, not a public key')
return jwt.decode(token, verification_key, algorithms=[alg])Published fix
Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.
- fix: reject DER public keys as HMAC secrets (jpadilla/pyjwt)
jwt/algorithms.py,jwt/algorithms.py · HMACAlgorithm.prepare_key
Cite this entry
@misc{vaitp:cve2026102271,
title = {{PyJWT uses DER public key as HMAC secret, enabling token forgery.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-102271},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-102271/}}
}
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 ::
