GitHub Security Advisory: GHSA-x6wf-f3px-wcqx
Package: xmldom (NPM)
Severity: HIGH (CVSS 0.0)
CWE: CWE-91: XML Injection (aka Blind XPath Injection)
Vulnerable versions: <= 0.6.0
Patched in: unpatched

Summary: xmldom has XML node injection through unvalidated processing instruction serialization

Details:
## Summary

The package allows attacker-controlled processing instruction data to be serialized into XML without validating or neutralizing the PI-closing sequence `?>`. As a result, an attacker can terminate the processing instruction early and inject arbitrary XML nodes into the serialized output.

---

## Details

The issue is in the DOM construction and serialization flow for processing instruction nodes.

When `createProcessingInstruction(target, data)` is called, the supplied `data` string is stored directly on the node without validation. Later, when the document is serialized, the serializer writes PI nodes by concatenating `<?`, the target, a space, `node.data`, and `?>` directly.

That behavior is unsafe because processing instructions are a syntax-sensitive context. The closing delimiter `?>` terminates the PI. If attacker-controlled input contains `?>`, the serializer does not preserve it as literal PI content. Instead, it emits output where the remainder of the payload is treated as live XML markup.

The same class of vulnerability was previously addressed for CDATA sections (GHSA-wh4c-j3r5-mjhp / CVE-2026-34601), where `]]>` in CDATA data was handled by splitting. The serializer applies no equivalent protection to processing instruction data.

---

## Affected code

**`lib/dom.js` — `createProcessingInstruction` (lines 2240–2246):**

```js
createProcessingInstruction: function (target, data) {
    var node = new ProcessingInstruction(PDC);
    node.ownerDocument = this;
    node.childNodes = new NodeList();
    node.nodeName = node.target = target;
    node.nodeValue = node.data = data;
    return node;
},
```

No validation is performed on `data`. Any string including `?>` is stored as-is.

**`lib/dom.js` — serializer PI case (line 2966):**

```js
case PROCESSING_INSTRUCTION_NODE:
    return buf.push('<?', node.target, ' ', node.data, '?>');
```

`node.data` is emitted verbatim. If it contains `?>`, that sequence terminates the PI in the output
stream and the remainder appears as active XML markup.

**Contrast — CDATA (line 2945, patched):**

```js
case CDATA_SECTION_NODE:
    return buf.push(g.CDATA_START, node.data.replace(/]]>/g, ']]]]><![CDATA[>'), g.CDATA_END);
```

---

## PoC

### Minimal (from @tlsbollei report, 2026-04-01)

```js
const { DOMImplementation, XMLSerializer } = require('@xmldom/xmldom');

const doc = new DOMImplementation().createDocument(null, 'r', null);
doc.documentElement.appendChild(
    doc.createProcessingInstruction('a', '?><z/><?q ')
);
console.log(new XMLSerializer().serializeToString(doc));
// <r><?a ?><z/><?q ?></r>
//          ^^^^ injected <z/> element is active markup
```

### With re-parse verification (from @tlsbollei report)

```js
const assert = require('assert');
const { DOMParser, XMLSerializer } = require('@xmldom/xmldom');

const doc = new DOMParser().parseFromString('<r/>', 'application/xml');
doc.documentElement.appendChild(doc.createProcessingInstruction('a', '?><z/><?q '));
const xml