Summary
xmldom's JavaScript DOM implementation performs several recursive traversals without enforcing a maximum depth, allowing extremely deep XML structures to exhaust the call stack.
When an application parses or walks attacker-controlled XML, a maliciously nested DOM tree can trigger a RangeError and crash the process, turning XML input into a denial-of-service vector.
Affected context
This vulnerability manifests in Node.js or browser-based applications that rely on xmldom or @xmldom/xmldom to parse and manipulate XML documents.
It becomes relevant when XML content can be influenced by external input—such as API requests, uploaded files, or integration feeds—and the resulting DOM tree is traversed using the library's recursive helpers.
In such contexts, extremely deep or intentionally nested XML structures can drive the recursion into stack exhaustion, especially in environments where input size or structural complexity is not constrained.
Exploit preconditions
- Attack surface: XML parsing and DOM manipulation endpoints (e.g., HTTP APIs, file upload handlers, message processors) that use xmldom.
- Required access: Ability to supply or influence XML input consumed by the parser (remote or local, depending on the application design).
- Trigger point: Construction and recursive traversal of a deeply nested DOM tree during parsing or subsequent processing.
- Why exploitation is possible: Recursive functions in
lib/dom.jsoperate without a depth limit or structural guard, allowing attacker-controlled nesting depth to exceed the call stack capacity and raise a RangeError.
Why this happens
The core issue aligns with CWE-674: Uncontrolled Recursion and is closely related to CWE-776: Improper Restriction of Recursive XML Expansion.
xmldom's DOM traversal routines rely on naive recursion that assumes reasonable tree depth and does not enforce explicit limits or iterative alternatives.
When parsing highly nested XML, each additional level of the tree consumes another frame on the call stack until the environment's recursion limit is breached, resulting in a runtime exception and process termination.
Abstractly, this pattern reflects a failure to treat nested or attacker-influenced data structures as potentially adversarial, leaving resource exhaustion unchecked.
Potential impact
- Application may crash with a
RangeError: Maximum call stack size exceeded. - Service availability could be degraded or fully disrupted, leading to denial of service.
- Scheduled background jobs or XML-driven workflows can be halted or repeatedly restarted.
- Error-handling and monitoring systems may be flooded with crash events and stack traces.
General mitigation guidance
Effective mitigation focuses on limiting recursion depth and constraining XML structure complexity before or during parsing.
Common defensive patterns include:
- Enforcing maximum depth and node-count limits on XML inputs, rejecting documents that exceed safe thresholds.
- Preferring iterative traversal strategies over unbounded recursion when walking DOM trees.
- Introducing configurable guards in parsing and processing logic to detect and abort on excessively nested or complex structures.
- Applying input validation and normalization steps that flatten or simplify XML before deep processing.
- Running XML-handling components with robust fault isolation (e.g., worker processes) so that crashes do not take down the entire service.
How teams detect issues like this
Organizations can detect similar recursion-based exhaustion risks through:
- Static analysis rules that flag recursive functions operating on untrusted or externally sourced data without explicit limits.
- Code review checklists that require depth bounds or defensive parsing patterns for XML and other nested formats.
- Runtime monitoring for repeated
RangeErrorexceptions and process restarts in XML-heavy components. - Policy enforcement that mandates safe XML processing libraries or wrappers with resource controls for services exposed to untrusted input.

