CVE-2026-48525: PyJWT: Unauthenticated DoS via unbounded Base64URL decoding of unused payload segment in b64=false detached JWS
Medium CVSS 5.3
- OSV id
- GHSA-w7vc-732c-9m39
- Also known as
- CVE-2026-48525, PYSEC-2026-178
- Published
- Last modified
Affected packages
| Package | Affected versions | Fixed in |
|---|---|---|
| pyjwt PyPI |
>= 2.8.0, < 2.13.0 | 2.13.0 |
Versions we track that it affects: pyjwt 2.8.0
How to fix it
Upgrade pyjwt to 2.13.0 or later.
# in requirements.txt: change the line to pyjwt==2.13.0
pip install -r requirements.txt
- If it is an indirect dependency, upgrade the package that depends on it, or add a minimum version constraint for it (e.g. in constraints.txt, or as a dependency in pyproject.toml).
- Check the changelog for breaking changes (especially across major versions), update the lockfile with the package manager, and run your tests.
Not sure whether your project uses an affected version? Check your lockfile below for free.
Details
[!NOTE] Practical impact depends on whether request body-size limits are enforced upstream (proxy/web-server/framework). Deployments with typical body-size caps (≤2 MB) bound the amplifier significantly; deployments accepting larger token inputs are more exposed.
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-provided detached_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):
- Calls
_load(jwt)first, which decodes the token segments - Only after that, checks
header.get("b64")and ifFalse, it replacespayload = detached_payloadand rebuilds the signing input
This behavior is visible in decode_complete():
_load(jwt)happens before theb64=falsehandling- then
payload = 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=false detached JWS, the payload segment in compact form is effectively not needed for verification in PyJWT’s own logic (since the library uses detached_payload as the real payload). Yet PyJWT still decodes it first, meaning:
- cost is paid even when signature is invalid
- the decoded bytes are discarded
- attacker controls the size of this cost via token length
Impact (evidence-driven)
Security impact
- Unauthenticated remote DoS: decoding work happens before signature rejection → attacker does not need signing key.
- CPU amplification: Base64URL decode time scales linearly with payload segment size.
- Memory amplification: decoded output allocates large byte buffers (tens of MB per request).
- Operational impact: request queueing / worker starvation under modest concurrency bursts.
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 crit validation, but the issue here is decode order / unbounded decode of an unused segment.)
Affected Versions
- Confirmed affected: PyJWT 2.12.1 (tested from your local editable install and repo).
- Likely affected: all versions that include detached payload support for JWS decoding, which was introduced in 2.4.0 (“Add detached payload support for JWS encoding and decoding”). ([pyjwt.readthedocs.io][3])
(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:
- token is provided in JSON body / query / header
- actual payload is the HTTP request body passed as
detached_payload
Attacker
- remote unauthenticated client
- can send requests to verify endpoint
- does not need a valid signature (invalid signature still triggers the expensive decode path)
Attack chain
- Attacker crafts a JWS compact token with header containing
"b64": falseandcrit:["b64"]. - Attacker inflates the payload segment (middle segment) to millions of Base64URL characters.
- Server calls
PyJWS.decode(...detached_payload=...). - PyJWT decodes the inflated segment (CPU + memory).
- Signature is rejected afterward (401) — but resources already consumed.
- Repeated requests or bursts cause queueing/worker starvation → DoS.
Proof of Concept - file names + results
PoC placement
PoC # 1 - Localhost verification server
File: server_localhost.py
Purpose: real HTTP endpoint (POST /verify) that calls PyJ
References
Am I affected?
Upload or paste your lockfile. We check every package version in it against OSV.dev, this advisory included, and email you the vulnerable ones with the version that fixes them. Free, and no account needed.
About this data
Source: GitHub Advisory Database via OSV.dev (CC-BY 4.0). Severity comes from the advisory's own rating when it has one, else from its CVSS score.