Advisory

GHSA-7vr2-2fgp-9w7p

Details, part 2 of 2. The advisory

Details

Steps to reproduce

  1. pip install authlib==1.8.0 cryptography flask requests
  2. 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).
  3. Confirm authlib.jose.rfc7518.oct_key.POSSIBLE_UNSAFE_KEYS does not match those bytes with startswith, while cryptography.hazmat.primitives.serialization.load_pem_public_key loads them.
  4. from authlib.jose import jwt then tok = jwt.encode({"alg":"HS256"}, {"sub":"attacker","role":"admin"}, mutated_pem)
  5. 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.jose emits AuthlibDeprecationWarning ("please use joserfc instead. It will be compatible before version 2.0.0"). It is deprecated but still shipped, still documented in docs/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 kty in the data model, so jwt.decode with an RSAKey/ECKey and alg=HS256 raises InvalidKeyTypeError for 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:

  1. Decide key family by type, not by bytes. Attempt load_pem_public_key / load_pem_x509_certificate / load_ssh_public_key / load_der_public_key on the candidate and reject it as an oct key 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.
  2. 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 DER SubjectPublicKeyInfo cases. This is strictly weaker than (1): the recogniser can drift again the next time cryptography becomes 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.

Sources & licences