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.
Vulnerable file: src/joserfc/_rfc7518/jwe_algs.py
Vulnerable function: PBES2HSAlgKeyEncryption.decrypt_cek()
Lines: 283
def decrypt_cek(self, recipient: Recipient[OctKey]) -> bytes:
headers = recipient.headers()
# ...
p2c = headers["p2c"] # ← attacker-controlled integer
# ...
kek = self.compute_derived_key(key.get_op_key("deriveKey"), p2s, p2c)
The p2c value is then passed to compute_derived_key :
def compute_derived_key(self, key: bytes, p2s: bytes, p2c: int) -> bytes:
# ...
kdf = PBKDF2HMAC(
algorithm=self.hash_alg,
length=self.key_size // 8,
salt=salt,
iterations=p2c, # ← unbounded iterations
backend=default_backend(),
)
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...
0.1.00.10.00.11.00.11.10.12.00.2.00.3.00.4.00.5.00.6.0+26 more1.6.3Exploitability
AV:NAC:LPR:NUI:NScope
S:UImpact
C:NI:NA:HCVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H