Summary
A flaw in fast-xml-parser's XML entity handling allows attackers to redefine built-in entities like <, >, &, ", and ' using crafted DOCTYPE declarations.
When the parsed output is rendered in a browser or embedded into HTML without strict encoding, this can lead to cross-site scripting (XSS) and execution of attacker-controlled JavaScript.
Affected context
This vulnerability appears in applications that rely on fast-xml-parser (versions 4.1.3 to before 5.3.5) to convert untrusted or semi-trusted XML into JavaScript objects or HTML fragments.
It becomes risky when:
- XML input can contain custom DOCTYPE entity declarations, and
- Parsed values are later embedded into web pages, templates, or DOM without robust output encoding.
The issue is more likely in services that accept user-provided XML or integrate XML feeds from external partners without strict sanitization or entity restrictions.
Exploit preconditions
- Attack surface: Any endpoint, service, or component that accepts XML input and parses it with affected versions of fast-xml-parser.
- Required access: Ability to submit or influence XML content (e.g., HTTP request body, uploaded file, message queue payload, or partner feed).
- Trigger point: Parsing of XML with a DOCTYPE where entity names include dots, enabling redefinition of built-in entities (<, >, &, ", ').
- Why exploitation is possible: The parser treats the dot (.) in DOCTYPE entity names as a regex wildcard during entity replacement instead of a literal character, allowing attacker-controlled entities to shadow standard ones. When the resulting content is rendered, attacker-controlled HTML or script can execute.
Why this happens
The underlying bug class maps to CWE-185: Incorrect Regular Expression combined with CWE-79: Improper Neutralization of Input During Web Page Generation (XSS).
Entity replacement logic in fast-xml-parser uses regular expressions that interpret dots in entity names as wildcards, causing overly broad matching and allowing malicious redefinitions of built-in XML entities. This breaks the assumption that <, >, &, ", and ' will always be safe-encoded. When these compromised entities are expanded and the resulting data is embedded into HTML or JavaScript contexts, the framework no longer neutralizes attacker-controlled markup or scripts, enabling XSS.
Potential impact
- Attackers can inject arbitrary HTML or JavaScript into pages rendered using parsed XML data.
- User sessions may be hijacked via theft of cookies or authentication tokens.
- Sensitive data displayed in the browser can be exfiltrated through malicious scripts.
- UI content, forms, or links can be altered to conduct phishing or drive-by attacks.
- Browser-side security controls relying on DOM integrity can be bypassed.
General mitigation guidance
Effective mitigation typically centers on tightening entity handling and strengthening output encoding patterns:
- Avoid trusting XML-defined entities when processing untrusted or mixed-trust XML; disable or ignore external and custom entity declarations where feasible.
- Ensure that all data derived from XML parsing is contextually encoded (HTML, attribute, JavaScript, URL) before insertion into any web page or DOM.
- Apply strict validation on XML inputs, rejecting payloads that declare unexpected DOCTYPEs or entities, especially those shadowing built-in ones.
- Treat server-side XML parser configuration as a security boundary: prefer safe defaults that do not allow entity expansion or DTD features unless explicitly required.
- Use least-privilege design for web views: minimize the amount of dynamic content inserted directly into script-sensitive contexts (e.g., inline event handlers or
<script>blocks).
How teams detect issues like this
High-level detection approaches include:
- Static analysis: Scan codebases for use of fast-xml-parser where parsed results are later concatenated into HTML strings, templates, or client-side scripts without robust encoding or sanitization.
- Configuration review: Examine XML parsing configurations for support of custom DOCTYPEs and entity expansion, flagging implementations that allow untrusted DTD content.
- Code review signals: Look for patterns where XML-sourced values are passed straight into templating engines, framework render functions, or DOM manipulation APIs (e.g.,
innerHTML, unsafe bindings). - Security testing: Incorporate XSS-oriented XML payloads in automated tests and dynamic analysis to identify flows where entity redefinitions alter rendered content.
- Automated tooling (SAST/DAST and dependency analysis platforms) can help detect both insecure usage patterns and presence of vulnerable parser versions, complementing manual review efforts.

