Skip to content

ext/dom: Fix use-after-free in getElementById() after removing an ID attribute - #25351

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/dom-removed-id-attr-uaf
Open

iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/dom-removed-id-attr-uaf

Conversation

@iliaal

@iliaal iliaal commented Nov 9, 2026

Copy link
Copy Markdown
Member

Freeing a detached ID attribute, for example after removeAttributeNode() and unset(), left the document's ID table pointing at it, so a later getElementById() for that ID read freed memory. php_libxml_node_free_resource() freed the attribute's children before xmlFreeProp() called xmlRemoveID(), which needs those children to find the entry. Remove the ID first, as php_libxml_node_free_list() already does.

…attribute

php_libxml_node_free_resource() freed a detached ID attribute's children
before xmlFreeProp() called xmlRemoveID(), which reads the ID value from
those children, so the entry was not found and the document's ID table kept
pointing at the freed attribute. Remove the ID before freeing the children,
as php_libxml_node_free_list() already does. This also covers
removeAttribute() while a reference to the attribute node is still held.
@iliaal

iliaal commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

One of the 2 PRs mentioned in slack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant