Issues (32)

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/Mapping/Loader/XmlClassMetadataLoader.php (1 issue)

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
/*
4
 * This file is part of the Ivory Serializer package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\Serializer\Mapping\Loader;
13
14
/**
15
 * @author GeLo <[email protected]>
16
 */
17
class XmlClassMetadataLoader extends AbstractFileClassMetadataLoader
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22 388
    protected function loadFile($file)
23
    {
24 388
        $data = [];
25 388
        $xml = simplexml_import_dom($this->loadDocument($file));
26
27 360
        foreach ($xml->class as $class) {
28 360
            $data[(string) $class['name']] = $this->loadClass($class);
29
        }
30
31 360
        return $data;
32
    }
33
34
    /**
35
     * @param \SimpleXMLElement $class
36
     *
37
     * @return mixed[]
38
     */
39 360
    private function loadClass(\SimpleXMLElement $class)
40
    {
41 360
        $definition = [];
42
43 360
        if (isset($class['exclusion-policy'])) {
44 248
            $definition['exclusion_policy'] = (string) $class['exclusion-policy'];
45
        }
46
47 360
        if (isset($class['order'])) {
48 264
            $definition['order'] = (string) $class['order'];
49
        }
50
51 360
        if (isset($class['readable'])) {
52 240
            $definition['readable'] = (string) $class['readable'] === 'true';
53
        }
54
55 360
        if (isset($class['writable'])) {
56 240
            $definition['writable'] = (string) $class['writable'] === 'true';
57
        }
58
59 360
        if (isset($class['xml-root'])) {
60 248
            $definition['xml_root'] = (string) $class['xml-root'];
61
        }
62
63 360
        $properties = [];
64
65 360
        foreach ($class->property as $property) {
66 352
            $properties[(string) $property['name']] = $this->loadProperty($property);
67
        }
68
69 360
        $definition['properties'] = $properties;
70
71 360
        return $definition;
72
    }
73
74
    /**
75
     * @param \SimpleXMLElement $element
76
     *
77
     * @return mixed[]
78
     */
79 352
    private function loadProperty(\SimpleXMLElement $element)
80
    {
81 352
        $property = [];
82
83 352
        if (isset($element['alias'])) {
84 248
            $property['alias'] = (string) $element['alias'];
85
        }
86
87 352
        if (isset($element['type'])) {
88 248
            $property['type'] = (string) $element['type'];
89
        }
90
91 352
        if (isset($element['exclude'])) {
92 248
            $property['exclude'] = (string) $element['exclude'] === 'true';
93
        }
94
95 352
        if (isset($element['expose'])) {
96 240
            $property['expose'] = (string) $element['expose'] === 'true';
97
        }
98
99 352
        if (isset($element['accessor'])) {
100 248
            $property['accessor'] = (string) $element['accessor'];
101
        }
102
103 352
        if (isset($element['readable'])) {
104 240
            $property['readable'] = (string) $element['readable'] === 'true';
105
        }
106
107 352
        if (isset($element['writable'])) {
108 240
            $property['writable'] = (string) $element['writable'] === 'true';
109
        }
110
111 352
        if (isset($element['mutator'])) {
112 248
            $property['mutator'] = (string) $element['mutator'];
113
        }
114
115 352
        if (isset($element['since'])) {
116 248
            $property['since'] = (string) $element['since'];
117
        }
118
119 352
        if (isset($element['until'])) {
120 248
            $property['until'] = (string) $element['until'];
121
        }
122
123 352
        if (isset($element['max-depth'])) {
124 240
            $property['max_depth'] = (int) $element['max-depth'];
125
        }
126
127 352
        foreach ($element->group as $group) {
128 248
            $property['groups'][] = (string) $group;
129
        }
130
131 352
        if (isset($element['xml-attribute'])) {
132 240
            $property['xml_attribute'] = (string) $element['xml-attribute'] === 'true';
133
        }
134
135 352
        if (isset($element['xml-value'])) {
136 240
            $property['xml_value'] = (string) $element['xml-value'] === 'true';
137
        }
138
139 352
        if (isset($element['xml-inline'])) {
140 240
            $property['xml_inline'] = (string) $element['xml-inline'] === 'true';
141
        }
142
143 352
        if (isset($element['xml-entry'])) {
144 248
            $property['xml_entry'] = (string) $element['xml-entry'];
145
        }
146
147 352
        if (isset($element['xml-entry-attribute'])) {
148 248
            $property['xml_entry_attribute'] = (string) $element['xml-entry-attribute'];
149
        }
150
151 352
        if (isset($element['xml-key-as-attribute'])) {
152 240
            $property['xml_key_as_attribute'] = (string) $element['xml-key-as-attribute'] === 'true';
153
        }
154
155 352
        if (isset($element['xml-key-as-node'])) {
156 240
            $property['xml_key_as_node'] = (string) $element['xml-key-as-node'] === 'true';
157
        }
158
159 352
        return $property;
160
    }
161
162
    /**
163
     * @param string $file
164
     *
165
     * @return \DOMDocument
166
     */
167 388
    private function loadDocument($file)
168
    {
169 388
        $data = trim(@file_get_contents($file));
170
171 388
        if (empty($data)) {
172 4
            throw new \InvalidArgumentException(sprintf('The XML mapping file "%s" is not valid.', $file));
173
        }
174
175 384
        $internalErrors = libxml_use_internal_errors();
176 384
        $disableEntities = libxml_disable_entity_loader();
177
178 384
        $this->setLibXmlState(true, true);
179
180 384
        $document = new \DOMDocument();
181 384
        $document->validateOnParse = true;
182
183 384
        if (!@$document->loadXML($data, LIBXML_NONET | LIBXML_COMPACT)) {
184 8
            throw $this->createException($file, $internalErrors, $disableEntities);
185
        }
186
187 376
        $document->normalizeDocument();
188
189 376
        if (!@$document->schemaValidateSource(file_get_contents(__DIR__.'/../Resource/mapping.xsd'))) {
190 16
            throw $this->createException($file, $internalErrors, $disableEntities);
191
        }
192
193 360
        foreach ($document->childNodes as $child) {
194 360
            if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
195 180
                throw new \InvalidArgumentException('The document type is not allowed.');
196
            }
197
        }
198
199 360
        $this->setLibXmlState($internalErrors, $disableEntities);
200
201 360
        return $document;
202
    }
203
204
    /**
205
     * @param string $file
206
     * @param bool   $internalErrors
207
     * @param bool   $disableEntities
208
     *
209
     * @return \InvalidArgumentException
210
     */
211 24
    private function createException($file, $internalErrors, $disableEntities)
212
    {
213 24
        $errors = [];
214
215 24 View Code Duplication
        foreach (libxml_get_errors() as $error) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
216 24
            $errors[] = sprintf('[%s %s] %s (in %s - line %d, column %d)',
217 24
                $error->level === LIBXML_ERR_WARNING ? 'WARNING' : 'ERROR',
218 24
                $error->code,
219 24
                trim($error->message),
220 18
                $file,
221 24
                $error->line,
222 24
                $error->column
223
            );
224
        }
225
226 24
        $this->setLibXmlState($internalErrors, $disableEntities);
227
228 24
        return new \InvalidArgumentException(implode(PHP_EOL, $errors));
229
    }
230
231
    /**
232
     * @param bool $internalErrors
233
     * @param bool $disableEntities
234
     */
235 384
    private function setLibXmlState($internalErrors, $disableEntities)
236
    {
237 384
        libxml_use_internal_errors($internalErrors);
238 384
        libxml_disable_entity_loader($disableEntities);
239 384
        libxml_clear_errors();
240 384
    }
241
}
242