JavaScriptSeverity: HighStatus: Published

Many nodes from deeply nested or wide documents cause excessive CPU use in removeSubsets()

Applications that pass many nodes of untrusted HTML or XML documents to domutils’ removeSubsets() are affected (CWE-407). css-select calls it on the context nodes whenever a query is given an array of roots, such as selectAll(query, nodes) and cheerio’s .find(). For each node, removeSubsets() searched the whole array for the node and for each of its ancestors, and removed nodes with splice(), so its running time grew with the square of the number of nodes, times their depth. npm package domutils versions >= 1.3.0 and <= 4.0.2 are affected. Fixed in 4.1.0. There is no fix for domutils 3.x. GitHub rates it high, with CVSS 3.1 score 7.5. The advisory credits ucsurf as reporter. The repository fix includes pull request 2313 by zhangj23, merged on 2026-10-10, and is in 4.1.0.

Impact

Applications that pass many nodes of untrusted HTML or XML documents to domutils’ removeSubsets() are affected. css-select calls it on the context nodes whenever a query is given an array of roots, such as selectAll(query, nodes) and cheerio’s .find(). For each node, removeSubsets() searched the whole array for the node and for each of its ancestors, and removed nodes with splice(), so its running time grew with the square of the number of nodes, times their depth (CWE-407). That can block the event loop.

Affected versions and fix

The npm package domutils is affected in versions >= 1.3.0 and <= 4.0.2. The patched release is 4.1.0. The advisory says there is no fix for domutils 3.x. cheerio 1.2.0 depends on domutils 3 and does not work with domutils 4, so its users need the workarounds until a cheerio release depends on domutils 4.1.0.

The published advisory is GHSA-42h4-gpjh-8xhf. GitHub rates it high, with CVSS 3.1 score 7.5 (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H). Felix Boehm (@fb55) published the advisory on 2026-12-03. It was reported on 2026-10-05 through GitHub private vulnerability reporting. The advisory credits ucsurf as reporter.

The advisory says this was fixed in 4.1.0, which looks nodes up in a set and walks each shared ancestor once. On the repository, pull request 2313 (“perf: replace two quadratic scans in helpers with linear ones”) by zhangj23 was merged on 2026-10-10 and is in v4.1.0. The pull request is not ours.

The advisory suggests limiting the number of nodes passed to removeSubsets() and the depth of untrusted documents. You can skip the call if every node is distinct and none is an ancestor of another.

Timeline

  1. Found
  2. Reported via private vulnerability report
  3. Advisory published
  4. Entry last updated

Machine-readable: JSON · Markdown · ID security/javascript/fb55__domutils/2026-10-05-removesubsets-excessive-cpu

If this work is useful to you, you can support it on Buy Me a Coffee.