{"id":"EEF-CVE-2026-134915","summary":"Quadratic HTML tag tracking in MDEx.stream/2 allows CPU exhaustion via unmatched closing tags","details":"## Summary\n\nInefficient Algorithmic Complexity vulnerability in leandrocp mdex allows an attacker who controls Markdown passed to `MDEx.stream/2` to exhaust CPU via unmatched HTML closing tags.\n\n`MDEx.stream/2` tracks open HTML tags with `MDEx.FragmentParser.continue_html_context/2` in `lib/mdex/fragment_parser.ex`. Every non-void opening tag is pushed onto an unbounded list, and `close_html_tag/2` scans the whole list for each closing tag. A closer with no matching opener leaves the list unchanged, so the next closer scans it again. An HTML block of N openers followed by N unmatched closers therefore costs O(N²), and about 270 KB of input keeps a scheduler busy for tens of seconds. The tracking runs on every HTML block and inline HTML literal regardless of the `auto_close` option and the render `unsafe` setting. `MDEx.to_html/1` and the other non-streaming entry points are not affected.\n\nThis issue affects mdex: from 0.14.0 before 0.15.0.\n\n## Details\n\n**1. Reachability.** `MDEx.stream/2` renders each chunk through `emit_stream_source`, `stream_source_blocks` and `stream_node_groups` in `lib/mdex.ex`. `stream_node_groups` calls `MDEx.FragmentParser.continue_html_context/2` on every parsed node, so every `HtmlBlock` and `HtmlInline` literal is scanned, whatever the `auto_close` and render `unsafe` settings are.\n\n**2. Unbounded stack.** `scan_html` pushes every non-void, non-self-closing opening tag onto the context list with no size limit.\n\n**3. Quadratic scan.** For each closing tag, `close_html_tag/2` runs `Enum.split_while/2` over the whole list. When no matching opener exists, it returns the list unchanged, so every following unmatched closer walks the full list again. N openers followed by N unmatched closers cost O(N²).\n\n## Proof of concept\n\n1. Build a Markdown string of `\u003cdiv\u003e` repeated 30,000 times followed by `\u003c/b\u003e` repeated 30,000 times (270,000 bytes).\n2. Render it as one chunk with `MDEx.stream(auto_close: false)` and run the stream.\n3. Observe about 30 seconds of CPU on mdex 0.14.9, against a few milliseconds for `MDEx.to_html!/1` on the same input. Doubling the input roughly quadruples the time.\n\n## Impact\n\nAn attacker who can submit Markdown that an application renders with `MDEx.stream/2` can tie up a BEAM scheduler for tens of seconds per request, and a few concurrent requests stall the node.","aliases":["CVE-2026-134915"],"modified":"2026-11-30T18:45:05.746238261Z","published":"2026-11-30T18:43:11.147Z","database_specific":{"$schema":"https://cna.erlef.org/schemas/osv/record-0.1.0.json","capec_ids":["CAPEC-130"],"cpe_ids":["cpe:2.3:a:leandrocp:mdex:*:*:*:*:*:*:*:*"],"cwe_ids":["CWE-407"]},"references":[{"type":"WEB","url":"https://cna.erlef.org/cves/CVE-2026-134915.html"},{"type":"WEB","url":"https://github.com/leandrocp/mdex/commit/a88793cb0fc5caf75bf878b92c64d36817824765"},{"type":"FIX","url":"https://github.com/leandrocp/mdex/commit/2c29b28cd0473c24347aa00b95d16f9ce5f9d9af"},{"type":"PACKAGE","url":"https://hex.pm/packages/mdex"}],"affected":[{"package":{"name":"mdex","ecosystem":"Hex","purl":"pkg:hex/mdex"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0.14.0"},{"fixed":"0.15.0"}]}],"versions":["0.14.0","0.14.1","0.14.2","0.14.3","0.14.4","0.14.5","0.14.6","0.14.7","0.14.8","0.14.9"],"ecosystem_specific":{"modules":["'Elixir.MDEx.FragmentParser'","'Elixir.MDEx'"],"program_files":["lib/mdex/fragment_parser.ex","lib/mdex.ex"],"program_routines":["'Elixir.MDEx.FragmentParser':close_html_tag/2","'Elixir.MDEx.FragmentParser':continue_html_context/2","'Elixir.MDEx':stream/2"],"$schema":"https://cna.erlef.org/schemas/osv/affected-0.1.0.json"},"database_specific":{"source":"https://cna.erlef.org/osv/EEF-CVE-2026-134915.json","$schema":"https://cna.erlef.org/schemas/osv/affected-0.1.0.json","modules":["'Elixir.MDEx.FragmentParser'","'Elixir.MDEx'"],"program_files":["lib/mdex/fragment_parser.ex","lib/mdex.ex"],"program_routines":["'Elixir.MDEx.FragmentParser':close_html_tag/2","'Elixir.MDEx.FragmentParser':continue_html_context/2","'Elixir.MDEx':stream/2"]}},{"ranges":[{"type":"GIT","repo":"https://github.com/leandrocp/mdex","events":[{"introduced":"a88793cb0fc5caf75bf878b92c64d36817824765"},{"fixed":"2c29b28cd0473c24347aa00b95d16f9ce5f9d9af"}]}],"versions":["v0.14.9","v0.14.8","v0.14.7","v0.14.6","v0.14.5","v0.14.4","v0.14.3","v0.14.2","v0.14.1","v0.14.0"],"database_specific":{"$schema":"https://cna.erlef.org/schemas/osv/affected-0.1.0.json","source":"https://cna.erlef.org/osv/EEF-CVE-2026-134915.json","modules":["'Elixir.MDEx.FragmentParser'","'Elixir.MDEx'"],"program_files":["lib/mdex/fragment_parser.ex","lib/mdex.ex"],"program_routines":["'Elixir.MDEx.FragmentParser':close_html_tag/2","'Elixir.MDEx.FragmentParser':continue_html_context/2","'Elixir.MDEx':stream/2"]}}],"schema_version":"1.9.2","severity":[{"type":"CVSS_V4","score":"CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N","source":"CNA"}],"credits":[{"name":"Peter Ullrich","type":"FINDER"},{"name":"Peter Ullrich","type":"REPORTER"},{"name":"Jonatan Männchen / EEF","type":"ANALYST"},{"name":"Leandro Pereira","type":"REMEDIATION_DEVELOPER"}]}