CVE-2026-102268
HMAC key misinterpreted as PEM public key allows token forgery.
- CVSS 9.1
- CWE-347
- Authentication, Authorization, and Session Management
- Remote
PyJWT is a Python implementation of JSON Web Token standards. Prior to 2.14.0, is_pem_format in jwt/utils.py is affected because is_pem_format does not recognize every PEM representation accepted by the cryptography loader. This occurs when an application mixes HMAC and asymmetric algorithms and supplies a mutated public-key PEM as raw key bytes. As a result, HMACAlgorithm.prepare_key treats the unrecognized asymmetric public key 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
- 9.1
- Published
- 2026-09-28
- OWASP
- A02 Cryptographic Failures
- Orthogonal defect classification
- Checking
- Code defect classification
- Missing Check
- 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
from jwt.utils import is_pem_format
def create_hmac_token(key_bytes: bytes, payload: dict) -> str:
# VULNERABLE: treats PEM as HMAC secret
token = jwt.encode(payload, key_bytes, algorithm="HS256")
return tokenPatched code sample
import jwt
from jwt.utils import is_pem_format
def create_hmac_token(key_bytes: bytes, payload: dict) -> str:
# FIX: reject PEM when using HMAC algorithms
if is_pem_format(key_bytes):
raise ValueError("PEM-formatted keys are not valid for HMAC signing")
token = jwt.encode(payload, key_bytes, algorithm="HS256")
return tokenPublished 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 loader-accepted PEM variants (jpadilla/pyjwt)
jwt/utils.py,jwt/utils.py · is_pem_format
Cite this entry
@misc{vaitp:cve2026102268,
title = {{HMAC key misinterpreted as PEM public key allows token forgery.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-102268},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-102268/}}
}
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 ::
