{"vuln_id":"GHSA-phmp-hrw4-r36r","aliases":["CVE-2026-97698"],"description":"Mistune: Quadratic-time DoS in parse_link_href via unbounded parenthesis scan on empty-label links","published_at":"2026-11-19T22:44:42Z","modified_at":"2026-11-19T23:00:36.648802Z","first_seen_at":"2026-11-21T19:15:19.422435Z","severity":"high","severity_source":"ghsa","cvss_score":7.5,"cvss_vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","cwe":["CWE-400","CWE-407"],"vendor":null,"product":null,"kev":{"is_kev":false,"date_added":null,"due_date":null,"ransomware":false},"epss":null,"epss_percentile":null,"nvd_status":null,"enriched_at":null,"links":{"nvd":"https://github.com/advisories/GHSA-phmp-hrw4-r36r"},"matched_alias":null,"items":[{"id":10715,"source":{"id":"osv","name":"OSV.dev"},"title":"GHSA-phmp-hrw4-r36r: Mistune: Quadratic-time DoS in parse_link_href via unbounded parenthesis scan on empty-label links","summary":"Mistune: Quadratic-time DoS in parse_link_href via unbounded parenthesis scan on empty-label links\n\n## Resolution\n\n**Fixed in Mistune 3.3.4.** Upgrade to 3.3.4 or later.\n\n- Affected versions: `< 3.3.4`\n- First patched version: `3.3.4`\n- Fix: https://github.com/lepture/mistune/compare/v3.3.3...v3.3.4\n\nThe reported payload was reproduced against the 3.3.3 release tag and verified to scale approximately linearly against the 3.3.4 release tag.\n\n## Original report\n\nThe following report describes the issue before the fix.\n\n## Summary\n`parse_link_href` in mistune performs an unbounded parenthesis-balancing scan that runs to end-of-document on each unmatched `(`. Because the empty label `[]` bypasses the `no_close_bracket_before` high-water-mark guard, a single small document of the form `\"[](\" * N` causes O(N) openers to each drive an O(N) scan, producing O(N²) CPU on the **default** `mistune.html()` renderer with no plugins.\n\n## Root Cause\n`parse_link` matches the empty label `[]` (`parse_link_label(\"[](\",1)` returns `('', 2)`), so it reaches the `(` branch and calls `parse_link_href`. That function's scan loop (helpers.py:143-159) advances past characters and increments `level` on each `(`, never finding an unescaped `)` at `level==0`, so it runs to EOF and returns `None`. The cursor then advances only ~2 chars to the next `[](`. The `no_close_bracket_before` high-water mark that keeps the balanced-bracket link path linear is never entered because the empty label matches before that branch; `_mark_no_link_before` only advances past the 2-char label, not the href region.\n\n## Impact\nA single unauthenticated request rendering untrusted markdown pins a worker at 100% CPU for tens of seconds. Measured on default `mistune.html`, no plugins: 6KB->0.80s, 12KB->3.15s, 24KB->12.5s, 48KB->49.8s (2x input -> ~3.9x time, clean O(n²)). This is the most severe of the mistune quadratic-DoS findings.\n\n## Proof of Concept\n```python\nimport mistune\nmd = mistune.create_markdown() # default HTML renderer, no plugins\nmd(\"[](\" * 16000) # ~48KB input stalls a worker ~50s\n```\n\n## Attack Chain\n1. Entry: rendered markdown body -> `\"[](\" * N` (3 bytes/unit, no plugins). Guard: none on input size (grep of markdown.py/core.py = no size/time cap). Bypass proof: no global guard exists.\n2. Check: `parse_link` guards at inline_parser.py:141 (`no_link_before`), :150 (`no_close_bracket_before`). Guard: high-water marks that linearize balanced-bracket links. Bypass proof: empty label matches (label != None) so the :150 branch is skipped entirely; `no_link_before` only crawls +2/opener because `parse_link_label` returns `('',2)`.\n3. Processing: `parse_link_href` (helpers.py:143) scans to EOF per `(` (unbalanced parens), returns `None`.\n4. Sink: O(N) openers x O(N) scan each -> O(N²) CPU.\n5. Impact: single ~48KB request stalls a worker ~50s (single-threaded); ~200KB approx minutes.\n\n## Bypass Evidence\n- `parse_link_label(\"[](\",1)` returns `('', 2)` — the empty label matches, so the balanced-bracket branch owning `no_close_bracket_before` is never entered.\n- `git log -S \"i\n\nAffected: PyPI:mistune\n\nFixed in: 3.3.4\n\nReferences:\nhttps://github.com/lepture/mistune/security/advisories/GHSA-phmp-hrw4-r36r\nhttps://nvd.nist.gov/vuln/detail/CVE-2026-97698\nhttps://github.com/lepture/mistune/commit/b4dd3284e52ec741ed9a227db29ade9017828e90\nhttps://github.com/lepture/mistune\nhttps://github.com/lepture/mistune/releases/tag/v3.3.4","url":"https://osv.dev/vulnerability/GHSA-phmp-hrw4-r36r","published_at":"2026-11-19T22:44:42Z","updated_at":"2026-11-19T23:00:36.648802Z","fetched_at":"2026-11-21T19:15:55.946125Z","severity":"high","cvss_score":7.5,"epss":0.00548,"is_kev":false,"has_exploit":false,"kev_due_date":null,"vendor":null,"product":"mistune","vuln_id":"CVE-2026-97698","vuln_ids":["CVE-2026-97698","GHSA-PHMP-HRW4-R36R"],"tags":["osv","pypi","fix-available"],"cluster_id":2188,"links":{"self":"https://vulnwatch.ve1ve2.com/api/v1/items/10715","html":"https://vulnwatch.ve1ve2.com/item/10715"}},{"id":2377,"source":{"id":"ghsa","name":"GitHub Security Advisories"},"title":"GHSA-phmp-hrw4-r36r / CVE-2026-97698: Mistune: Quadratic-time DoS in parse_link_href via unbounded parenthesis scan on empty-label links","summary":"Mistune: Quadratic-time DoS in parse_link_href via unbounded parenthesis scan on empty-label links\n\n## Resolution\n\n**Fixed in Mistune 3.3.4.** Upgrade to 3.3.4 or later.\n\n- Affected versions: `< 3.3.4`\n- First patched version: `3.3.4`\n- Fix: https://github.com/lepture/mistune/compare/v3.3.3...v3.3.4\n\nThe reported payload was reproduced against the 3.3.3 release tag and verified to scale approximately linearly against the 3.3.4 release tag.\n\n## Original report\n\nThe following report describes the issue before the fix.\n\n## Summary\n`parse_link_href` in mistune performs an unbounded parenthesis-balancing scan that runs to end-of-document on each unmatched `(`. Because the empty label `[]` bypasses the `no_close_bracket_before` high-water-mark guard, a single small document of the form `\"[](\" * N` causes O(N) openers to each drive an O(N) scan, producing O(N²) CPU on the **default** `mistune.html()` renderer with no plugins.\n\n## Root Cause\n`parse_link` matches the empty label `[]` (`parse_link_label(\"[](\",1)` returns `('', 2)`), so it reaches the `(` branch and calls `parse_link_href`. That function's scan loop (helpers.py:143-159) advances past characters and increments `level` on each `(`, never finding an unescaped `)` at `level==0`, so it runs to EOF and returns `None`. The cursor then advances only ~2 chars to the next `[](`. The `no_close_bracket_before` high-water mark that keeps the balanced-bracket link path linear is never entered because the empty label matches before that branch; `_mark_no_link_before` only advances past the 2-char label, not the href region.\n\n## Impact\nA single unauthenticated request rendering untrusted markdown pins a worker at 100% CPU for tens of seconds. Measured on default `mistune.html`, no plugins: 6KB->0.80s, 12KB->3.15s, 24KB->12.5s, 48KB->49.8s (2x input -> ~3.9x time, clean O(n²)). This is the most severe of the mistune quadratic-DoS findings.\n\n## Proof of Concept\n```python\nimport mistune\nmd = mistune.create_markdown() # default HTML renderer, no plugins\nmd(\"[](\" * 16000) # ~48KB input stalls a worker ~50s\n```\n\n## Attack Chain\n1. Entry: rendered markdown body -> `\"[](\" * N` (3 bytes/unit, no plugins). Guard: none on input size (grep of markdown.py/core.py = no size/time cap). Bypass proof: no global guard exists.\n2. Check: `parse_link` guards at inline_parser.py:141 (`no_link_before`), :150 (`no_close_bracket_before`). Guard: high-water marks that linearize balanced-bracket links. Bypass proof: empty label matches (label != None) so the :150 branch is skipped entirely; `no_link_before` only crawls +2/opener because `parse_link_label` returns `('',2)`.\n3. Processing: `parse_link_href` (helpers.py:143) scans to EOF per `(` (unbalanced parens), returns `None`.\n4. Sink: O(N) openers x O(N) scan each -> O(N²) CPU.\n5. Impact: single ~48KB request stalls a worker ~50s (single-threaded); ~200KB approx minutes.\n\n## Bypass Evidence\n- `parse_link_label(\"[](\",1)` returns `('', 2)` — the empty label matches, so the balanced-bracket branch owning `no_close_bracket_before` is never entered.\n- `git log -S \"i\n\nAffected packages: pip:mistune\nPatched: mistune 3.3.4","url":"https://github.com/advisories/GHSA-phmp-hrw4-r36r","published_at":"2026-11-19T22:44:42Z","updated_at":"2026-11-19T22:44:43Z","fetched_at":"2026-11-21T19:15:18.416790Z","severity":"high","cvss_score":7.5,"epss":0.00548,"is_kev":false,"has_exploit":false,"kev_due_date":null,"vendor":null,"product":"mistune","vuln_id":"CVE-2026-97698","vuln_ids":["CVE-2026-97698","GHSA-PHMP-HRW4-R36R"],"tags":["ghsa","pip","CWE-400","CWE-407"],"cluster_id":2188,"links":{"self":"https://vulnwatch.ve1ve2.com/api/v1/items/2377","html":"https://vulnwatch.ve1ve2.com/item/2377"}},{"id":6701,"source":{"id":"nvd","name":"NVD CVE API 2.0"},"title":"CVE-2026-97698: Mistune is a Python Markdown parser with renderers and plugins. Prior to 3.3.4, parse_link_href performs an unbounded parenthesis-balancing scan to the end of…","summary":"Mistune is a Python Markdown parser with renderers and plugins. Prior to 3.3.4, parse_link_href performs an unbounded parenthesis-balancing scan to the end of the document for each unmatched opening parenthesis reached through an empty [] link label. In src/mistune/helpers.py and src/mistune/inline_parser.py, the empty label bypasses no_close_bracket_before, and no_link_before advances only past the short label, so successive [] ( candidates repeatedly scan the remaining document. Rendering untrusted Markdown with the default HTML renderer and no plugins can perform quadratic CPU work and keep a worker at 100 percent utilization. This issue is fixed in version 3.3.4.\n\nReferences:\nhttps://github.com/lepture/mistune/commit/b4dd3284e52ec741ed9a227db29ade9017828e90\nhttps://github.com/lepture/mistune/releases/tag/v3.3.4\nhttps://github.com/lepture/mistune/security/advisories/GHSA-phmp-hrw4-r36r\nhttps://github.com/lepture/mistune/security/advisories/GHSA-phmp-hrw4-r36r","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-97698","published_at":"2026-11-17T20:18:00.033000Z","updated_at":"2026-11-17T20:18:00.177000Z","fetched_at":"2026-11-21T19:15:31.482498Z","severity":"high","cvss_score":7.5,"epss":0.00548,"is_kev":false,"has_exploit":false,"kev_due_date":null,"vendor":null,"product":null,"vuln_id":"CVE-2026-97698","vuln_ids":["CVE-2026-97698","GHSA-PHMP-HRW4-R36R"],"tags":["CWE-400","CWE-407"],"cluster_id":2189,"links":{"self":"https://vulnwatch.ve1ve2.com/api/v1/items/6701","html":"https://vulnwatch.ve1ve2.com/item/6701"}}]}