Issues (1)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/XmlIterator.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace XmlIterator;
4
5
use Iterator;
6
7
class XmlIterator implements Iterator
8
{
9
    /**
10
     * @var int
11
     */
12
    protected $position = 0;
13
14
    /**
15
     * @var string
16
     */
17
    protected $xmlFileUri;
18
19
    /**
20
     * @var string The name of the tag that delimits/separates each iterated element/row
21
     */
22
    protected $delimiterTagName;
23
24
    /**
25
     * @var array
26
     */
27
    protected $options = array(
28
        /**
29
         * @var string Encoding of source file
30
         */
31
        "encoding"      => null,
32
33
        /**
34
         * @var null See __construct() for the default
35
         */
36
        "readerOptions" => null,
37
38
        /**
39
         * @var bool Activate UTF8 filter agains invalid (e.g. "out of allowed range") characters?
40
         *
41
         * Disable for performance gain if you know that the xml is clean of bad characters.
42
         */
43
        "utf8Filter"    => true,
44
45
        /**
46
         * @var bool Return current element as an array for ease of use?
47
         *
48
         * Disable for performance gain. Bu you need to do (string)$current->something for each sub-element.
49
         */
50
        "asArray"       => true,
51
    );
52
53
    /**
54
     * @var \XMLReader
55
     */
56
    protected $reader;
57
58
    /**
59
     * @var \DOMDocument
60
     */
61
    protected $doc;
62
63
    /**
64
     * @param string $xmlFileUri
65
     * @param string $delimiterTagName
66
     * @param array $options
67
     *
68
     * @throws \Exception
69
     */
70 2
    public function __construct(
71
        $xmlFileUri,
72
        $delimiterTagName,
73
        $options = array()
74
    ) {
75 2
        $this->xmlFileUri = $xmlFileUri;
76 2
        $this->delimiterTagName = $delimiterTagName;
77
78
        // work-around for non-scalar default value
79 2
        $this->options["readerOptions"] = \XMLReader::VALIDATE | \XMLReader::SUBST_ENTITIES | LIBXML_NOCDATA;
80 2
        $this->options = array_replace_recursive($this->options, $options);
81
82 2
        $this->reader = new \XMLReader();
83 2
        $this->doc = new \DOMDocument();
84
85 2
        if ($this->options["utf8Filter"]) {
86 2
            require_once "Utf8Filter.php";
87 2
            stream_filter_register('xmlutf8', __NAMESPACE__ . "\\Utf8Filter");
88 1
        }
89 2
    }
90
91
    /**
92
     * Return the current element, <b>FALSE</b> on error
93
     * @link http://php.net/manual/en/iterator.current.php
94
     * @link http://stackoverflow.com/a/1835324/372654
95
     * @return false|array|\SimpleXMLElement
96
     */
97 2
    public function current()
98
    {
99 2
        $node = $this->reader->expand();
100 2
        if ($node === false) {
101
            return false;
102
        }
103 2
        $node = $this->doc->importNode($node, true);
104 2
        if ($node === false) {
105
            return false;
106
        }
107 2
        $current = simplexml_import_dom($node);
108 2
        if ($current === false) {
109
            return false;
110
        }
111
112 2
        if ($this->options["asArray"]) {
113 2
            return json_decode(json_encode($current), true);
114
        } else {
115
            return $current;
116
        }
117
    }
118
119
    /**
120
     * Move forward to next element
121
     * @link http://php.net/manual/en/iterator.next.php
122
     * @return void Any returned value is ignored.
123
     */
124 2
    public function next()
125
    {
126 2
        if ($this->reader->next($this->delimiterTagName)) {
127 2
            ++$this->position;
128 1
        }
129 2
    }
130
131
    /**
132
     * Return the key of the current element
133
     * @link http://php.net/manual/en/iterator.key.php
134
     * @return int scalar on success, or null on failure.
135
     */
136
    public function key()
137
    {
138
        return $this->position;
139
    }
140
141
    /**
142
     * Checks if current position is valid
143
     * @link http://php.net/manual/en/iterator.valid.php
144
     * @return boolean The return value will be casted to boolean and then evaluated.
145
     *       Returns true on success or false on failure.
146
     */
147 2
    public function valid()
148
    {
149 2
        return $this->reader->name === $this->delimiterTagName;
150
    }
151
152
    /**
153
     * Rewind the Iterator to the first element
154
     * @link http://php.net/manual/en/iterator.rewind.php
155
     * @throws \Exception
156
     * @return void Any returned value is ignored.
157
     */
158 2
    public function rewind()
159
    {
160 2
        $uri = $this->xmlFileUri;
161
162 2
        if ($this->options["utf8Filter"]) {
163 2
            $uri = "php://filter/read=xmlutf8/resource=" . $uri;
164 1
        }
165
166 2
        if (!$this->reader
167 2
            ->open(
168 1
                $uri,
169 2
                $this->options["encoding"],
170 2
                $this->options["readerOptions"]
171 1
            )
172 1
        ) {
173
            throw new \Exception("$this->xmlFileUri cannot be opened");
174
        }
175
176
        // move to the first element
177 2
        while ($this->reader->read() && $this->reader->name !== $this->delimiterTagName) {
0 ignored issues
show
This while loop is empty and can be removed.

This check looks for while loops that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

Consider removing the loop.

Loading history...
178
            // intentionally empty
179 1
        }
180 2
    }
181
}
182