Python JWT Library Vulnerabilities
The 2024–2026 run of verification bypasses in PyJWT, Authlib, joserfc, python-jose and jwcrypto. Nearly all are one of three classes: a public key accepted as an HMAC secret, an empty HMAC key accepted, or Python type quirks in claim checks.
How it works
Python JOSE libraries try to defend against JWT Algorithm Confusion by guessing whether a key passed as an HMAC secret is really public-key material (PEM markers, JWK kty, SSH prefixes). Each guard is a denylist over encodings, and researchers keep finding encodings it misses. The exposure precondition is almost always in the caller’s code:
jwt.decode(tok, key, algorithms=["RS256", "HS256"]) # reachable by every confusion bug
jwt.decode(tok, public_key, algorithms=["RS256"], audience="api") # never reachableIf an allow-list mixes HMAC with RS/ES/PS/EdDSA and the verification key is raw material, an attacker who knows the public key (which is public by definition) signs HS256 with it.
Bug classes and cases
Public key as HMAC secret
| Library | ID | Encoding that slipped the guard | Fixed |
|---|---|---|---|
| PyJWT | CVE-2026-102268 (Critical) | Whitespace-prefixed, CR-only or single-line PEM | 2.14.0 |
| PyJWT | CVE-2026-102271 | DER-encoded public keys (since 2.4.0) | 2.14.0 |
| PyJWT | CVE-2026-102272 | UTF-8 BOM before JWK JSON | 2.14.0 |
| PyJWT | CVE-2026-102273 / GHSA-xgmm-8j9v-c9wx | Public JWK wrapped in a JWKS or array | 2.14.0 |
| Authlib | CVE-2026-114615 / GHSA-7vr2-2fgp-9w7p | Leading newline or space before PEM. The 1.3.1 fix for CVE-2024-37568 only checked the start of the input. Affects 1.3.1–1.8.0 | 1.9.0 |
| Authlib | — | OpenSSH public keys and certs loaded as OctKey | 1.9.5 |
| joserfc | GHSA-vvgp-wfq3-pjxj | DER RSA public key imported as an oct key | 1.7.6 |
PyJWT already “fixed” this class as CVE-2022-29217. The 2026 advisories are four new encodings past that marker-based check.
Empty HMAC key
- PyJWT < 2.13.0, CVE-2026-102266:
PyJWK/PyJWKSetaccepted an emptyoctkey because that path skipped the empty-key check that raw bytes get. - Authlib CVE-2026-114616:
OctKey.import_keyandHMACAlgorithmaccept a zero-length key, which produces deterministic, forgeable HS* signatures. The same bug exists in fast-jwt and ruby-jwt. - python-jose ≤ 3.5.0, CVE-2026-120459:
HMACKey/CryptographyHMACKeyaccept zero-length secrets.
Claim validation and type quirks
- jwcrypto ≤ 1.6.1:
check_claims={"sub": None}usesNoneto mean “required, any value”. A payload containing JSONnullsatisfies the presence check and then returns early, which bypasses requirediss/sub/aud/jti. Python bool/int equivalence (int(True) == 1) and unhandled exceptions add further bypass and DoS paths. - joserfc < 1.7.6 (GHSA-mcm9-p458-pjmc): a list-valued
jtipassed an exact-value check as list membership. RFC 7519 requires a string. - Authlib RFC 7523 bearer grant (GHSA-fch4-3c6x-j4gc):
get_audiences()returning[]madeverify_claims()accept anyaud. - PyJWT non-canonical signatures (Ubuntu USN-9177-1, November 2026): PyJWT accepted non-canonical encodings of the signature segment, which the advisory says could let an attacker bypass token revocation checks; fixed in updated packages. The advisory gives no mechanism; the likely one is that a single valid token gains several string forms, defeating denylists keyed on the raw token (Ubuntu).
JWKS fetching and DoS
- PyJWT
PyJWKClient: follows redirects on JWKS fetch (CVE-2026-102267), refetches on every unknownkid(CVE-2026-101917), lets one bad RSA key abort the whole set (CVE-2026-102274), and has ReDoS inis_pem_format(CVE-2026-102270). There areRecursionErrors on nested headers (CVE-2026-102265, CVE-2026-101918) that escapeexcept jwt.PyJWTErrorand cause a 500 or a dead worker.decode()also mutated a reusedoptionsdict (CVE-2026-103001). Upgrade to PyJWT ≥ 2.15.0 for all 14. - Authlib JAR (RFC 9101):
request_uripassed unvalidated to the fetch hook, giving unauthenticated SSRF.
Testing / review
pip show pyjwt authlib joserfc python-jose jwcrypto | grep -E '^(Name|Version)'
grep -rnE "algorithms\s*=\s*\[[^]]*HS[0-9]+[^]]*(RS|ES|PS|EdDSA)" --include=*.py .
grep -rnE 'verify_signature|get_unverified_header|options=' --include=*.py .- Is the algorithm list built dynamically, or from the token header? Either one means confusion is reachable.
- Is
options={"verify_signature": False}used on a request path? That is decode without verification. - Is the HS secret ≥ 256 bits and not a password (RFC 7518 §3.2, RFC 8725 §3.5)? See JWT Secret Cracking.
- Send tokens with
nullclaims, list-valued claims and empty-key HS256 signatures.
Defenses
- Pin one algorithm per issuer from trusted config. Never mix HMAC and asymmetric in one
decode(). - Use typed key objects, not raw strings, and keep HMAC secrets and public keys in separate stores.
- Require
iss,audandexpexplicitly, and catch broad exceptions around decode. - Pin PyJWT explicitly in lockfiles because it often arrives transitively.
Related
- Python Security
- Python Web Framework Security
- Python SAST Tools
- JSON Web Tokens
- JWT Algorithm Confusion
- JWT None Algorithm
- JWT Header Injection
- JWT Secret Cracking
- OAuth 2.0 Vulnerabilities
- OpenID Connect Security
Sources
- PyJWT 2.14/2.15: algorithm confusion advisories explained · original
- PyJWT accepts public JWK containers as HMAC secrets · original
- PyJWT public-key JWK accepted as HMAC secret · original
- PyJWT: PyJWK accepts empty HMAC keys (CVE-2026-102266) · original
- PyJWT HMAC forgery with known public key (SUSE) · original
- SUSE-SU-2026:5064-1: PyJWT fixes · original
- SUSE security update for python-PyJWT · original
- CVE-2026-114615: Authlib JWT algorithm confusion fix bypass · original
- Authlib accepts empty HMAC key · original
- Authlib accepts OpenSSH keys/certs as HMAC secrets · original
- Authlib JWT bearer grant accepts wrong audience · original
- Authlib: unvalidated request_uri fetch in JAR (SSRF) · original
- joserfc OctKey accepts DER RSA public keys · original
- joserfc: list-valued jti accepted · original
- python-jose authentication bypass through 3.5.0 · original
- Breaking JWT Validation: JSON nulls, Python booleans · original
- USN-9177-1: PyJWT non-canonical signature vulnerability · original
- JWT verification bugs: pin the algorithm, then prove the fix · original