CVE-2026-135775: Quadratic CPU consumption in mdex auto-close trimming of trailing parentheses after bare URLs
Summary
Inefficient Algorithmic Complexity vulnerability in leandrocp mdex allows an attacker who controls rendered Markdown to cause a denial of service via a bare URL followed by many closing parentheses.
When auto-close is active, MDEx.FragmentParser.autolinksize/2 in lib/mdex/fragmentparser.ex trims trailing ) from a bare URL one byte at a time and recounts every ( and ) in the remaining URL at each step, so a URL followed by N parentheses costs O(N²) work. Around 20 KB of input pins a scheduler for tens of seconds, and MDEx.stream/2 repeats the completion over the whole accumulated source for every chunk. No extension needs to be enabled. Rendering with auto-close disabled is not affected.
This issue affects mdex: from 0.14.2 before 0.15.0.
Details
1. Reaching the trimmer. With auto-close active, MDEx.FragmentParser.complete/2 runs completeinline/3, which calls unmatchedsuffix/1. That masks bare URLs through maskurls/1 and maskurlspans/4, and each URL span is measured with autolinktext/1. No extension needs to be enabled.
2. Quadratic trim. autolinksize/2 walks back from the end of the URL candidate. For every trailing ) it takes the remaining prefix, counts all ( and all ) in it with countchar/2, and if closers outnumber openers it drops one byte and recurses. A URL followed by N ) therefore performs N full scans of a string of length up to N, which is O(N²).
3. Amplification. MDEx.stream/2 re-runs completion over the whole accumulated source for every chunk, so a payload delivered over many chunks multiplies the cost. None of the entry points limits input size.
Proof of concept
1. Build the input "http://x" followed by 15,000 ) characters (about 15 KB). 2. Render it with MDEx.tohtml!(markdown): it completes in a few milliseconds. 3. Render the same input with MDEx.tohtml!(markdown, autoclose: true), or pass it as a single chunk to MDEx.stream/2: rendering takes tens of seconds and holds a scheduler for the whole time. 4. Doubling the number of parentheses roughly quadruples the time.
Impact
An attacker who can supply Markdown, or steer LLM output, that an application renders with auto-close can pin BEAM schedulers with a few kilobytes of input per request, delaying or denying service to every other user of the node.
Workarounds
Render untrusted Markdown with auto-close disabled: pass autoclose: false to MDEx.stream/2, and do not pass autoclose: true to MDEx.tohtml/2 or the other renderers.
Configurations
The vulnerable code runs only when auto-close is active: in MDEx.stream/2, where autoclose defaults to true; in MDEx.tohtml/2 and the other renderers when called with autoclose: true; and in MDEx.Document streaming buffers with autoclose set. Rendering with the default options of MDEx.tohtml/2 does not reach it.
Other sources
Inefficient Algorithmic Complexity vulnerability in leandrocp mdex allows an attacker who controls rendered Markdown to cause a denial of service via a bare URL followed by many closing parentheses.
When auto-close is active, MDEx.FragmentParser.autolinksize/2 in lib/mdex/fragmentparser.ex trims trailing ) from a bare URL one byte at a time and recounts every ( and ) in the remaining URL at each step, so a URL followed by N parentheses costs O(N²) work. Around 20 KB of input pins a scheduler for tens of seconds, and MDEx.stream/2 repeats the completion over the whole accumulated source for every chunk. No extension needs to be enabled. Rendering with auto-close disabled is not affected.
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-close when rendering untrusted Markdown: pass auto_close: false to MDEx.stream/2 and do not enable auto_close: true for MDEx.to_html/2 or other renderers.
MDEx auto_close = false
Event History
Frequently Asked Questions
Which deployments are exposed to this denial-of-service issue?
MDEx versions from 0.14.2 before 0.15.0 are affected when rendering uses auto-close. No Markdown extension needs to be enabled; rendering with auto-close disabled is not affected.
What input does an attacker need to supply to trigger the expensive processing?
The attacker must control Markdown that is rendered and include a bare URL followed by many closing parentheses. Approximately 20 KB of such input can pin a scheduler for tens of seconds.
Does streaming change the impact?
Yes. MDEx.stream/2 repeats completion over the entire accumulated source for each chunk, which can amplify the processing cost for malicious input.
What mitigation is available if upgrading is not immediately possible?
Disable auto-close for Markdown rendering. This avoids the affected trailing-parenthesis trimming behavior.