PyJWT: Public keys in DER form are accepted as HMAC secrets, bypassing the CVE-2022-29217 guard
### Summary `HMACAlgorithm.prepare_key` blocks asymmetric keys from being used as HMAC secrets by searching for text markers only. It looks for `-----BEGIN` and for an `ssh-` prefix. The same key in DER form is binary ASN.1 and has neither marker, so it passes the check and is used as an HMAC secret. An application that verifies tokens with an RSA or EC public key, and also allows HS256 with that same key, can be given a forged token. The attacker signs it with the public key, which is public. This is the key confusion problem CVE-2022-29217 was filed for, reachable again through a different encoding. The reach is smaller than the original CVE. The application must already be in that misconfiguration, and it must hold its public key as DER bytes rather than PEM. ### Details The guard is at `jwt/algorithms.py:331`: ```python if is_pem_format(key_bytes) or is_ssh_key(key_bytes): raise InvalidKeyError( "The specified key is an asymmetric key or x509 certificate and" " should not be used as an HMAC secret." ) ``` Both helpers are text matchers. Neither one parses the key. - `jwt/utils.py:126`, `is_pem_format`, runs a regex for `----[- ]BEGIN ...----`. - `jwt/utils.py:141`, `is_ssh_key`, checks `startswith` against a list of `ssh-` and `ecdsa-sha2-` prefixes. A DER encoded public key starts with the bytes `0x30 0x82`. It matches neither, so `prepare_key` returns it unchanged and it becomes the HMAC secret. There is no DER handling anywhere in the package. `grep -rni "\bDER\b|load_
PYSEC-2026-4149
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-4149
pyjwt
Source reference: /affected/0/package/name
- Affected versions
- 2.10.0
Source reference:
/affected/0/versions2.10.1Source reference:
/affected/0/versions2.11.0Source reference:
/affected/0/versions2.12.0Source reference:
/affected/0/versions2.12.1Source reference:
/affected/0/versions2.13.0Source reference:
/affected/0/versions2.4.0Source reference:
/affected/0/versions2.5.0Source reference:
/affected/0/versions2.6.0Source reference:
/affected/0/versions2.7.0Source reference:
/affected/0/versions2.8.0Source reference:
/affected/0/versions2.9.0Source 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.4.0"
},
{
"fixed": "2.14.0"
}
]
}
],
"package": {
"name": "pyjwt",
"purl": "pkg:pypi/pyjwt",
"ecosystem": "PyPI"
},
"versions": [
"2.10.0",
"2.10.1",
"2.11.0",
"2.12.0",
"2.12.1",
"2.13.0",
"2.4.0",
"2.5.0",
"2.6.0",
"2.7.0",
"2.8.0",
"2.9.0"
],
"database_specific": {
"source": "https://github.com/pypa/advisory-database/blob/main/vulns/pyjwt/PYSEC-2026-4149.yaml"
}
}
]- Related CVEs
- CVE-2026-102271
Source reference:
/aliases
Publisher severity
No explicit severity was provided.
- Event
- #62545 · Revision 2
- Added to Heist Feed
- Publisher date