JavaScriptSeverity: MediumStatus: Published
Deeply nested documents make find() and findAll() take quadratic time
Applications that search untrusted HTML or XML documents with domutils’ find() or findAll(), or with the helpers built on find() (filter(), getElements(), getElementsByTagName(), getElementsByClassName() and getElementsByTagType()), are affected (CWE-407). These functions kept the child lists still to be searched on a stack that they grew and shrank at its front with unshift() and shift(), which moves every entry already on it, so searching a deeply nested document took time quadratic in its depth. npm package domutils versions >= 3.1.0 and <= 4.0.2 are affected: getElementsByClassName() from 3.2.0, and the other functions from 3.1.0. Fixed in 4.1.0. GitHub rates it medium, with CVSS 3.1 score 5.3. The advisory credits ucsurf as reporter. Fixed by Felix Boehm (@fb55).
Impact
Applications that search untrusted HTML or XML documents with domutils’ find() or findAll(), or with the helpers built on find() (filter(), getElements(), getElementsByTagName(), getElementsByClassName() and getElementsByTagType()), are affected. These functions kept the child lists still to be searched on a stack that they grew and shrank at its front with unshift() and shift(), which moves every entry already on it, so searching a deeply nested document took time quadratic in its depth (CWE-407). That can block the event loop.
Affected versions and fix
The npm package domutils is affected in versions >= 3.1.0 and <= 4.0.2: getElementsByClassName() from 3.2.0, which added it, and the other functions from 3.1.0, which introduced these stacks. The patched release is 4.1.0.
The published advisory is GHSA-qx47-vpjg-465w. 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 as reporter.
The advisory says this was fixed in 4.1.0, which grows and shrinks the stacks at their ends. On the repository, Felix Boehm merged pull request 2406 (“fix: keep tree queries linear and stack-safe on deep documents”) 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 searching them, or running the search in a worker that is terminated after a time limit, if an upgrade is not possible yet.
Timeline
- Found
- Reported via private vulnerability report
- Advisory published
- Entry last updated
Machine-readable: JSON · Markdown · ID security/javascript/fb55__domutils/2026-10-05-find-findall-quadratic-time
If this work is useful to you, you can support it on Buy Me a Coffee.