Issues (53)

Security Analysis    not enabled

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.

code/SOAPModelAccess.php (2 issues)

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
 * Basic SOAP Server to access and modify DataObject instances.
4
 * You can enable SOAP access on a DataObject by setting {@link DataObject::$api_access} to true.
5
 * This means that you'll also enable a RESTful API through {@link RestfulServer}.
6
 *
7
 * @todo Test relation methods
8
 */
9
class SOAPModelAccess extends SapphireSoapServer
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
10
{
11
    private static $methods = array(
12
        'getXML' => array(
13
            'class' => 'string',
14
            'id' => 'int',
15
            'relation' => 'string',
16
            '_returns' => 'string',
17
        ),
18
        'getJSON' => array(
19
            'class' => 'string',
20
            'id' => 'int',
21
            'relation' => 'string',
22
            '_returns' => 'string',
23
        ),
24
        'putXML' => array(
25
            'class' => 'string',
26
            'id' => 'int',
27
            'relation' => 'string',
28
            'data' => 'string',
29
            'username' => 'string',
30
            'password' => 'string',
31
            '_returns' => 'boolean',
32
        ),
33
        'putJSON' => array(
34
            'class' => 'string',
35
            'id' => 'int',
36
            'relation' => 'string',
37
            '_returns' => 'boolean',
38
        ),
39
    );
40
41
    public function Link($action = null)
42
    {
43
        return Controller::join_links('soap/v1/', $action);
44
    }
45
46
    /**
47
     * Used to emulate RESTful GET requests with XML data.
48
     *
49
     * @param string $class
50
     * @param Number $id
51
     * @param string $relation Relation name
52
     *
53
     * @return string
54
     */
55 View Code Duplication
    public function getXML($class, $id, $relation = false, $username = null, $password = null)
56
    {
57
        $this->authenticate($username, $password);
58
59
        $response = Director::test(
60
            $this->buildRestfulURL($class, $id, $relation, 'xml'),
61
            null,
62
            null,
63
            'GET'
64
        );
65
66
        return ($response->isError()) ? $this->getErrorMessage($response) : $response->getBody();
67
    }
68
69
    /**
70
     * Used to emulate RESTful GET requests with JSON data.
71
     *
72
     * @param string $class
73
     * @param Number $id
74
     * @param string $relation Relation name
75
     * @param string $username
76
     * @param string $password
77
     *
78
     * @return string
79
     */
80 View Code Duplication
    public function getJSON($class, $id, $relation = false, $username = null, $password = null)
81
    {
82
        $this->authenticate($username, $password);
83
84
        $response = Director::test(
85
            $this->buildRestfulURL($class, $id, $relation, 'json'),
86
            null,
87
            null,
88
            'GET'
89
        );
90
91
        return ($response->isError()) ? $this->getErrorMessage($response) : $response->getBody();
92
    }
93
94
    /**
95
     * Used to emulate RESTful POST and PUT requests with XML data.
96
     *
97
     * @param string $class
98
     * @param Number $id
99
     * @param string $relation Relation name
100
     * @param array  $data
101
     * @param string $username
102
     * @param string $password
103
     *
104
     * @return string
105
     */
106 View Code Duplication
    public function putXML($class, $id = false, $relation = false, $data, $username = null, $password = null)
107
    {
108
        $this->authenticate($username, $password);
109
110
        $response = Director::test(
111
            $this->buildRestfulURL($class, $id, $relation, 'xml'),
112
            array(),
113
            null,
114
            ($id) ? 'PUT' : 'POST',
115
            $data
116
        );
117
118
        return ($response->isError()) ? $this->getErrorMessage($response) : $response->getBody();
119
    }
120
121
    /**
122
     * Used to emulate RESTful POST and PUT requests with JSON data.
123
     *
124
     * @param string $class
125
     * @param Number $id
126
     * @param string $relation Relation name
127
     * @param array  $data
128
     * @param string $username
129
     * @param string $password
130
     *
131
     * @return string
132
     */
133 View Code Duplication
    public function putJSON($class = false, $id = false, $relation = false, $data, $username = null, $password = null)
134
    {
135
        $this->authenticate($username, $password);
136
137
        $response = Director::test(
138
            $this->buildRestfulURL($class, $id, $relation, 'json'),
139
            array(),
140
            null,
141
            ($id) ? 'PUT' : 'POST',
142
            $data
143
        );
144
145
        return ($response->isError()) ? $this->getErrorMessage($response) : $response->getBody();
146
    }
147
148
    /**
149
     * Used to emulate RESTful DELETE requests.
150
     *
151
     * @param string $class
152
     * @param Number $id
153
     * @param string $relation Relation name
154
     * @param string $username
155
     * @param string $password
156
     *
157
     * @return string
158
     */
159 View Code Duplication
    public function deleteXML($class, $id, $relation = false, $username = null, $password = null)
160
    {
161
        $this->authenticate($username, $password);
162
163
        $response = Director::test(
164
            $this->buildRestfulURL($class, $id, $relation, 'xml'),
165
            null,
166
            null,
167
            'DELETE'
168
        );
169
170
        return ($response->isError()) ? $this->getErrorMessage($response) : $response->getBody();
171
    }
172
173
    /**
174
     * Used to emulate RESTful DELETE requests.
175
     *
176
     * @param string $class
177
     * @param Number $id
178
     * @param string $relation Relation name
179
     * @param string $username
180
     * @param string $password
181
     *
182
     * @return string
183
     */
184 View Code Duplication
    public function deleteJSON($class, $id, $relation = false, $username = null, $password = null)
185
    {
186
        $this->authenticate($username, $password);
187
188
        $response = Director::test(
189
            $this->buildRestfulURL($class, $id, $relation, 'json'),
190
            null,
191
            null,
192
            'DELETE'
193
        );
194
195
        return ($response->isError()) ? $this->getErrorMessage($response) : $response->getBody();
196
    }
197
198
    /**
199
     * Faking an HTTP Basicauth login in the PHP environment
200
     * that RestfulServer can pick up.
201
     *
202
     * @param string $username Username
203
     * @param string $password Plaintext password
204
     */
205
    protected function authenticate($username, $password)
0 ignored issues
show
authenticate uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
206
    {
207
        if (is_string($username)) {
208
            $_SERVER['PHP_AUTH_USER'] = $username;
209
        }
210
        if (is_string($password)) {
211
            $_SERVER['PHP_AUTH_PW'] = $password;
212
        }
213
    }
214
215
    /**
216
     * @param string $class
217
     * @param Number $id
218
     * @param string $relation
219
     * @param string $extension
220
     *
221
     * @return string
222
     */
223
    protected function buildRestfulURL($class, $id, $relation, $extension)
224
    {
225
        $url = "api/v1/{$class}";
226
        if ($id) {
227
            $url .= "/{$id}";
228
        }
229
        if ($relation) {
230
            $url .= "/{$relation}";
231
        }
232
        if ($extension) {
233
            $url .= "/.{$extension}";
234
        }
235
236
        return $url;
237
    }
238
239
    /**
240
     * @param SS_HTTPResponse $response
241
     *
242
     * @return string XML string containing the HTTP error message
243
     */
244
    protected function getErrorMessage($response)
245
    {
246
        return '<error type="authentication" code="'.$response->getStatusCode().'">'.$response->getStatusDescription().'</error>';
247
    }
248
}
249