Описание
Double free during DOM XML serialization
Summary
PHP's modern DOM XML serializer can incorrectly share ownership of a generated namespace prefix between an element and its descendant. An application that calls saveXml() on attacker-controlled XML or HTML can consequently use and free the same allocation more than once, which can crash the PHP process.
Details
Dom\XMLDocument and Dom\HTMLDocument maintain a namespace-prefix map while serializing a document as XML. The serializer can generate a prefix for an attribute whose namespace has no usable prefix. Descendants initially share the ancestor's map and use copy-on-write when adding another candidate prefix for an existing namespace URI.
The vulnerable copy-on-write path duplicates the candidate list but leaves the copied pointers marked as owned. Destroying the descendant's map therefore frees a generated prefix that remains referenced by the ancestor. A later sibling can access that freed value, and destroying the ancestor's map frees the same allocation again. The fix marks generated-prefix pointers copied into descendant lists as borrowed.
Valid input can establish this state by combining namespaced attributes, nested namespace declarations and a later sibling. The input does not need to be malformed. The HTML path requires only a crafted document followed by Dom\HTMLDocument::saveXml(). For Dom\XMLDocument, the same state can arise when ordinary application code adds a namespaced attribute and the supplied document declares another prefix for that namespace.
Impact
A remote attack requires an application to parse attacker-controlled XML or HTML using the modern DOM API and then serialize it with saveXml(). Applications that do not XML-serialize untrusted documents are not affected by that attack path.
The demonstrated impact is memory corruption and denial of service through a PHP process crash. Corrupting ZendMM's free list may allow later allocations in the same request to alias, but turning that into type confusion or code execution requires application-specific allocation control and has not been demonstrated through realistic application code. No confidentiality or integrity impact has been established.
Repeated requests can terminate PHP workers and reduce or exhaust an application's worker pool.
Affected versions
The affected code was introduced in PHP 8.4.0 together with the Dom\XMLDocument and Dom\HTMLDocument classes and their XML serializer. The legacy DOMDocument class does not use this serializer. PHP 8.3 and earlier are not affected.
Mitigation
Upgrade to the fixed release for your PHP branch when it becomes available. Until then, avoid calling saveXml() on attacker-controlled Dom\XMLDocument or Dom\HTMLDocument instances. For HTML documents where XML output is not required, saveHtml() avoids the affected XML serializer. Process isolation and worker restart limits can contain individual crashes but do not remove the vulnerable behavior.
Пакеты
php
>= 8.4.0, < 8.4.28
8.4.28
php
>= 8.5.0, < 8.5.13
8.5.13
Связанные уязвимости
PHP's modern DOM XML serializer can incorrectly share ownership of a generated namespace prefix between an element and its descendant. An application that calls saveXml() on attacker-controlled XML or HTML can consequently use and free the same allocation more than once, which can crash the PHP process.
Double free during DOM XML serialization. The XML serializer of Dom\XMLDocument and Dom\HTMLDocument can share ownership of a generated namespace prefix between the namespace-prefix maps of an element and a descendant, so the prefix is used after being freed and then freed a second time. The document does not need to be malformed. An application that parses attacker-controlled XML or HTML with these classes and serializes it with saveXml() can be crashed, and repeated requests can cause denial of service. Code execution has not been demonstrated. This issue affects PHP versions 8.4.* before 8.4.28 and 8.5.* before 8.5.13.
Double free during DOM XML serialization. The XML serializer of Dom\XMLDocument and Dom\HTMLDocument can share ownership of a generated namespace prefix between the namespace-prefix maps of an element and a descendant, so the prefix is used after being freed and then freed a second time. The document does not need to be malformed. An application that parses attacker-controlled XML or HTML with these classes and serializes it with saveXml() can be crashed, and repeated requests can cause denial of service. Code execution has not been demonstrated. This issue affects PHP versions 8.4.* before 8.4.28 and 8.5.* before 8.5.13.
Double free during DOM XML serialization. The XML serializer of Dom\X ...