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 find() and findAll() in src/querying.ts, which maintain stacks of child-node arrays using unshift() and shift() at the front of the array. Because these operations shift every existing entry on each call, traversing a deeply nested document takes time quadratic in its nesting depth. An attacker can supply a deeply nested HTML or XML document to any API built on these functions - including filter(), getElements(), getElementsByTagName(), getElementsByClassName(), and getElementsByTagType() - to block the Node.js event loop. A document of 100,000 nested <b> tags (approximately 300 KB) causes findAll() to run for about 2 seconds.
Reject documents nested deeper than the application requires before searching them, or run the search in a worker thread that is terminated after a time limit.
import { parseDocument } from "htmlparser2";
import { findAll } from "domutils";
const doc = parseDocument("<b>".repeat(100_000));
console.time("findAll");
findAll(() => false, doc.children); // about 2 s with domutils 4.0.2
console.timeEnd("findAll");