CVE-2026-129522: Quadratic rescanning in MDEx auto-close link scanner allows CPU denial of service
Summary
Inefficient Algorithmic Complexity vulnerability in MDEx.FragmentParser in leandrocp mdex allows an attacker who controls streamed or auto-closed Markdown to cause a denial of service through CPU exhaustion. Any application that renders untrusted Markdown with MDEx.stream/2 or the autoclose option is affected, for example live previews or streamed LLM output.
While auto-closing the last paragraph, closebracket/5 in lib/mdex/fragmentparser.ex runs an unbounded forward scan of the link tail for every ](. When that scan finds no valid link, scanning resumes just after the ], so the next ]( rescans the same tail. Each closed link also re-filters every pending image opener. Repeated [](x (, [](x(, or . The reporter measured 120 KB of [](x ( at 12.0 s in a one-chunk MDEx.stream/2, against about 10 ms for MDEx.tohtml!/1 without auto-close.
Proof of concept
1. Build a single paragraph of 20,000 repetitions of z (about 120 KB, no blank line). 2. Pass it as one chunk to MDEx.stream/2 and consume the stream. 3. Observe the call take over ten seconds, while MDEx.tohtml!/1 on the same input returns in about 10 ms. Doubling the input roughly quadruples the time.
Impact
An attacker who can submit Markdown to a streaming or auto-closing renderer can occupy a CPU scheduler for seconds per request with about 100 KB of input, slowing or denying rendering for other users.
Configurations
The application must render untrusted Markdown with auto-closing enabled: through MDEx.stream/2, where it is on unless autoclose: false is passed, or with the autoclose option set on a document. Rendering with the default options of MDEx.tohtml/2 and MDEx.parsedocument/2 does not run the affected scanner.
Other sources
Inefficient Algorithmic Complexity vulnerability in MDEx.FragmentParser in leandrocp mdex allows an attacker who controls streamed or auto-closed Markdown to cause a denial of service through CPU exhaustion. Any application that renders untrusted Markdown with MDEx.stream/2 or the autoclose option is affected, for example live previews or streamed LLM output.
While auto-closing the last paragraph, closebracket/5 in lib/mdex/fragmentparser.ex runs an unbounded forward scan of the link tail for every ](. When that scan finds no valid link, scanning resumes just after the ], so the next ]( rescans the same tail. Each closed link also re-filters every pending image opener. Repeated [](x (, [](x(, or ![ openers in one paragraph therefore cost quadratic time, and about 100 KB of input occupies a scheduler for over ten seconds.
This issue affects mdex: from 0.14.2 before 0.15.0.
— MITRE
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
erlang/mdexto a version that resolves this vulnerability.Fixed in 0.15.0 - Upgrade
Upgrade
mdexto a version that resolves this vulnerability.Fixed in 0.15.0 - Configuration
Disable auto-closing by passing auto_close: false to MDEx.stream/2 or setting auto_close: false on the document.
MDEx.stream/2 and MDEx documents auto_close = false
Event History
Frequently Asked Questions
Which applications are realistically exposed to this denial of service?
Applications that render attacker-controlled Markdown using MDEx.stream/2 or MDEx with the auto_close option are affected. Examples include live Markdown previews and applications rendering streamed LLM output.
What input does an attacker need to supply?
An attacker needs control over streamed or auto-closed Markdown in a single paragraph. Repeated malformed link-like sequences such as [](x (, [](x(, or repeated ![ openers can trigger quadratic CPU consumption.
Are ordinary MDEx rendering configurations affected?
The issue is specifically described for MDEx.stream/2 and use of the auto_close option. The provided information does not establish that rendering paths without streamed or auto-closed Markdown are affected.
What versions should be remediated?
The affected range is mdex 0.14.2 through versions before 0.15.0. Upgrade to 0.15.0 or later.
What can be done before upgrading?
Avoid rendering untrusted Markdown through MDEx.stream/2 or with auto_close enabled where possible. Apply input-size and processing-time limits to untrusted streamed or auto-closed Markdown to reduce CPU-exhaustion risk.