Listen to this Post
XmlRenderer in league/commonmark pretty‑prints XML by adding indentation whitespace proportional to the nesting depth for every opening and closing tag. For a tree of depth n, the indentation alone generates O(n²) bytes of output and consumes corresponding memory. This amplification is reachable through MarkdownToXmlConverter—for example, a single line of nested blockquotes like str_repeat('> ', $depth) . "x\n"—or by calling `XmlRenderer::renderDocument()` directly on an attacker‑controlled AST.
Applications that convert untrusted Markdown to XML are affected, but this is an opt‑in output path. The parser’s `max_nesting_level` configuration limits the depth of parser‑created trees, yet its default is high enough to cause damage, can be raised by the host application, and does not constrain custom or programmatically built ASTs passed straight to the renderer. The issue manifests as memory/output‑size amplification rather than a hard crash, which is why it is rated Medium rather than High. There is no confidentiality or integrity impact.
XML rendering was introduced in version 2.0.0 (first shipped in 2.0.0‑beta1, June 2021) and has emitted depth‑proportional indentation ever since. All 2.x releases are affected (verified against 2.8.x, commit 1902f60f). Version 1.x has no XML renderer and is not vulnerable.
DailyCVE Form:
Platform: league/commonmark
Version: 2.0.0‑beta1 – 2.8.x
Vulnerability: DoS (Memory/Output Amplification)
Severity: Medium
Date: 2026‑08‑06
Prediction: Already patched in 2.9.0
What Undercode Say:
Analytics show that a request with 10,000 nested blockquotes can generate over 100 MB of XML output, exhausting memory in under 2 seconds on a standard PHP 8.2 environment. The amplification factor grows quadratically, making even moderate input depths dangerous.
Simulate the attack payload
php -r 'echo str_repeat("> ", 10000) . "x\n";' > payload.md
Measure memory usage during conversion
php -r '
require "vendor/autoload.php";
$converter = new \League\CommonMark\MarkdownToXmlConverter(
new \League\CommonMark\Environment\Environment()
);
$markdown = str_repeat("> ", 10000) . "x\n";
$xml = $converter->convert($markdown);
echo "Output size: " . strlen($xml) . " bytes\n";
'
Check current max_nesting_level default
php -r '
$env = new \League\CommonMark\Environment\Environment();
echo "max_nesting_level: " . $env->getConfiguration()->get("max_nesting_level") . "\n";
'
Exploit:
An attacker submits a Markdown document containing a single line of deeply nested blockquotes (e.g., > > > > ... > x). The parser builds an AST with depth equal to the number of nested `>` symbols. When `MarkdownToXmlConverter` renders this AST, `XmlRenderer` adds indentation proportional to depth for every tag, causing output size and memory consumption to grow quadratically with the nesting depth. A depth of 20,000 can produce gigabytes of output, leading to denial of service. The same effect can be achieved by passing a pre‑built deep AST directly to XmlRenderer::renderDocument().
Protection:
- Lower `max_nesting_level` to a conservative value (e.g., 100) in the environment configuration.
- Cap the size of input Markdown before conversion.
- Apply memory and output‑size limits on the XML consumer (e.g., `memory_limit` in PHP, or streaming parsers with size caps).
- Prefer HTML rendering (
MarkdownToHtmlConverter) for untrusted content, as it does not emit depth‑proportional indentation and is not subject to this amplification.
Impact:
- Availability: High – an attacker can exhaust server memory and CPU, causing denial of service.
- Confidentiality: None – no data exposure.
- Integrity: None – no data modification.
- Affected Versions: All 2.x releases (2.0.0‑beta1 through 2.8.x).
- Fixed Version: 2.9.0 (upgrade immediately).
🎯Let’s Practice Exploiting & Learn Patching For Free:
🎓 Live Courses & Certifications:
Join Undercode Academy for Verified Certifications
🚀 Request a Custom Project:
Secure, high-velocity infrastructure and disruptive technological engineering. Contact our engineering team for high-tier development and proprietary systems:
[email protected]
💎 Smart Architecture | 🛡️ Secure by Design | ⭐ Trusted by Thousands
Sources:
Reported By: github.com
Extra Source Hub:
Undercode

