{"id":"CVE-2026-97699","aliases":["GHSA-ww7q-mxrj-5ffg"],"title":"Mistune: Quadratic-time DoS in inline image parsing (precedence_scan) bypasses not-is-image guards","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\nmistune's inline image parsing reaches `precedence_scan` for `![` openers because the two guards that keep the link path linear are both gated behind `not is_image`. A small default-renderer document of the form `\"![\" * N + \"x\" + \"]\" * N` produces O(N²) CPU with no plugins.\n\n## Root Cause\nFor `![` openers, `is_image` is True, so both linearizing guards are skipped: `if not is_image and pos <= state.no_link_before` (inline_parser.py:141) and `has_nested_link = not is_image and _label_contains_link(...)` (:171). Execution reaches `precedence_scan` (:179) which runs `sc.search(state.src, mark_pos, end_pos)` over the whole image body — O(n) per outer opener, x O(n) openers -> O(n²). `max_image_depth` never fires because the failing scans never produce an image token (`image_depth` stays 0).\n\n## Impact\nA single unauthenticated request pins a worker at 100% CPU. Measured on default `mistune.html`, no plugins: 6KB->0.28s, 12KB->1.07s, 24KB->4.20s, 48KB->15.8s (2x input -> ~3.8x time).\n\n## Proof of Concept\n```python\nimport mistune\nmd = mistune.create_markdown()   # default, no plugins\nmd(\"![\" * 16000 + \"x\" + \"]\" * 16000)\n```\n\n## Attack Chain\n1. Entry: rendered markdown -> `\"![\"*N + \"x\" + \"]\"*N` (no plugins). Guard: none on input size. Bypass proof: no global cap.\n2. Check: `not is_image` guards at inline_parser.py:141 (`no_link_before`) and :171 (`_label_contains_link`). Guard: high-water mark + nested-link short-circuit. Bypass proof: `is_image` is True for `![`, so BOTH guards are gated out; `max_image_depth` (:checked after) measured flat across all values because no image token is produced.\n3. Processing: reaches `precedence_scan` (:179) -> `sc.search(state.src, mark_pos, end_pos)` over the full body per opener.\n4. Sink: O(N) openers x O(N) scan -> O(N²) CPU.\n5. Impact: 48KB -> ~16s single-threaded worker stall.\n\n## Bypass Evidence\n- The LINK payload `\"[\"*n+\"x\"+\"]\"*n` is LINEAR on HEAD (0.076s @ 16k, ~2x per 2x) because links get the `_label_contains_link` short-circuit; the IMAGE payload `\"![\"*n+\"x\"+\"]\"*n` is O(n²) (0.27->1.05->3.92s, ~3.8x). Same HEAD, only `is_image` differs — proves the guard asymmetry, not incidental input growth.\n- `max_image_depth` set across 0..100 leaves runtime flat (no image token produced by failing scans).\n\n## Affected Versions\n`<= 3.3.3` (present on latest release tag v3.3.3 and HEAD).\n\n## Suggested Fix\nGeneralize the `no_link_before` high-water mark (and/or the `_label_contains_link` short-circuit) to cover the image path, so failed `![` scans do not each re-traverse the document.\n\n---\nReported by **zx (Jace)** — GitHub: @manus-use","severity":"high","score":7.5,"published":"2026-11-17T19:17:47.107Z","modified":"2026-11-19T23:00:36.653Z","withdrawn":false,"knownExploited":false,"affected":[{"ecosystem":"PyPI","name":"mistune","sources":[{"name":"OSV · GHSA-ww7q-mxrj-5ffg","url":"https://osv.dev/vulnerability/GHSA-ww7q-mxrj-5ffg"}],"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-ww7q-mxrj-5ffg","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-97699","https://github.com/lepture/mistune"],"sources":[{"name":"CVE","id":"CVE-2026-97699","modified":"2026-11-17T22:25:23.243Z","url":"https://www.cve.org/CVERecord?id=CVE-2026-97699"},{"name":"OSV","id":"GHSA-ww7q-mxrj-5ffg","modified":"2026-11-19T23:00:36.653352593Z","url":"https://osv.dev/vulnerability/GHSA-ww7q-mxrj-5ffg"}],"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-97699","source":"GitHub_M","state":"PUBLISHED","reasons":[],"replacements":[],"disputed":false,"unsupportedWhenAssigned":false,"reserved":"2026-09-24T21:43:37.209Z","published":"2026-11-17T19:17:47.107Z","modified":"2026-11-17T22:25:23.243Z"}],"publishers":[{"name":"GitHub_M","role":"CNA","organizationId":"a0819718-46f1-4df5-94e2-005712e83aaa","modified":"2026-11-17T19:17:47.107Z"},{"name":"CISA-ADP","role":"ADP","organizationId":"134c704f-9b21-4f2e-91b3-4a467353bcc0","modified":"2026-11-17T22:25:23.243Z"}],"references":[{"url":"https://github.com/lepture/mistune/security/advisories/GHSA-ww7q-mxrj-5ffg","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"}],"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-17T22:18:58.611884Z","decisions":[{"name":"Exploitation","value":"none"},{"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-97699"}],"remediation":[],"observedAt":"2026-11-20T00:27:12.988Z","kev":{"status":"not-listed","checkedAt":"2026-11-22T12:20:32.540Z"},"coverage":[{"source":"NVD","status":"no-result","checkedAt":"2026-11-17T19:40:53.339Z","attemptedAt":"2026-11-17T19:40:53.339Z"},{"source":"GHSA","status":"no-result","checkedAt":"2026-11-17T19:40:33.592Z","attemptedAt":"2026-11-17T19:40:33.592Z"},{"source":"EUVD","status":"no-result","checkedAt":"2026-11-17T19:40:33.729Z","attemptedAt":"2026-11-17T19:40:33.729Z"},{"source":"EPSS","status":"no-result","checkedAt":"2026-11-17T19:40:33.162Z","attemptedAt":"2026-11-17T19:40:33.162Z"}],"evidence":[],"aiSummary":null}