Skip to content

Commit 0943a06

Browse files
Seldaekfabpot
authored andcommitted
[Serializer] Fix XML decoding attack vector through external entities
1 parent d89f7d2 commit 0943a06

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Encoder/XmlEncoder.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,18 @@ public function encode($data, $format)
5454
*/
5555
public function decode($data, $format)
5656
{
57+
$internalErrors = libxml_use_internal_errors(true);
58+
$disableEntities = libxml_disable_entity_loader(true);
59+
libxml_clear_errors();
60+
5761
$xml = simplexml_load_string($data);
62+
libxml_use_internal_errors($internalErrors);
63+
libxml_disable_entity_loader($disableEntities);
64+
65+
if ($error = libxml_get_last_error()) {
66+
throw new UnexpectedValueException($error->message);
67+
}
68+
5869
if (!$xml->count()) {
5970
if (!$xml->attributes()) {
6071
return (string) $xml;

0 commit comments

Comments
 (0)