JavaScriptSeverity: MediumStatus: Published

Comparing the positions of deeply nested nodes takes quadratic time

Applications that call domutils’ compareDocumentPosition() or uniqueSort() on nodes of untrusted HTML or XML documents are affected (CWE-407). compareDocumentPosition() built each node’s chain of ancestors with unshift(), so comparing two nodes took time quadratic in their depth, and uniqueSort() pays this cost on every comparison it makes. npm package domutils versions >= 1.5.0 and <= 4.0.2 are affected. Fixed in 4.1.0. GitHub rates it medium, with CVSS 3.1 score 5.3. The advisory credits ucsurf and zachariah-mithani as reporters. Fixed by Felix Boehm (@fb55).

Impact

Applications that call domutils’ compareDocumentPosition() or uniqueSort() on nodes of untrusted HTML or XML documents are affected. compareDocumentPosition() built each node’s chain of ancestors with unshift(), which moves every entry already in the chain, so comparing two nodes took time quadratic in their depth (CWE-407). uniqueSort() pays this cost on every comparison it makes. A single comparison of two deeply nested nodes can block the event loop.

Affected versions and fix

The npm package domutils is affected in versions >= 1.5.0 and <= 4.0.2. The patched release is 4.1.0.

The published advisory is GHSA-pvqx-4ghw-x6gp. GitHub rates it medium, with CVSS 3.1 score 5.3 (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L). 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 and zachariah-mithani as reporters.

The advisory says this was fixed in 4.1.0. On the repository, Felix Boehm merged pull request 2407 (“fix: compare document positions in linear time”) on 2026-12-03. That change is in v4.1.0. The pull request is not ours.

The advisory suggests rejecting documents nested deeper than the application needs before comparing or sorting their nodes, if an upgrade is not possible yet.

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-compare-positions-quadratic-time

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