Details
Measured on Node v18.20.8 (absolute ms vary by host; the load-bearing fact is that doubling the
input ~quadruples the time — canonical O(n²)):
Finding A, isolated ("<r>" + "a<"×N + "</r>", normalize disabled to isolate the re-scan):
| N | input bytes | @xmldom/xmldom 0.9.10 | 0.8.13 |
|--:|--:|--:|--:|
| 2000 | 4007 | 43 ms | 37 ms |
| 4000 | 8007 | 129 ms | 106 ms |
| 8000 | 16007 | 434 ms | 424 ms |
| 16000 | 32007 | 1629 ms | 1611 ms |
Finding B, isolated ("<r>" + "a<>"×N + "</r>", time attributable to normalize()):
| K (N) | input bytes | 0.9.10 | 0.8.13 |
|--:|--:|--:|--:|
| 4000 | 12007 | 120 ms | 165 ms |
| 8000 | 24007 | 589 ms | 771 ms |
| 16000 | 48007 | 3142 ms | 4448 ms |
| 32000 | 96007 | 12127 ms | 12951 ms |
Combined (default parser, both findings; "<r>" + "a<"×N + "</r>"):
| N | input bytes | 0.9.10 | 0.8.13 |
|--:|--:|--:|--:|
| 4000 | 8007 | 341 ms | 397 ms |
| 8000 | 16007 | 1894 ms | 1641 ms |
| 16000 | 32007 | 4398 ms | 7661 ms |
~32 KB of input → several seconds of single-threaded event-loop stall.
Finding B via the public normalize() API (no parser)
const { DOMImplementation } = require('@xmldom/xmldom');
function timeNormalize(K) {
const doc = new DOMImplementation().createDocument(null, 'r', null);
const el = doc.documentElement;
for (let i = 0; i < K; i++) el.appendChild(doc.createTextNode('x')); // K adjacent text nodes
const t0 = process.hrtime.bigint();
doc.normalize(); // O(K^2) merge — no parsing involved
const ms = Number(process.hrtime.bigint() - t0) / 1e6;
console.log('K=' + K + ' time=' + ms.toFixed(1) + ' ms');
}
for (const K of [2000, 4000, 8000, 16000, 32000]) timeNormalize(K);
Measured on Node v18.20.8 (doubling K ~quadruples the time — O(K²)):
| K | 0.9.10 | 0.8.13 |
|--:|--:|--:|
| 2000 | 5.7 ms | 5.6 ms |
| 32000 | 1263 ms | 1704 ms |
This path is reachable by any application that builds a DOM from attacker-influenced data and callsnormalize(), entirely independent of DOMParser.
Impact
Availability only: a single parse of a small crafted document blocks the Node.js event loop for the
duration of the quadratic work (multiple seconds at tens of KB; larger inputs scale as O(n²)). No
memory blow-up beyond transient strings, no data exposure, no integrity impact. Because XML is
routinely accepted from untrusted sources and parsed with default options, one request can stall a
server. The payloads are highly compressible, so any endpoint accepting compressed XML faces
additional amplification. Finding B is additionally reachable via an explicit normalize() call on a
programmatically built DOM (see Proof of Concept), so applications that construct a document from attacker-influenced
data and normalize it are exposed even without parsing.
Severity note
The complexity is quadratic, not exponential, so a multi-second stall requires
tens-to-hundreds of KB of input. VA:H reflects that xmldom applies no input-size limit and the
path runs on default-options parsing, so a single unbounded parse can fully stall the event loop.
Fix Applied
Two independent, non-breaking fixes shipped together — each alone leaves the other's quadratic cost dominating the default parse.
Finding A — terminate the malformed tag-name scan at an embedded <, so error recovery is linear instead of O(n²). DOM output is unchanged; only the reported error-message text differs (error strings are not a semver contract).
Finding B — merge adjacent text nodes in normalize() in O(K) instead of O(K²), which also closes the same slowdown reachable programmatically through a direct normalize() call. Both ship on both maintained versions.