Skip to content

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

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

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.

@iliaal

iliaal commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

One of the 2 PRs mentioned in slack

@devnexen

Copy link
Copy Markdown
Member

seems correct but there is a conflict.

…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 force-pushed the fix/dom-removed-id-attr-uaf branch from 0726b06 to b0c38ac Compare November 23, 2026 19:44
@iliaal

iliaal commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Rebased.

@iliaal iliaal closed this in f1ad57d Nov 23, 2026
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.

2 participants