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 (27 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(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
The property $methods is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
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)
0 ignored issues
show
This method seems to be duplicated in 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...
56
    {
57
        $this->authenticate($username, $password);
58
59
        $response = Director::test(
60
            $this->buildRestfulURL($class, $id, $relation, 'xml'),
0 ignored issues
show
It seems like $relation defined by parameter $relation on line 55 can also be of type false; however, SOAPModelAccess::buildRestfulURL() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
61
            null,
62
            null,
0 ignored issues
show
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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)
0 ignored issues
show
This method seems to be duplicated in 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...
81
    {
82
        $this->authenticate($username, $password);
83
84
        $response = Director::test(
85
            $this->buildRestfulURL($class, $id, $relation, 'json'),
0 ignored issues
show
It seems like $relation defined by parameter $relation on line 80 can also be of type false; however, SOAPModelAccess::buildRestfulURL() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
86
            null,
87
            null,
0 ignored issues
show
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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)
0 ignored issues
show
This method seems to be duplicated in 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...
107
    {
108
        $this->authenticate($username, $password);
109
110
        $response = Director::test(
111
            $this->buildRestfulURL($class, $id, $relation, 'xml'),
0 ignored issues
show
It seems like $id defined by parameter $id on line 106 can also be of type false; however, SOAPModelAccess::buildRestfulURL() does only seem to accept integer|double, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
It seems like $relation defined by parameter $relation on line 106 can also be of type false; however, SOAPModelAccess::buildRestfulURL() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
112
            array(),
113
            null,
0 ignored issues
show
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
114
            ($id) ? 'PUT' : 'POST',
115
            $data
0 ignored issues
show
$data is of type array, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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)
0 ignored issues
show
This method seems to be duplicated in 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...
134
    {
135
        $this->authenticate($username, $password);
136
137
        $response = Director::test(
138
            $this->buildRestfulURL($class, $id, $relation, 'json'),
0 ignored issues
show
It seems like $class defined by parameter $class on line 133 can also be of type false; however, SOAPModelAccess::buildRestfulURL() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
It seems like $id defined by parameter $id on line 133 can also be of type false; however, SOAPModelAccess::buildRestfulURL() does only seem to accept integer|double, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
It seems like $relation defined by parameter $relation on line 133 can also be of type false; however, SOAPModelAccess::buildRestfulURL() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
139
            array(),
140
            null,
0 ignored issues
show
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
141
            ($id) ? 'PUT' : 'POST',
142
            $data
0 ignored issues
show
$data is of type array, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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)
0 ignored issues
show
This method seems to be duplicated in 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...
160
    {
161
        $this->authenticate($username, $password);
162
163
        $response = Director::test(
164
            $this->buildRestfulURL($class, $id, $relation, 'xml'),
0 ignored issues
show
It seems like $relation defined by parameter $relation on line 159 can also be of type false; however, SOAPModelAccess::buildRestfulURL() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
165
            null,
166
            null,
0 ignored issues
show
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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)
0 ignored issues
show
This method seems to be duplicated in 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...
185
    {
186
        $this->authenticate($username, $password);
187
188
        $response = Director::test(
189
            $this->buildRestfulURL($class, $id, $relation, 'json'),
0 ignored issues
show
It seems like $relation defined by parameter $relation on line 184 can also be of type false; however, SOAPModelAccess::buildRestfulURL() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
190
            null,
191
            null,
0 ignored issues
show
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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