Summary
xmldom and @xmldom/xmldom allowed attacker-controlled strings containing the CDATA terminator sequence ]]> to be inserted into CDATASection nodes without sanitization or splitting.
When such nodes were serialized, the raw content was emitted verbatim, turning what should have been text-only data into active XML markup and enabling XML structure injection and manipulation of downstream business logic that consumes the XML.
Affected context
The vulnerability appears in applications that:
- Use xmldom (≤ 0.6.0) or @xmldom/xmldom (prior to 0.8.12/0.9.9) for parsing and serializing XML, and
- Insert attacker-controlled or otherwise untrusted data into CDATASection nodes, and
- Rely on XMLSerializer output as a trusted XML document for later processing, persistence, or transmission.
In these cases, data that should remain inert text inside CDATA can be transformed into active XML structure when serialized, potentially affecting any component that later parses or interprets the XML.
Exploit preconditions
- Attack surface: XML-based APIs, document generation pathways, or integrations that accept untrusted input and embed it into CDATA sections before serialization.
- Required access: Ability to supply or influence the text content placed into CDATASection nodes (e.g., user input fields, external feed data, partner integrations).
- Trigger point: Invocation of XMLSerializer on a DOM that holds a CDATASection containing the
]]>terminator sequence supplied by the attacker. - Why exploitation is possible: The serializer does not reject, escape, or safely split CDATA content containing the
]]>terminator. As a result, the emitted XML breaks out of the original CDATA, allowing the attacker-controlled data that follows to be interpreted as XML markup instead of plain text.
Why this happens
This issue stems from improper neutralization of special elements in XML output, aligning with CWE-91: XML Injection.
The library assumes that content placed into CDATASection nodes can be emitted verbatim, without considering that untrusted input might contain the CDATA terminator sequence ]]>.
During serialization, XMLSerializer writes CDATA content directly, so a malicious payload with ]]> closes the CDATA early and injects additional tags, attributes, or entities.
Conceptually, the bug is an output encoding/escaping failure: data and XML control characters share the same channel, and the boundary between data (inside CDATA) and markup is not enforced when user-controlled text can contain structural tokens.
Potential impact
- Injection of arbitrary XML elements or attributes into serialized documents.
- Manipulation of downstream XML-based business logic (e.g., changing operation types, flags, or configuration-like values).
- Circumvention of application-level validation that assumes certain XML regions are text-only.
- Data integrity issues where stored or forwarded XML no longer matches the original application intent.
- Potential chaining into other XML-related issues (e.g., logic flaws, authorization bypasses) depending on how the injected XML is consumed.
General mitigation guidance
Effective mitigation focuses on enforcing a strong separation between untrusted data and XML structure, especially around CDATA sections:
- Treat all input destined for CDATASection nodes as untrusted and ensure it cannot contain raw CDATA terminators; either sanitize or reject such sequences.
- Prefer safe serialization patterns that automatically escape or split CDATA content when structural tokens appear, rather than writing node values verbatim.
- Centralize XML construction in a small, well-reviewed layer where rules for handling untrusted data (encoding, escaping, or schema enforcement) are consistently applied.
- Where possible, restrict the XML surface by using strict schemas (XSD, Relax NG) and validating serialized documents against them before further processing.
- Apply least-privilege principles around systems that consume serialized XML so that XML injection cannot directly lead to high-impact state changes without additional checks.
How teams detect issues like this
Detection typically involves combining code-level analysis with behavioral checks:
- Static analysis and code review:
- Search for uses of xmldom or @xmldom/xmldom where CDATASection nodes are created from variables derived from user input or external data sources.
- Flag patterns that directly accept untrusted strings into CDATASection.nodeValue or equivalent without sanitization.
- Review serialization call sites (e.g., new XMLSerializer().serializeToString(doc)) that subsequently feed XML into security-sensitive workflows (e.g., signing, policy enforcement, or cross-system messages).
- Policy and tooling:
- Enforce secure coding guidelines for XML handling, including mandatory escaping/sanitization for data inserted into CDATA.
- Integrate automated code review tools or linters with custom rules to identify untrusted-to-CDATA flows and missing checks.
- Runtime/behavioral checks:
- Log and monitor serialized XML documents in testing or staging environments, scanning for unexpected structural changes originating from data fields that should be text-only.

