Issues (13)

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/PrestashopWebService.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
namespace DansMaCulotte\PrestashopWebService;
4
5
use SimpleXMLElement;
6
7
class PrestashopWebService extends PrestashopWebServiceLibrary
8
{
9
10
    /**
11
     * Retrieve the resource schema
12
     *
13
     * @param $resource
14
     * @param string $schema
15
     * @return SimpleXMLElement
16
     * @throws Exceptions\PrestashopWebServiceException
17
     */
18
    public function getSchema($resource, $schema = 'blank')
19
    {
20
        return $this->get(['resource' => $resource . "?schema=$schema"]);
21
    }
22
23
    /**
24
     * Fill the provided schema with an associative array data, also remove the useless XML nodes if
25
     * the corresponding flag is true
26
     *
27
     * @param SimpleXMLElement $xmlSchema
28
     * @param array $data
29
     * @param bool $removeUselessNodes set true if you want to remove nodes that are not present in the data array
30
     * @param array $removeSpecificNodes If $removeUselessNodes is false you may add here the first level nodes that
31
     *                                   you want to remove
32
     * @return SimpleXMLElement
33
     */
34
    public function fillSchema(
35
        SimpleXMLElement $xmlSchema,
36
        $data,
37
        $removeUselessNodes = true,
38
        $removeSpecificNodes = []
39
    ) {
40
        $resource = $xmlSchema->children()->children();
41
        foreach ($data as $key => $value) {
42
            $this->processNode($resource, $key, $value);
43
        }
44
        if ($removeUselessNodes) {
45
            $this->checkForUselessNodes($resource, $data);
46
        } else {
47
            $this->removeSpecificNodes($resource, $removeSpecificNodes);
48
        }
49
        return $xmlSchema;
50
    }
51
52
    /**
53
     * @param string|array $data
54
     * @param $languageId
55
     * @return string
56
     */
57
    private function getLanguageValue($data, $languageId)
58
    {
59
        if (is_string($data)) {
60
            return $data;
61
        }
62
63
        if (array_key_exists($languageId, $data)) {
64
            return $data[$languageId];
65
        } else {
66
            return $data[1];
67
        }
68
    }
69
70
    /**
71
     * @param $node
72
     * @param $data
73
     */
74
    private function fillLanguageNode($node, $data)
75
    {
76
        for ($i = 0; $i < count($node->language); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
77
            $node->language[$i] = $this->getLanguageValue($data, (int) $node->language[$i]['id']->__toString());
78
        }
79
    }
80
81
    /**
82
     * @param SimpleXMLElement $node
83
     * @param $dataKey
84
     * @param $dataValue
85
     */
86
    private function processNode(SimpleXMLElement $node, $dataKey, $dataValue)
87
    {
88
        if (is_int($dataKey)) {
89
            if ($dataKey === 0) {
90
                $this->emptyNode($node);
91
            }
92
            $this->createNode($node, $dataValue);
93
        } elseif (property_exists($node->$dataKey, 'language')) {
94
            $this->fillLanguageNode($node->$dataKey, $dataValue);
95
        } elseif (is_array($dataValue)) {
96
            foreach ($dataValue as $key => $value) {
97
                $this->processNode($node->$dataKey, $key, $value);
98
            }
99
        } else {
100
            $node->$dataKey = $dataValue;
101
        }
102
    }
103
104
    /**
105
     * Remove XML first level nodes that are not present int the data array
106
     * @param SimpleXMLElement $resource
107
     * @param $data
108
     */
109
    private function checkForUselessNodes(SimpleXMLElement $resource, $data)
110
    {
111
        $uselessNodes = [];
112
        foreach ($resource as $key => $value) {
113
            if (!array_key_exists($key, $data)) {
114
                $uselessNodes[] = $key;
115
            }
116
        }
117
118
        foreach ($uselessNodes as $key) {
119
            unset($resource->$key);
120
        }
121
    }
122
123
    /**
124
     * Remove the given nodes from the resource
125
     * @param $resource
126
     * @param $removeSpecificNodes
127
     */
128
    private function removeSpecificNodes($resource, $removeSpecificNodes)
129
    {
130
        foreach ($removeSpecificNodes as $node) {
131
            unset($resource->$node);
132
        }
133
    }
134
135
    /**
136
     * @param SimpleXMLElement $node
137
     * @param array $dataValue
138
     */
139
    private function createNode(SimpleXMLElement $node, $dataValue)
140
    {
141
        foreach ($dataValue as $key => $value) {
142
            if (is_array($value)) {
143
                if (is_int($key)) {
144
                    $this->createNode($node, $value);
145
                } else {
146
                    $childNode=$node->addChild($key);
147
                    $this->createNode($childNode, $value);
148
                }
149
            } else {
150
                $node->addChild($key, $value);
151
            }
152
        }
153
    }
154
155
    /**
156
     * @param SimpleXMLElement $node
157
     */
158
    private function emptyNode(SimpleXMLElement $node)
159
    {
160
        $nodeNames = [];
161
        foreach ($node->children() as $key => $value) {
162
            $nodeNames[]=$key;
163
        }
164
165
        foreach ($nodeNames as $nodeName) {
166
            unset($node->$nodeName);
167
        }
168
    }
169
}
170