[php-src] Issue #22624: Use-after-free via DOMNameSpaceNode after DOMDocument::xinclude()

[email protected] (alexandre-daubois) Tue, 7 Jul 2026 10:11:15 +0000
Newsgroups php.bugs
Message-ID <[email protected]>
Issue: https://github.com/php/php-src/issues/22624
Author: alexandre-daubois

### Description

Create `included.xml`:

```xml
<?xml version="1.0"?><included/>
```

Then run:

```php
<?php
$doc = new DOMDocument();
$doc->loadXML('<?xml version="1.0"?>
<root xmlns:xi="http://www.w3.org/2001/XInclude">
  <xi:include href="included.xml" xmlns:local="urn:test"/>
</root>');

$xpath = new DOMXPath($doc);
$xpath->registerNamespace('xi', 'http://www.w3.org/2001/XInclude');
$xi = $xpath->query('//xi:include')->item(0);
$ns = $xpath->query('namespace::local', $xi)->item(0); // DOMNameSpaceNode

$doc->xinclude(); // frees the xi:include element

var_dump($ns->parentNode); // heap-use-after-free
```

`dom_xinclude_strip_references()` invalidates element and attribute wrappers (it walks `children` and `properties`), but `DOMNameSpaceNode` wraps a synthetic node held only by userland, which that walk never reaches, so it is never invalidated. 

This is the same class as the element fix for GH-17847 and the later attribute fix, applied to the namespace-node case that neither covered.

Originally reported by @ExPatch-LLC.

### PHP Version

```plain
-
```

### Operating System

_No response_