Snyk has a proof-of-concept or detailed explanation of how to exploit this vulnerability.
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 applicationsUpgrade domutils to version 4.1.0 or higher.
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.
Reject documents nested deeper than the application requires before comparing or sorting their nodes.
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.