PyJWT BOM Bypass
## Affected Package - **Package**: PyJWT (`pyjwt` on PyPI) - **Repository**: https://www.google.com/url?q=https://github.com/jpadilla/pyjwt&source=gmail&ust=1781794518474000&sa=E - **Affected version**: 2.13.0 - **Vulnerability class**: Algorithm confusion / patch bypass --- ## Root Cause PyJWT 2.13.0 introduced a guard in `HMACAlgorithm.prepare_key()` (file `jwt/algorithms.py`, approximately line 344) to prevent RSA public key material from being used as an HMAC secret — the root cause of CVE-2026-48526. The guard uses `bytes.lstrip()` before calling `startswith(b"{")`: ```python stripped = key_bytes.lstrip() # strips ASCII whitespace only if stripped.startswith(b"{"): # JWK detection ... raise InvalidKeyError("The specified key is an asymmetric key...") ``` `bytes.lstrip()` with no argument removes only bytes in the ASCII whitespace set (`\x20 \t \n \r \x0b \x0c`). A UTF-8 BOM prefix (`\xef\xbb\xbf`) is not stripped, so `stripped.startswith(b"{")` returns `False` for any BOM-prefixed JWK JSON. The JWK detection block is never entered, and the RSA public key bytes are silently accepted as the HMAC-SHA256 secret. --- ## PoC Sketch (pseudocode — not a weaponized payload) ```python # 1. Attacker obtains RSA public key JWK (e.g., from /jwks.json endpoint) # and prepends a UTF-8 BOM byte sequence before the JSON opening brace. # 2. Attacker signs a JWT using HS256, with the BOM-prefixed JWK as the secret. # 3. Attacker submits the forged token to a verifier that: # - accepts algo
PYSEC-2026-4150
Primary source · Revision 2
Imported from structured advisory data. Source references identify upstream records or fields; verify affected versions and your deployed configuration.
Security context
Source reference: osv:PYSEC-2026-4150
pyjwt
Source reference: /affected/0/package/name
- Affected versions
- 2.13.0
Source reference:
/affected/0/versions - Fixed versions
- 2.14.0
Source reference:
/affected/0/ranges - Prerequisites
- Not stated in this record
Structured affected-version data
Original package identities and version rules from this source.
[
{
"ranges": [
{
"type": "ECOSYSTEM",
"events": [
{
"introduced": "2.13.0"
},
{
"fixed": "2.14.0"
}
]
}
],
"package": {
"name": "pyjwt",
"purl": "pkg:pypi/pyjwt",
"ecosystem": "PyPI"
},
"versions": [
"2.13.0"
],
"database_specific": {
"source": "https://github.com/pypa/advisory-database/blob/main/vulns/pyjwt/PYSEC-2026-4150.yaml"
}
}
]- Related CVEs
- CVE-2026-102272
Source reference:
/aliases
Publisher severity
No explicit severity was provided.
- Event
- #62570 · Revision 2
- Added to Heist Feed
- Publisher date