| Conditions | 16 | 
| Paths | 12 | 
| Total Lines | 57 | 
| Code Lines | 36 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 3 | ||
| Bugs | 0 | Features | 0 | 
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php  | 
            ||
| 72 | private static function convert(\DOMNode $node)  | 
            ||
| 73 |     { | 
            ||
| 74 | $output = [];  | 
            ||
| 75 |         switch ($node->nodeType) { | 
            ||
| 76 | case XML_CDATA_SECTION_NODE:  | 
            ||
| 77 | $output['@cdata'] = trim($node->textContent);  | 
            ||
| 78 | break;  | 
            ||
| 79 | case XML_TEXT_NODE:  | 
            ||
| 80 | $output = trim($node->textContent);  | 
            ||
| 81 | break;  | 
            ||
| 82 | case XML_ELEMENT_NODE:  | 
            ||
| 83 | // for each child node, call the covert function recursively  | 
            ||
| 84 |                 for ($i = 0, $m = $node->childNodes->length; $i < $m; ++$i) { | 
            ||
| 85 | $child = $node->childNodes->item($i);  | 
            ||
| 86 | $v = self::convert($child);  | 
            ||
| 87 |                     if (isset($child->tagName)) { | 
            ||
| 88 | $t = $child->tagName;  | 
            ||
| 89 | // assume more nodes of same kind are coming  | 
            ||
| 90 |                         if (!array_key_exists($t, $output)) { | 
            ||
| 91 | $output[$t] = [];  | 
            ||
| 92 | }  | 
            ||
| 93 | $output[$t][] = $v;  | 
            ||
| 94 |                     } else { | 
            ||
| 95 | //check if it is not an empty node  | 
            ||
| 96 |                         if (!empty($v)) { | 
            ||
| 97 | $output = $v;  | 
            ||
| 98 | }  | 
            ||
| 99 | }  | 
            ||
| 100 | }  | 
            ||
| 101 |                 if (is_array($output)) { | 
            ||
| 102 | // if only one node of its kind, assign it directly instead if array($value);  | 
            ||
| 103 |                     foreach ($output as $t => $v) { | 
            ||
| 104 |                         if (is_array($v) && count($v) == 1) { | 
            ||
| 105 | $output[$t] = $v[0];  | 
            ||
| 106 | }  | 
            ||
| 107 | }  | 
            ||
| 108 |                     if (empty($output)) { | 
            ||
| 109 | //for empty nodes  | 
            ||
| 110 | $output = '';  | 
            ||
| 111 | }  | 
            ||
| 112 | }  | 
            ||
| 113 | // loop through the attributes and collect them  | 
            ||
| 114 |                 if ($node->attributes->length) { | 
            ||
| 
                                                                                                    
                         1 ignored issue 
                            –
                            show
                         | 
                |||
| 115 | $a = [];  | 
            ||
| 116 |                     foreach ($node->attributes as $attrName => $attrNode) { | 
            ||
| 117 | $a[$attrName] = $attrNode->value;  | 
            ||
| 118 | }  | 
            ||
| 119 | // if its an leaf node, store the value in @value instead of directly storing it.  | 
            ||
| 120 |                     if (!is_array($output)) { | 
            ||
| 121 | $output = ['@value' => $output];  | 
            ||
| 122 | }  | 
            ||
| 123 | $output['@attributes'] = $a;  | 
            ||
| 124 | }  | 
            ||
| 125 | break;  | 
            ||
| 126 | }  | 
            ||
| 127 | return $output;  | 
            ||
| 128 | }  | 
            ||
| 129 | /**  | 
            ||
| 142 | 
$input_xmlcan contain request data and is used in xml context(s) leading to a potential security vulnerability.8 paths for user data to reach this point
$this->parameters['HTTP_AUTHORIZATION']seems to return tainted data, and$authorizationHeaderis assigned in ServerBag.php on line 62$this->parameters['HTTP_AUTHORIZATION']seems to return tainted data, and$authorizationHeaderis assignedin vendor/ServerBag.php on line 62
in vendor/ServerBag.php on line 77
in vendor/ParameterBag.php on line 45
$inputis assignedin vendor/Request.php on line 335
$this->input()is passed through array_replace_recursive()in vendor/Request.php on line 323
in src/POData/OperationContext/Web/Illuminate/IncomingIlluminateRequest.php on line 132
in src/POData/UriProcessor/RequestDescription.php on line 282
$stringis assignedin src/POData/UriProcessor/RequestDescription.php on line 297
$stringis passed to XML2Array::createArray()in src/POData/UriProcessor/RequestDescription.php on line 302
$_POST,and$_POSTis passed to Request::createRequestFromFactory() in Request.php on line 281$_POST,and$_POSTis passed to Request::createRequestFromFactory()in vendor/Request.php on line 281
$requestis passed to Request::__construct()in vendor/Request.php on line 1945
$requestis passed to Request::initialize()in vendor/Request.php on line 222
$requestis passed to ParameterBag::__construct()in vendor/Request.php on line 240
in vendor/ParameterBag.php on line 35
in vendor/ParameterBag.php on line 45
$inputis assignedin vendor/Request.php on line 335
$this->input()is passed through array_replace_recursive()in vendor/Request.php on line 323
in src/POData/OperationContext/Web/Illuminate/IncomingIlluminateRequest.php on line 132
in src/POData/UriProcessor/RequestDescription.php on line 282
$stringis assignedin src/POData/UriProcessor/RequestDescription.php on line 297
$stringis passed to XML2Array::createArray()in src/POData/UriProcessor/RequestDescription.php on line 302
$_SERVER,and$serveris assigned in Request.php on line 271$_SERVER,and$serveris assignedin vendor/Request.php on line 271
$serveris passed to Request::createRequestFromFactory()in vendor/Request.php on line 281
$serveris passed to Request::__construct()in vendor/Request.php on line 1945
$serveris passed to Request::initialize()in vendor/Request.php on line 222
$serveris passed to ParameterBag::__construct()in vendor/Request.php on line 245
in vendor/ParameterBag.php on line 35
in vendor/ParameterBag.php on line 45
$inputis assignedin vendor/Request.php on line 335
$this->input()is passed through array_replace_recursive()in vendor/Request.php on line 323
in src/POData/OperationContext/Web/Illuminate/IncomingIlluminateRequest.php on line 132
in src/POData/UriProcessor/RequestDescription.php on line 282
$stringis assignedin src/POData/UriProcessor/RequestDescription.php on line 297
$stringis passed to XML2Array::createArray()in src/POData/UriProcessor/RequestDescription.php on line 302
HTTP_CONTENT_LENGTHfrom$_SERVER,and$serveris assigned in Request.php on line 274HTTP_CONTENT_LENGTHfrom$_SERVER,and$serveris assignedin vendor/Request.php on line 274
$serveris passed to Request::createRequestFromFactory()in vendor/Request.php on line 281
$serveris passed to Request::__construct()in vendor/Request.php on line 1945
$serveris passed to Request::initialize()in vendor/Request.php on line 222
$serveris passed to ParameterBag::__construct()in vendor/Request.php on line 245
in vendor/ParameterBag.php on line 35
in vendor/ParameterBag.php on line 45
$inputis assignedin vendor/Request.php on line 335
$this->input()is passed through array_replace_recursive()in vendor/Request.php on line 323
in src/POData/OperationContext/Web/Illuminate/IncomingIlluminateRequest.php on line 132
in src/POData/UriProcessor/RequestDescription.php on line 282
$stringis assignedin src/POData/UriProcessor/RequestDescription.php on line 297
$stringis passed to XML2Array::createArray()in src/POData/UriProcessor/RequestDescription.php on line 302
HTTP_CONTENT_TYPEfrom$_SERVER,and$serveris assigned in Request.php on line 277HTTP_CONTENT_TYPEfrom$_SERVER,and$serveris assignedin vendor/Request.php on line 277
$serveris passed to Request::createRequestFromFactory()in vendor/Request.php on line 281
$serveris passed to Request::__construct()in vendor/Request.php on line 1945
$serveris passed to Request::initialize()in vendor/Request.php on line 222
$serveris passed to ParameterBag::__construct()in vendor/Request.php on line 245
in vendor/ParameterBag.php on line 35
in vendor/ParameterBag.php on line 45
$inputis assignedin vendor/Request.php on line 335
$this->input()is passed through array_replace_recursive()in vendor/Request.php on line 323
in src/POData/OperationContext/Web/Illuminate/IncomingIlluminateRequest.php on line 132
in src/POData/UriProcessor/RequestDescription.php on line 282
$stringis assignedin src/POData/UriProcessor/RequestDescription.php on line 297
$stringis passed to XML2Array::createArray()in src/POData/UriProcessor/RequestDescription.php on line 302
$server['HTTP_HOST']seems to return tainted data, and$serveris assigned in Request.php on line 347$server['HTTP_HOST']seems to return tainted data, and$serveris assignedin vendor/Request.php on line 347
$serveris assignedin vendor/Request.php on line 395
$serveris assignedin vendor/Request.php on line 396
$serveris passed to Request::createRequestFromFactory()in vendor/Request.php on line 398
$serveris passed to Request::__construct()in vendor/Request.php on line 1945
$serveris passed to Request::initialize()in vendor/Request.php on line 222
$serveris passed to ParameterBag::__construct()in vendor/Request.php on line 245
in vendor/ParameterBag.php on line 35
in vendor/ParameterBag.php on line 45
$inputis assignedin vendor/Request.php on line 335
$this->input()is passed through array_replace_recursive()in vendor/Request.php on line 323
in src/POData/OperationContext/Web/Illuminate/IncomingIlluminateRequest.php on line 132
in src/POData/UriProcessor/RequestDescription.php on line 282
$stringis assignedin src/POData/UriProcessor/RequestDescription.php on line 297
$stringis passed to XML2Array::createArray()in src/POData/UriProcessor/RequestDescription.php on line 302
$this->parameters['PHP_AUTH_USER']seems to return tainted data, and$headersis assigned in ServerBag.php on line 43$this->parameters['PHP_AUTH_USER']seems to return tainted data, and$headersis assignedin vendor/ServerBag.php on line 43
$headersis assignedin vendor/ServerBag.php on line 44
$this->server->getHeaders()is passed to HeaderBag::__construct()in vendor/Request.php on line 246
$valuesis assignedin vendor/HeaderBag.php on line 31
$valuesis passed to HeaderBag::set()in vendor/HeaderBag.php on line 32
(array) $valuesis passed through array_values(), and$valuesis assignedin vendor/HeaderBag.php on line 142
in vendor/HeaderBag.php on line 145
in vendor/HeaderBag.php on line 125
$requestUriis assignedin vendor/Request.php on line 1715
$requestUriis passed to ParameterBag::set()in vendor/Request.php on line 1746
in vendor/ParameterBag.php on line 99
in vendor/ParameterBag.php on line 45
$inputis assignedin vendor/Request.php on line 335
$this->input()is passed through array_replace_recursive()in vendor/Request.php on line 323
in src/POData/OperationContext/Web/Illuminate/IncomingIlluminateRequest.php on line 132
in src/POData/UriProcessor/RequestDescription.php on line 282
$stringis assignedin src/POData/UriProcessor/RequestDescription.php on line 297
$stringis passed to XML2Array::createArray()in src/POData/UriProcessor/RequestDescription.php on line 302
$this->parameters['PHP_AUTH_PW']seems to return tainted data, and$headersis assigned in ServerBag.php on line 44$this->parameters['PHP_AUTH_PW']seems to return tainted data, and$headersis assignedin vendor/ServerBag.php on line 44
$this->server->getHeaders()is passed to HeaderBag::__construct()in vendor/Request.php on line 246
$valuesis assignedin vendor/HeaderBag.php on line 31
$valuesis passed to HeaderBag::set()in vendor/HeaderBag.php on line 32
(array) $valuesis passed through array_values(), and$valuesis assignedin vendor/HeaderBag.php on line 142
in vendor/HeaderBag.php on line 145
in vendor/HeaderBag.php on line 125
$requestUriis assignedin vendor/Request.php on line 1715
$requestUriis passed to ParameterBag::set()in vendor/Request.php on line 1746
in vendor/ParameterBag.php on line 99
in vendor/ParameterBag.php on line 45
$inputis assignedin vendor/Request.php on line 335
$this->input()is passed through array_replace_recursive()in vendor/Request.php on line 323
in src/POData/OperationContext/Web/Illuminate/IncomingIlluminateRequest.php on line 132
in src/POData/UriProcessor/RequestDescription.php on line 282
$stringis assignedin src/POData/UriProcessor/RequestDescription.php on line 297
$stringis passed to XML2Array::createArray()in src/POData/UriProcessor/RequestDescription.php on line 302
Preventing XML Injection Attacks
If you pass user-data to XML parsing functions like
simplexml_load_string(), this can be abused to inject external entities to gain access to the contents of any file in your filesystem, or it can be used to freeze your PHP process with an entity expansion attack.In order to prevent that, make sure to disable external entity loading and disallow custom doc-types:
libxml_disable_entity_loader(true); $dom = new DOMDocument; $dom->loadXML($taintedXml); foreach ($dom->childNodes as $child) { if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) { throw new InvalidArgumentException( 'Invalid XML: Detected use of illegal DOCTYPE' ); } } // It is now safe to use $taintedXml $xml = simplexml_load_string($taintedXml);General Strategies to prevent injection
In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:
if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) { throw new \InvalidArgumentException('This input is not allowed.'); }For numeric data, we recommend to explicitly cast the data: