Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into form/select-date
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,17 @@ public function queryXpath($xpathQuery, $query = null)
} else {
$domDoc = new DOMDocument('1.0', $encoding);
}

$type = $this->getDocumentType();
switch ($type) {
case self::DOC_XML:
$success = $domDoc->loadXML($document);
foreach ($domDoc->childNodes as $child) {
if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
throw new Exception\RuntimeException(
'Invalid XML: Detected use of illegal DOCTYPE'
);
}
}
break;
case self::DOC_HTML:
case self::DOC_XHTML:
Expand Down
14 changes: 14 additions & 0 deletions test/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,18 @@ public function testXhtmlDocumentWithXmlAndDoctypeDeclaration()
$this->query->setDocument($xhtmlWithXmlDecl, 'utf-8');
$this->assertEquals(1, $this->query->execute('//p')->count());
}

public function testLoadingXmlContainingDoctypeShouldFailToPreventXxeAndXeeAttacks()
{
$xml = <<<XML
<?xml version="1.0"?>
<!DOCTYPE results [<!ENTITY harmless "completely harmless">]>
<results>
<result>This result is &harmless;</result>
</results>
XML;
$this->query->setDocumentXml($xml);
$this->setExpectedException("\Zend\Dom\Exception\RuntimeException");
$this->query->queryXpath('/');
}
}

0 comments on commit c09dfeb

Please sign in to comment.