Skip to content

Commit dc18faa

Browse files
schmittjohfabpot
authored andcommitted
prevents injection of malicious doc types
1 parent 6de3b71 commit dc18faa

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Encoder/XmlEncoder.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function encode($data, $format)
5454
*/
5555
public function decode($data, $format)
5656
{
57+
$this->assertNoCustomDocType($data);
5758
$internalErrors = libxml_use_internal_errors(true);
5859
$disableEntities = libxml_disable_entity_loader(true);
5960
libxml_clear_errors();
@@ -290,6 +291,17 @@ private function buildXml($parentNode, $data)
290291
throw new UnexpectedValueException('An unexpected value could not be serialized: '.var_export($data, true));
291292
}
292293

294+
private function assertNoCustomDocType($data)
295+
{
296+
$dom = new \DOMDocument;
297+
$dom->loadXML($data);
298+
foreach ($dom->childNodes as $child) {
299+
if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
300+
throw new \InvalidArgumentException('Document types are not allowed.');
301+
}
302+
}
303+
}
304+
293305
/**
294306
* Selects the type of node to create and appends it to the parent.
295307
*

0 commit comments

Comments
 (0)