21 private function heuristicScan($xmlContent)
23 return strpos($xmlContent,
'<!ENTITY') ===
false;
31 private function isPhpFpm()
33 return substr(php_sapi_name(), 0, 3) ===
'fpm';
44 public function scan($xmlContent)
51 if ($this->isPhpFpm()) {
52 return $this->heuristicScan($xmlContent);
55 $document =
new DOMDocument();
57 $loadEntities = libxml_disable_entity_loader(
true);
58 $useInternalXmlErrors = libxml_use_internal_errors(
true);
65 function ($errno, $errstr) {
66 if (substr_count($errstr,
'DOMDocument::loadXML()') > 0) {
74 $result = (bool)$document->loadXML($xmlContent, LIBXML_NONET);
75 restore_error_handler();
77 libxml_disable_entity_loader($loadEntities);
78 libxml_use_internal_errors($useInternalXmlErrors);
84 foreach ($document->childNodes as $child) {
85 if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
86 if ($child->entities->length > 0) {