{"id":"CVE-2026-97698","aliases":["GHSA-phmp-hrw4-r36r"],"title":"Mistune: Quadratic-time DoS in parse_link_href via unbounded parenthesis scan on empty-label links","titleSource":"GitHub_M","descriptionSource":"OSV","declaredSeverity":"HIGH","description":"## 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 \"if c == \\\"(\\\":\" -- helpers.py` returns only refactor `5de41fb`; `parse_link_href` has NEVER received a DoS fix (all helpers.py DoS fixes targeted `parse_link_text`).\n- Empirical: the `[`*n unbalanced-bracket payload is LINEAR on HEAD (0.03->0.12s) while `[](`*n is O(n²) (3.99x per 2x) — proving the fix does not cover this branch.\n\n## Affected Versions\n`<= 3.3.3` (present on latest release tag v3.3.3 and HEAD `719107f`; no fix on HEAD).\n\n## Suggested Fix\nAdd a high-water mark for `parse_link_href` failed scans (mirroring `no_link_before`/`no_close_bracket_before`), or bound the parenthesis scan to a maximum length, so repeated failed href scans cannot each traverse the remaining document.\n\n---\nReported by **zx (Jace)** — GitHub: @manus-use","severity":"high","score":7.5,"published":"2026-11-17T19:20:09.915Z","modified":"2026-11-19T23:00:36.648Z","withdrawn":false,"knownExploited":false,"affected":[{"ecosystem":"PyPI","name":"mistune","sources":[{"name":"OSV · GHSA-phmp-hrw4-r36r","url":"https://osv.dev/vulnerability/GHSA-phmp-hrw4-r36r"}],"ranges":[{"events":[{"introduced":"0"},{"fixed":"3.3.4"}],"type":"ECOSYSTEM"}],"versions":["0.1.0","0.2.0","0.3.0","0.3.1","0.4","0.4.1","0.5","0.5.1","0.6","0.7","0.7.1","0.7.2","0.7.3","0.7.4","0.8","0.8.1","0.8.2","0.8.3","0.8.4","2.0.0","2.0.0a1","2.0.0a2","2.0.0a3","2.0.0a4","2.0.0a5","2.0.0a6","2.0.0rc1","2.0.1","2.0.2","2.0.3","2.0.4","2.0.5","2.1.0","3.0.0","3.0.0a1","3.0.0a2","3.0.0a3","3.0.0rc1","3.0.0rc2","3.0.0rc3","3.0.0rc4","3.0.0rc5","3.0.1","3.0.2","3.1.0","3.1.1","3.1.2","3.1.3","3.1.4","3.2.0","3.2.1","3.3.0","3.3.1","3.3.2","3.3.3"],"fixed":["3.3.4"]}],"sourceAffected":[],"references":["https://github.com/lepture/mistune/security/advisories/GHSA-phmp-hrw4-r36r","https://github.com/lepture/mistune/commit/b4dd3284e52ec741ed9a227db29ade9017828e90","https://github.com/lepture/mistune/releases/tag/v3.3.4","https://nvd.nist.gov/vuln/detail/CVE-2026-97698","https://github.com/lepture/mistune"],"sources":[{"name":"CVE","id":"CVE-2026-97698","modified":"2026-11-17T19:33:19.308Z","url":"https://www.cve.org/CVERecord?id=CVE-2026-97698"},{"name":"OSV","id":"GHSA-phmp-hrw4-r36r","modified":"2026-11-19T23:00:36.648802260Z","url":"https://osv.dev/vulnerability/GHSA-phmp-hrw4-r36r"}],"assessments":[{"source":"GitHub_M","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5},{"source":"OSV","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5}],"cve":{"records":[{"id":"CVE-2026-97698","source":"GitHub_M","state":"PUBLISHED","reasons":[],"replacements":[],"disputed":false,"unsupportedWhenAssigned":false,"reserved":"2026-09-24T21:43:37.209Z","published":"2026-11-17T19:20:09.915Z","modified":"2026-11-17T19:33:19.308Z"}],"publishers":[{"name":"GitHub_M","role":"CNA","organizationId":"a0819718-46f1-4df5-94e2-005712e83aaa","modified":"2026-11-17T19:20:09.915Z"},{"name":"CISA-ADP","role":"ADP","organizationId":"134c704f-9b21-4f2e-91b3-4a467353bcc0","modified":"2026-11-17T19:33:19.308Z"}],"references":[{"url":"https://github.com/lepture/mistune/security/advisories/GHSA-phmp-hrw4-r36r","tags":["x_refsource_CONFIRM"],"source":"GitHub_M"},{"url":"https://github.com/lepture/mistune/commit/b4dd3284e52ec741ed9a227db29ade9017828e90","tags":["x_refsource_MISC"],"source":"GitHub_M"},{"url":"https://github.com/lepture/mistune/releases/tag/v3.3.4","tags":["x_refsource_MISC"],"source":"GitHub_M"},{"url":"https://github.com/lepture/mistune/security/advisories/GHSA-phmp-hrw4-r36r","tags":["exploit"],"source":"CISA-ADP"}],"weaknesses":[{"id":"CWE-400","description":"CWE-400: Uncontrolled Resource Consumption","source":"GitHub_M"},{"id":"CWE-407","description":"CWE-407: Inefficient Algorithmic Complexity","source":"GitHub_M"}],"applicability":[],"prioritization":[{"source":"CISA-ADP","type":"SSVC","role":"CISA Coordinator","timestamp":"2026-11-17T19:32:55.649728Z","decisions":[{"name":"Exploitation","value":"poc"},{"name":"Automatable","value":"yes"},{"name":"Technical Impact","value":"partial"}]}]},"products":[{"vendor":"lepture","name":"mistune","platforms":[],"versions":[{"version":"< 3.3.4","status":"affected"}],"cpes":[],"source":"GitHub_M","url":"https://www.cve.org/CVERecord?id=CVE-2026-97698"}],"remediation":[],"observedAt":"2026-11-20T00:27:20.980Z","kev":{"status":"not-listed","checkedAt":"2026-11-22T12:45:32.449Z"},"coverage":[{"source":"NVD","status":"no-result","checkedAt":"2026-11-17T19:40:32.333Z","attemptedAt":"2026-11-17T19:40:32.333Z"},{"source":"GHSA","status":"no-result","checkedAt":"2026-11-17T19:40:31.689Z","attemptedAt":"2026-11-17T19:40:31.689Z"},{"source":"EUVD","status":"no-result","checkedAt":"2026-11-17T19:40:31.686Z","attemptedAt":"2026-11-17T19:40:31.686Z"},{"source":"EPSS","status":"no-result","checkedAt":"2026-11-17T19:40:31.690Z","attemptedAt":"2026-11-17T19:40:31.690Z"}],"evidence":[],"aiSummary":null}