Repository navigation
deps(api): update dependency pyjwt to v2.15.0 [security] - #8639
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
|
Important Review skippedBot user detected. To trigger a single review, invoke the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8639 +/- ##
=======================================
Coverage 98.84% 98.84%
=======================================
Files 1656 1656
Lines 68348 68348
=======================================
Hits 67558 67558
Misses 790 790 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
✅ oss · depot-ubuntu-latest-arm-16 — run #21065 (attempt 1)Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
🗂️ Previous results✅ oss · depot-ubuntu-latest-16 — run #21065 (attempt 1)Playwright Test Results (oss - depot-ubuntu-latest-16)Details
|
This PR contains the following updates:
2.14.0→2.15.0PyJWT: Algorithm allow-list bypass when decoding with
PyJWK/PyJWKClientkeysCVE-2026-48523 / GHSA-jq35-7prp-9v3f
More information
Details
PyJWT
2.9.0through2.12.1allows a verifier-side algorithm allow-list bypass whenjwt.decode()orjwt.decode_complete()are called with aPyJWKkey. The token headeralgis checked against the caller-suppliedalgorithmsallow-list, but signature verification is performed with the algorithm bound to thePyJWKobject instead of the header algorithm. An attacker who controls a registered JWK/JWKS private key can sign with a disallowed algorithm, advertise an allowed algorithm in the JWT header, and still be accepted. The issue affects the documentedPyJWKClient.get_signing_key_from_jwt(...)flow.Summary
PyJWT's
PyJWKverification path allows a verifier-side algorithm allow-list bypass.In affected versions, when a JWT is decoded with a
PyJWKobject, PyJWT verifies that the headeralgstring is present in the caller'salgorithms=[...]list, but it does not actually use the header algorithm to verify the signature. Instead, it verifies with the algorithm already bound to thePyJWKobject.This lets an attacker who controls a registered JWK/JWKS private key sign with a disallowed algorithm and have the token accepted as long as the JWT header advertises an allowed algorithm. This affects the documented
PyJWKClientusage flow and does not require any non-default flags or unsafe configuration.Details
In
jwt/api_jws.pyin2.12.1,_verify_signature()treatsPyJWKkeys differently from normal PEM/public-key inputs:This logic means:
algis checked only as a string against the caller-supplied allow-list.PyJWK, the actual verifier is not selected from the header algorithm.key.Algorithm, which is fixed when thePyJWKobject is created.PyJWKbinds its algorithm injwt/api_jwk.pyfrom the JWK'salgfield or from key-type defaults:So once a
PyJWKis constructed, the verifier uses thePyJWK's bound algorithm, not the JWT header algorithm.The issue is reachable through the documented JWKS flow. In
docs/usage.rst, the project documents:PyJWKClient.get_signing_key_from_jwt()returns aPyJWK, so this documented path is affected.This is not a "no-key forgery" issue. The attacker still needs control of an accepted JWK/JWKS private key. However, that is realistic in deployments such as:
In those cases, the attacker can bypass verifier-side algorithm policy. For example, if the server intends to only accept
PS256, an attacker controlling an accepted RSA JWK can sign withRS256, setalg=PS256in the JWT header, and still be accepted through thePyJWKpath.The same forged token is rejected through the normal PEM/public-key verification path, which shows the bug is specific to
PyJWKverification rather than expected JWT behavior.This behavior was introduced by commit
ab8176abe21e550dbc1c9a6bb7e78ad80853bfb1(Decode with PyJWK (#​886)), which is present in tagged releases2.9.0,2.10.0,2.10.1,2.11.0,2.12.0, and2.12.1.PoC
Tested locally against PyJWT
2.12.1on Python3.12.10withcryptography 45.0.6.Install dependencies:
Run the following script:
Observed output:
The token is accepted when the verification key is a
PyJWK, even though:["RS512"]RS256The same token is rejected when verified through the normal PEM/public-key path.
Impact
This is an algorithm allow-list bypass affecting
jwt.decode()andjwt.decode_complete()when the verification key is aPyJWK, including keys returned byPyJWKClient.The impact depends on the deployment model:
Impacted deployments include:
algorithms=[...]to enforce a crypto policy against externally controlled signing keysWhat an attacker can do:
PS256" or "onlyRS512"What this issue does not do by itself:
Severity
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:NReferences
This data is provided by the GitHub Advisory Database (CC-BY 4.0).
PyJWT: Public-key JWK accepted as HMAC secret enables forged HS256 tokens when mixed families are allowed
CVE-2026-48526 / GHSA-xgmm-8j9v-c9wx
More information
Details
Summary
When the verifier is decoding JSON Web Tokens, while supporting both asymmetric and HMAC algorithms, the library does not validate use of JSON Web Keys in HMAC algorithm, allowing attacker to use the issuer public key as the secret key for HMAC algorithm.
Details
In JWT algorithm confusion attack, the verifier is mistakenly use of public key to be used as the shared secret in symmetric algorithms.
In pyjwt case, when the verifier is supporting both HMAC with other asymmetric algorithm and mistakenly using the public key of the issuer to verify the token as demonstrated in the following example:
jws.decode(token, key=rsa_jwk_json, algorithms=["HS256","RS256"]))An attacker who specifies in the token header to use HMAC, will cause the verifier to accept the JWK as the secret key in HMAC algorithm.
The attacker will be able to forge JWT signed with the public key of the issuer to impersonate any user.
If we look on current protections implemented in the library, at class HMACAlgorithm:
We can observe that there is a protection against this type of attacks but only when the verifier is using PEM format or SSH key to verify the token. JSON Web Keys, on the other hand will pass the validation.
In The following example:
jws.decode(token, key=rsa_jwk_json, algorithms=["HS256","RS256"]))There is indeed a wrong implementation of the verifier, but a stronger protection in the library side will prevent and protect against those type of misconfiugrations.
The bypass happens only if the verifier:
(a) allows HS* and an asymmetric algorithm in the same call and (b) passes a public-key value as key.
PoC
Please run the code and observe the payload printed in clear text({"sub":"alice","admin":true}')
Impact
Unauthenticated token forgery → full identity/role impersonation at the resource server (authorization bypass).
Severity
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:NReferences
This data is provided by the GitHub Advisory Database (CC-BY 4.0).
PyJWT: Unauthenticated DoS via unbounded Base64URL decoding of unused payload segment in b64=false detached JWS
CVE-2026-48525 / GHSA-w7vc-732c-9m39
More information
Details
When verifying detached JWS tokens using the unencoded-payload option (
"b64": false, RFC 7797), PyJWT performs Base64URL decoding of the compact-serialization payload segment before enforcing the detached-payload rules.For
b64=false, PyJWT later discards that decoded payload and replaces it with the caller-provideddetached_payload. In practice, this turns the middle segment into an attacker-controlled “work amplifier”: a remote client can supply an arbitrarily large Base64URL payload segment that forces CPU work + memory allocations even if the signature is invalid.This creates an unauthenticated DoS vector against any endpoint that verifies detached JWS using PyJWT.
Affected Component(s)
jwt/api_jws.pyPyJWS.decode()/PyJWS.decode_complete()_load()(parsing and Base64URL decoding)Root Cause (exact logic flaw)
What happens in the code
In
jwt/api_jws.py,decode_complete()does the following (order matters):_load(jwt)first, which decodes the token segmentsheader.get("b64")and ifFalse, it replacespayload = detached_payloadand rebuilds the signing inputThis behavior is visible in
decode_complete():_load(jwt)happens before theb64=falsehandlingpayload = detached_payloadandsigning_input = ... detached_payloadhappens afterward ([GitHub][1])Inside
_load(), PyJWT unconditionally performs:payload = base64url_decode(payload_segment)This is the expensive step the attacker can amplify ([GitHub][1])
Why this becomes a vulnerability
For
b64=falsedetached JWS, the payload segment in compact form is effectively not needed for verification in PyJWT’s own logic (since the library usesdetached_payloadas the real payload). Yet PyJWT still decodes it first, meaning:Impact (evidence-driven)
Security impact
Standards context (RFC 7797)
RFC 7797 explicitly notes this option is used when payload is large and/or detached, and discusses interoperability requirements around marking it critical (“crit” with “b64”). ([IETF Datatracker][2])
(PyJWT supports
critvalidation, but the issue here is decode order / unbounded decode of an unused segment.)Affected Versions
(For GHSA, this phrasing is strong: “confirmed” + “likely since feature introduction”.)
Threat Model
Typical real deployment
A service verifies signed HTTP requests or webhooks using detached JWS:
detached_payloadAttacker
Attack chain
"b64": falseandcrit:["b64"].PyJWS.decode(...detached_payload=...).Proof of Concept - file names + results
PoC placement
server_localhost.py
client_localhost.py
flood_localhost.py
PoC # 1 - Localhost verification server
File: server_localhost.py
Purpose: real HTTP endpoint (
POST /verify) that calls PyJWT detached verification and prints:ok / time_ms / peak_bytes / token_len / error.Results (server console output)
Key takeaways from these results
At 8,000,000 chars, a single invalid-signature request still causes:
PoC # 2 - Localhost network client
File: client_localhost.py
Purpose: generates baseline + (invalid signature) + (valid signature) tokens and sends them over HTTP to localhost server.
Results (client output)
payload-chars = 500,000
payload-chars = 2,000,000
payload-chars = 8,000,000
Why this is strong evidence
PoC # 3 - Localhost flood / burst concurrency
File: flood_localhost.py
Purpose: sends N concurrent invalid-signature requests over HTTP to demonstrate queueing/worker starvation.
Results (your run: 20 concurrent @ 8,000,000 chars)
Interpretation
Fix
Goal
Prevent unbounded resource consumption from an attacker-controlled payload segment that is unused in
b64=falsedetached flow.Minimal change strategy
In
_load()(or by refactoring parse order), do not Base64-decodepayload_segmentuntil after you know whetherb64=falseapplies.Two safe options:
Reject non-empty payload segment when
b64=falseb64is false andpayload_segmentis non-empty → raiseDecodeErrorbefore decodingdetached_payloadonlySkip decoding payload segment entirely when
b64=falseThis aligns with the idea that detached payload is the trusted payload input for verification; the compact payload segment should not become a resource amplification vector.
(Implementation context: the current decode order and unconditional
base64url_decode(payload_segment)are visible in the file and line region around_load()anddecode_complete()([GitHub][1]).)Workarounds
b64=false) is not needed in your app, reject tokens where header includes"b64": false.Severity
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:LReferences
This data is provided by the GitHub Advisory Database (CC-BY 4.0).
PyJWKClient unbounded JWKS endpoint requests via attacker-controlled kid values (DoS)
CVE-2026-48524 / GHSA-fhv5-28vv-h8m8
More information
Details
Summary
PyJWKClient.get_signing_key() forces a fresh HTTP request to the JWKS endpoint for every JWT with an unknown kid value, with no rate limiting. Since kid comes from the unverified token header, an attacker can trigger unlimited outbound requests.
Additionally, fetch_data() finally block clears the JWKS cache on network error.
Root Cause
jwt/jwks_client.py:172-198 - get_signing_key(kid) calls get_signing_keys(refresh=True) for unknown kids, bypassing TTL cache with no cooldown.
jwt/jwks_client.py:120-122 - finally block writes None to cache on error, clearing valid data.
Impact
Suggested Fix
Affected Versions
All versions with PyJWKClient (2.4.0 through 2.12.1)
Severity
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:LReferences
This data is provided by the GitHub Advisory Database (CC-BY 4.0).
PyJWKClient: missing scheme allowlist enables CVE-2024-21643-class SSRF + token forgery via file://, ftp://, data: schemes
CVE-2026-48522 / GHSA-993g-76c3-p5m4
More information
Details
Summary
PyJWKClient passes its
uriargument directly tourllib.request.urlopen()which uses Python stdlib's defaultOpenerDirectorregisteringHTTPHandler,HTTPSHandler,FTPHandler,FileHandler, andDataHandler. There is currently no documented option to restrict which schemes PyJWKClient will fetch.If an application's
jkuURL ingestion path accepts attacker-influenced URLs (e.g., from JWT header, configuration file, OAuth flow parameter), the attacker can:file://(SSRF on local filesystem) — the file's contents are passed tojson.load.jwt.decode()accepts.Affected versions
Tested and reproducible on PyJWT 2.11.0 and 2.12.1. Likely all versions back to PyJWKClient introduction.
Reproducer (full attack chain — verified empirically)
Cross-library evidence — PyJWT is the outlier
The same composition pattern is structurally safe in 4 other mainstream JWT libraries:
jku=file://...fetch()rejects non-http(s) at fetch-spec layerhttp.DefaultTransportonly registers http/httpsHttpDocumentRetrieverdefaultsRequireHttps=truePyJWT is the only library of these 5 where the default behavior allows
file://to reach the fetch layer.Recommended fix
Add
allowed_schemes: tuple[str, ...] = ("https", "http")kwarg toPyJWKClient.__init__. Pre-validate URL scheme before invokingurllib.request.urlopen. URLs with disallowed schemes raisePyJWKClientErrorbefore any fetch is attempted.Diff sketch against
jwt/jwks_client.pyTests to add
Compatibility
allowed_schemes=("https", "http")preserves backwards compatibility for the overwhelming majority of callers using HTTP/HTTPS JWKS endpointsClass precedent
This is the same class as CVE-2024-21643 (Apache Jena JKU-trust: attacker-supplied JKU URL fetched without scheme validation). NVD-rated CVSS 7.5.
Prior art (verified 2026-05-06)
Confirmed via live recon (NVD direct, OSV.dev, PyJWT GitHub Security Advisories, issue/PR keyword search, CHANGELOG inspection):
Credit
Reported by Keijo Tuominen — independent security research at CMHT.tech (https://cmht.tech).
Reproduction artifacts available on request: full multi-language probe pack (5 wrappers × 25 fixtures × 125 cells) demonstrating cross-library divergence at the URL-scheme boundary.
Severity
CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:L/A:NReferences
This data is provided by the GitHub Advisory Database (CC-BY 4.0).
PyJWT: Malformed RSA JWK aborts parsing of an entire JWK Set
CVE-2026-102274 / GHSA-w6j9-cwv2-h6wq
More information
Details
Summary
A malformed RSA JWK inside a JWK Set aborts parsing of the entire set instead of being skipped, because
RSAAlgorithm.from_jwkcan raise a plainValueErrorthat isn't caught byPyJWKSet's per-key error-skipping logic.Affected component / version
PyJWT(PyPI, ecosystempip)jwt/api_jwk.py(PyJWK.__init__,PyJWKSet.__init__),jwt/algorithms.py(RSAAlgorithm.from_jwk)masterbranch as of 2026-09-05 (commit7144e4534c34810f4525dc4578a32addd8212cff, tag2.13.0). Directly verified identical in tags2.9.0,2.10.0,2.11.0,2.12.0,2.12.1,2.13.0-- the vulnerable call and theexcept PyJWTErrorguard are unchanged across all six releases. Not verified against any release prior to2.9.0.Details
PyJWKSet.__init__(jwt/api_jwk.py:145-152) iterates each key in a JWK Set:PyJWK.__init__(api_jwk.py:82) callsself.Algorithm.from_jwk(self._jwk_data)with no try/except of its own. For an RSA JWK, this dispatches toRSAAlgorithm.from_jwk(jwt/algorithms.py:539-586). When the JWK suppliesd,e,nwithout the CRT parameters (p,q,dp,dq,qi),from_jwkcallscryptography'srsa_recover_prime_factors(public_numbers.n, d, public_numbers.e)(algorithms.py:572-574) to derive the key. Ifdis not the correct private exponent for thatn/epair,rsa_recover_prime_factorsraises a plainValueError.ValueErroris a built-in Python exception and is not a subclass ofjwt.exceptions.PyJWTError(PyJWTError(Exception)is the root of PyJWT's own exception hierarchy). It is therefore not caught byPyJWKSet.__init__'sexcept PyJWTError, and propagates out of the constructor, aborting thefor key in keys:loop before any subsequent key in the list is processed.PyJWKSet.from_dict/from_jsonandPyJWK.from_dict/from_jsonare exported public API (jwt/__init__.py).PyJWKClient.get_jwk_set(jwt/jwks_client.py:158) feeds a fetched JWKS HTTP response directly intoPyJWKSet.from_dictwith no per-key pre-validation, so this is reachable through the documentedPyJWKClientflow whenever the fetched JWKS contains a malformed key alongside valid ones.Proof of concept
Impact
PyJWKSet.__init__raises before completing, so no key in the JWK Set is added to the resulting set, including keys unrelated to the malformed entry. This requires the malformed key to already be present in a JWK Set the application parses (e.g. one entry in an aggregated/federated key set, or a key affected by transit corruption before signature verification of the JWKS transport itself). Applications that vet each key individually before adding it to a trusted set are not affected. The failure is an uncaughtValueError, not one of PyJWT's documentedjwt.exceptions.*types, so exception handling written against PyJWT's documented contract (except jwt.exceptions.PyJWTError) will not catch it either.Suggested remediation
Wrap the key-construction call in
PyJWK.__init__(api_jwk.py:82) so aValueErroris converted intoInvalidKeyError(aPyJWTErrorsubclass):This lets
PyJWKSet.__init__'s existingexcept PyJWTError: continueskip the one malformed key as its own comment already states is intended.Responsible Disclosure Timeline
Per the OWASP Vulnerability Disclosure Cheat Sheet and Google Project Zero's 2020 disclosure policy:
created_attimestamp when this report is submitted. If submitted on the date of this draft (2026-09-05), Day 0 = 2026-09-05.Try It Yourself (Sandbox)
Reproduce the PoC above, and attempt your own fix, in an isolated sandbox with no access to production systems, secrets, or real data.
Credit
Discovered and reported by SecDim Security Research: secdim.com, @secdim, security@secdim.com.
Maintainer update — 2026-09-08
We reproduced the reported behavior on PyJWT 2.13.0 with
cryptographyinstalled: a malformed RSA private JWK containing an invaliddvalue and no CRT parameters raised a plainValueErrorwhile parsing a JWK set. BecausePyJWKSetskipsPyJWTErrorinstances only, that exception aborted parsing before subsequent valid keys were loaded. The impact is a conditional availability failure for applications that parse a key set containing a malformed entry; it is not a signature-forgery or claims-verification bypass.The independently verified affected range is
>= 2.9.0, <= 2.13.0; earlier releases were not checked. A narrow fix has been prepared in commit8915570based on master commit5fa7594:PyJWKconverts key-constructionValueErrorexceptions toInvalidKeyError, allowing the existingPyJWKSetskip path to continue. Regression coverage verifies that a malformed RSA key is skipped while a valid key in the same set remains usable. The full suite passes with 370 tests and 4 intentional cryptography-environment skips; formatting, lint, and targeted type checks pass. The advisory remains in triage while the fix goes through release planning.Severity
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:HReferences
This data is provided by the GitHub Advisory Database (CC-BY 4.0).
PyJWT: PyJWKClient still amplifies unauthenticated JWKS fetches on unknown kid values (incomplete fix of CVE-2026-48524)
CVE-2026-101917 / GHSA-2gx3-rcp4-g85q
More information
Details
Summary
CVE-2026-48524 (GHSA-fhv5-28vv-h8m8, "PyJWKClient unbounded JWKS endpoint requests via attacker-controlled kid values (DoS)") was fixed in 2.13.0 by stopping fetch_data() from clearing the cache on a fetch error. That closed one amplification path but did not add the mitigation the advisory's title implies: there is still no rate-limit, negative-cache, or minimum-refresh-interval for unknown kids.
At HEAD, get_signing_key(kid) (jwt/jwks_client.py:185-211), on any unknown kid, calls get_signing_keys(refresh=True), and refresh=True bypasses jwk_set_cache unconditionally and forces a fresh fetch_data(). The kid is read from the unverified token header (get_signing_key_from_jwt decodes with verify_signature=False), so no valid token and no authentication is required. lru_cache does not cache the raised exception, so even the same unknown kid repeated re-fetches on every call.
Affected
pyjwt <= 2.13.0 (the latest release; the patched release for CVE-2026-48524). No fixed version yet.
Proof of concept (verified on 2.13.0, cache enabled = realistic prod config)
import threading, http.server, socketserver, json
from jwt import PyJWKClient
hits = {'n': 0}
JWKS = json.dumps({"keys":[{"kty":"oct","kid":"real","k":"AAAA"}]}).encode()
class H(http.server.BaseHTTPRequestHandler):
def do_GET(self):
hits['n'] += 1
self.send_response(200); self.send_header('Content-Type','application/json'); self.end_headers()
self.wfile.write(JWKS)
def log_message(self,*a): pass
srv = socketserver.TCPServer(('127.0.0.1',0), H); port = srv.server_address[1]
threading.Thread(target=srv.serve_forever, daemon=True).start()
c = PyJWKClient(f'http://127.0.0.1/:{port}[/jwks](tg://bot_command?command=jwks).json', cache_keys=True, lifespan=3600)
for i in range(8):
try: c.get_signing_key(f'attacker-unknown-kid-{i}')
except Exception: pass
before = hits['n']
for _ in range(5):
try: c.get_signing_key('same-unknown')
except Exception: pass
print('distinct unknown kids: 8 -> fetches:', hits['n'])
print('same unknown kid x5 -> extra fetches:', hits['n'] - before)
Output:
distinct unknown kids: 8 -> fetches: 9
same unknown kid x5 -> extra fetches: 5
Each unknown kid forces a fresh JWKS fetch; a repeated identical unknown kid still re-fetches every time against an unexpired cache. No rate-limit or negative-cache.
Impact
One unauthenticated request -> one outbound JWKS HTTP fetch + full JSON parse on the victim server. An attacker floods tokens carrying junk kids, so the victim hammers its own JWKS/IdP endpoint (amplification: attacker -> victim -> IdP), exhausting victim CPU/sockets and potentially tripping the JWKS provider's rate-limit, causing an application-wide auth outage. This is the unauthenticated DoS the parent advisory is named for, still reachable after the 2.13.0 fix.
Suggested fix
Guard the forced refresh on unknown kids: negative-cache unknown kids for a short TTL, or enforce a minimum interval between forced JWKS refreshes, so a repeated or unknown kid cannot force unbounded fetches.
Note: the same-kid-repeated result (5 identical unknown kids producing 5 fetches against an unexpired cache) shows this is request amplification, not legitimate key-rotation handling, since that refresh can never succeed.
Reported by Babakizo (Securva).
Maintainer update — 2026-09-10
The maintainer confirmed the reported behavior against PyJWT 2.13.0. With JWKS caching
enabled, an unknown
kidpreviously forced an unconditional JWKS refresh,including when the same unknown value was repeated while the cached key set was
still valid. This allowed unauthenticated token headers to cause unnecessary
outbound JWKS requests and repeated parsing work.
The fix is now on
masterin commitba4853a.PyJWKClientnow applies a30-second cooldown after successful JWKS fetches before permitting another
unknown-
kidrefresh, serializes concurrent refresh decisions per client, andallows callers to configure or disable the cooldown. Cache-disabled behavior
and immediate retry after failed fetches remain unchanged.
Regression tests cover repeated unknown kids, cooldown expiry, concurrent
misses, cache-disabled operation, and invalid cooldown values. The available
full tox matrix, Ruff, and mypy checks pass. The fix will be included in the
next released 2.x version.
Maintainer update — 2026-09-11
The verified fix for this advisory is included in PyJWT 2.14.0, released on 2026-09-11 and available on PyPI. PyJWT 2.14.0 is the first release containing the fix. This advisory is now published with 2.14.0 recorded as the patched version.
Severity
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:LReferences
This data is provided by the GitHub Advisory Database (CC-BY 4.0).
PyJWT: Public keys in DER form are accepted as HMAC secrets, bypassing the CVE-2022-29217 guard
CVE-2026-102271 / GHSA-p4g4-x82p-q773
More information
Details
Summary
HMACAlgorithm.prepare_keyblocks asymmetric keys from being used as HMAC secrets by searching for text markers only. It looks for-----BEGINand for anssh-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: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, checksstartswithagainst a list ofssh-andecdsa-sha2-prefixes.A DER encoded public key starts with the bytes
0x30 0x82. It matches neither, soprepare_keyreturns it unchanged and it becomes the HMAC secret.There is no DER handling anywhere in the package.
grep -rni "\bDER\b|load_der" jwt/ tests/returns nothing.This affects three encodings that are all blocked in their PEM form today:
History of this guard:
Applications that use
PyJWKorPyJWKClientare not affected.jwt/api_jws.py:395binds the headeralgto the key's own algorithm, so HS256 never reachesHMACAlgorithm.prepare_keyon that path.Suggested fix: try to parse the bytes as a key and reject if parsing works. For example
load_der_public_key,load_der_private_keyandload_der_x509_certificatein a try/except chain, next to the checks already there. A random HMAC secret will not parse as valid DER, so real secrets should not be rejected.PoC
Tested on 2.4.0, on 2.13.0, and on main at commit
7144e4534. All three behave the same. The guard has been marker based since 2.4.0, so the versions in between are very likely affected as well.No special configuration is needed. The script builds its own key.
Output:
The token is signed with plain
hmac, so this exercises the verify path only. The PEM and the DER values come from the same key object, so the encoding is the only thing that changes.We also have a regression test written in your pytest style. It uses your own
tests/keysfixtures, covers the DER certificate case too, and fails on current main. Glad to send it or open a PR.Impact
Key confusion, CWE-347, improper verification of a cryptographic signature. Same class as CVE-2022-29217.
Who is affected: applications that verify tokens with an asymmetric public key, also list an HS* algorithm pass that public key to `jwt.decode