Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
Security Class Reference

Public Member Functions

 scan ($xmlContent)
 

Detailed Description

Class Security

Definition at line 13 of file Security.php.

Member Function Documentation

◆ scan()

scan (   $xmlContent)

Security check loaded XML document

Parameters
string$xmlContent
Returns
bool

@SuppressWarnings(PHPMD.UnusedLocalVariable)

If running with PHP-FPM we perform an heuristic scan We cannot use libxml_disable_entity_loader because of this bug

See also
https://bugs.php.net/bug.php?id=64938

Load XML with network access disabled (LIBXML_NONET) error disabled with @ for PHP-FPM scenario

Definition at line 44 of file Security.php.

45  {
51  if ($this->isPhpFpm()) {
52  return $this->heuristicScan($xmlContent);
53  }
54 
55  $document = new DOMDocument();
56 
57  $loadEntities = libxml_disable_entity_loader(true);
58  $useInternalXmlErrors = libxml_use_internal_errors(true);
59 
64  set_error_handler(
65  function ($errno, $errstr) {
66  if (substr_count($errstr, 'DOMDocument::loadXML()') > 0) {
67  return true;
68  }
69  return false;
70  },
71  E_WARNING
72  );
73 
74  $result = (bool)$document->loadXML($xmlContent, LIBXML_NONET);
75  restore_error_handler();
76  // Entity load to previous setting
77  libxml_disable_entity_loader($loadEntities);
78  libxml_use_internal_errors($useInternalXmlErrors);
79 
80  if (!$result) {
81  return false;
82  }
83 
84  foreach ($document->childNodes as $child) {
85  if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
86  if ($child->entities->length > 0) {
87  return false;
88  }
89  }
90  }
91 
92  return true;
93  }

The documentation for this class was generated from the following file: