acoustic-carpenter-78188
06/16/2026, 3:35 AM2.13.0
PyJWT 2.13.0 — Security Release
This release bundles five security fixes plus three additional hardening / spec-compliance changes. We recommend all users upgrade.
Security
•— JWK JSON accepted as HMAC secret (algorithm confusion).GHSA-xgmm-8j9v-c9wxpreviously rejected PEM- and SSH-formatted asymmetric keys but did not catch a JWK passed as a raw JSON string. In a verifier configured with both symmetric and asymmetric algorithms inHMACAlgorithm.prepare_keyand a raw-JSON JWK as the key, an attacker could forge HS256 tokens using the JWK text as the HMAC secret. The guard has been extended to reject any JWK-shaped JSON. Reported byalgorithms=[…].@aradona91
•— Algorithm allow-list bypass withGHSA-jq35-7prp-9v3f/PyJWK. When verifying with aPyJWKClient, the caller'sPyJWKallow-list was checked against the token headeralgorithms=[…]as a string only; actual verification used the algorithm bound to thealg. An attacker who controlled a registered JWKS key could sign with one algorithm and advertise another on the header. PyJWT now requires the token headerPyJWKto match the `PyJWK`'s algorithm before verification. Reported byalg.@sushi-gif
•— DoS via base64 decode of unused payload segment whenGHSA-w7vc-732c-9m39. For detached-payload JWS (b64=false), the compact-form payload segment was base64-decoded before being discarded in favor of the caller-suppliedb64=false. An attacker could inflate the unused segment to force CPU + memory cost without holding a valid signature. The segment is now required to be empty per RFC 7515 Appendix F, and is no longer decoded. Reported bydetached_payload.@thesmartshadow
•—GHSA-993g-76c3-p5m4accepts non-HTTP(S) URIs.PyJWKClientpassed its URI toPyJWKClient.fetch_data, which by default also handlesurllib.request.urlopen,file://, andftp://schemes. An application that fed an attacker-influenced URI intodata:could be coerced into reading local files or reaching other unintended schemes.PyJWKClientnow rejects any URI whose scheme isn'tPyJWKClientorhttp. Reported byhttps.@KEIJOT
•—GHSA-fhv5-28vv-h8m8cache wiped on fetch error. APyJWKClient-blockfinallycleared the JWK Set cache whenever a fetch raised, turning a transient JWKS-endpoint outage into application-wide auth failure. The cache write was moved into the success path; transient errors no longer evict valid cached keys. Reported byput(jwk_set=None).@eddieran
Fixed
• Reject empty HMAC keys outright inwithHMACAlgorithm.prepare_keyinstead of accepting them with only a warning. Defends against theInvalidKeyErrorfootgun. Thanks toos.getenv("JWT_SECRET", "")and@SnailSploitfor the reports.@spartan8806
• Forward per-call(includingoptions) fromenforce_minimum_key_lengththrough toPyJWT.decode. The option was previously silently dropped between the two layers, so it only took effect when set on thePyJWS._verify_signatureinstance. Thanks toPyJWTfor the report.@WLUB
• RFC 7797 §3 compliance for `b64=false`: the encoder now auto-addsto"b64", and the decoder rejects tokens that setcritwithout listing it inb64=false. Thanks tocritfor the report.@MachineLearning-Nerd
Changed
• Migrate the,dev, anddocspackage extras to dependency groups, bytestsin #1152.@kurtmckee
Upgrade notes
Most fixes are invisible to correctly-configured callers. A few behavioral changes you may encounter:
• Empty HMAC keys now raise. If your app passedor""as a secret (often via a missing env var, e.g.b""), `encode`/`decode` will now raiseos.getenv("JWT_SECRET", ""). This is the intended behavior — fix the configuration.InvalidKeyError
•decoding now requires the token'sPyJWKto match the JWK's algorithm. Previously a mismatch was silently honored if the headeralgappeared in the allow-list. Tokens that relied on this mismatch will now fail withalg.InvalidAlgorithmError
•now rejects non-HTTP(S) URIs at construction time. Tests or dev environments that fetched JWKS fromPyJWKClientURIs need to switch to a local HTTP server or load the JWKS by other means (e.g. constructfile://directly).PyJWKSet.from_dict(...)
•tokens are now strictly RFC 7515 / 7797 compliant. Tokens with a non-empty compact-form payload segment, or that omitb64=falsefrom"b64", will be rejected. PyJWT-produced tokens always satisfy both invariants, so round-trips through PyJWT are unaffected.crit
•set per-call now takes effect. Callers who passedenforce_minimum_key_lengthtooptions={"enforce_minimum_key_length": True}previously got no enforcement; they will now getjwt.decode()on undersized keys, as documented.InvalidKeyError
Full changelog: jpadilla/pyjwt@2.12.1...2.13.0Changelog Sourced from pyjwt's changelog.
`v2.13.0 https://github.com/jpadilla/pyjwt/compare/2.12.1...2.13.0`__
Security
````
- Reject JWK JSON documents passed as raw HMAC secrets in
``HMACAlgorithm.prepare_key`` to close an algorithm-confusion gap that
the existing PEM/SSH guard did not cover. Reported by @aradona91 in
`GHSA-xgmm-8j9v-c9wx https://github.com/jpadilla/pyjwt/security/advisories/GHSA-xgmm-8j9v-c9wx`__.
- Bind the JWT header ``alg`` to ``PyJWK.algorithm_name`` during
verification so the caller's ``algorithms=[...]`` allow-list cannot be
bypassed when decoding with a ``PyJWK`` / ``PyJWKClient`` key. Reported
by @sushi-gif in `GHSA-jq35-7prp-9v3f https://github.com/jpadilla/pyjwt/security/advisories/GHSA-jq35-7prp-9v3f`__.
- Reject non-``http(s)`` URI schemes in ``PyJWKClient`` so attacker-
influenced URIs cannot read local files or reach unintended schemes via
urllib's default ``file://`` / ``ftp://`` / ``data:`` handlers. Reported
by @KEIJOT in `GHSA-993g-76c3-p5m4 https://github.com/jpadilla/pyjwt/security/advisories/GHSA-993g-76c3-p5m4`__.
- Preserve the cached JWK Set on fetch errors in ``PyJWKClient.fetch_data``.
The previous ``finally``-block ``put(None)`` pattern cleared the cache
on any transient outage, turning one bad JWKS request into application-
wide auth failure. Reported by @eddieran in `GHSA-fhv5-28vv-h8m8 https://github.com/jpadilla/pyjwt/security/advisories/GHSA-fhv5-28vv-h8m8`__.
- Skip the unconditional base64 decode of the compact-form payload segment
when ``b64=false`` is set in the protected header, and require that
segment to be empty (RFC 7515 Appendix F detached form). Closes an
unauthenticated DoS amplifier. Reported by @thesmartshadow in
`GHSA-w7vc-732c-9m39 <https://git…flyteorg/flyte-migrate