Details
No authentication, special options, or invalid XML is required. A valid, deeply nested XML
document is enough.
---
Disclosure
The normalize() vector was publicly disclosed at 2026-04-06T11:25:07Z via
xmldom/xmldom#987 (closed without merge).serializeToString() and the five additional recursive entry points were not mentioned in that PR.
---
Fix Applied
All seven affected traversals have been converted from recursive to iterative implementations, eliminating call-stack consumption on deep trees.
walkDOM utility
A new walkDOM(node, context, callbacks) utility is introduced. It traverses the subtree rooted at node in depth-first order using an explicit JavaScript array as a stack, consuming heap memory instead of call-stack frames. context is an arbitrary value threaded through the walk — each callbacks.enter(node, context) call returns the context to pass to that node's children, enabling per-branch state (e.g. namespace snapshots in the serializer). callbacks.exit(node, context) (optional) is called in post-order after all children have been visited.
The following six operations are re-implemented on top of walkDOM:
| Operation | Public entry point(s) |
|---|---|
| _visitNode helper | getElementsByTagName(), getElementsByTagNameNS(), getElementsByClassName(), getElementById() |
| getTextContent inner function | node.textContent getter |
| cloneNode module function | Node.prototype.cloneNode(true) |
| importNode module function | Document.prototype.importNode(node, true) |
| serializeToString worker | XMLSerializer.prototype.serializeToString(), Node.prototype.toString(), NodeList.prototype.toString() |
| normalize | Node.prototype.normalize() |
normalize uses walkDOM with a null context and an enter callback that merges adjacent Text children of the current node before walkDOM reads and queues those children — so the surviving post-merge children are what the walker descends into.
Custom iterative loop for isEqualNode
One function cannot use walkDOM:
`Node.prototype.isEqualNode(other)` (0.9.x only; absent from 0.8.x) compares two trees in parallel. It maintains an explicit stack of {node, other} node pairs — one node from each tree — which cannot be expressed with walkDOM's single-tree visitor.
After the fix
All seven entry points succeed on trees of arbitrary depth without throwing RangeError. The original PoCs still demonstrate the vulnerability on unpatched versions and confirm the fix on patched versions.