Issues (162)

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/test/RestTest.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
namespace Ntb\RestAPI;
4
5
/**
6
 * Rest test class can work as base class for your functional tests. It provides some helpful methods to test your rest
7
 * api more easily.
8
 */
9
abstract class RestTest extends \SapphireTest {
10
11
    /**
12
     * The namespace of your api.
13
     * @var string
14
     */
15
    protected $namespace = 'v/1';
16
17
    /**
18
     * The route to the session without the namespace.
19
     * @var string
20
     */
21
    protected $sessionRoute = 'sessions';
22
23
    public function setUp() {
24
        parent::setUp();
25
        // clear cache
26
        \SS_Cache::factory('rest_cache')->clean(\Zend_Cache::CLEANING_MODE_ALL);
27
    }
28
29
30
    /**
31
     * Perform an api request with the given options
32
     *
33
     * @param string $path the request path; can consist of resource name, identifier and GET params
34
     * @param array $options
35
     *  * string `body` the data
36
     *  * int `code` the expected response code
37
     *  * string `method` the http method
38
     *  * ApiSession `session` the test session
39
     *  * string `token` the auth token
40
     *  * array `postVars` the post data, eg. multi form or files
41
     * @return array
42
     * @throws \SS_HTTPResponse_Exception
43
     */
44
    protected function makeApiRequest($path, $options=[]) {
45
        $settings = array_merge([
46
            'session' => null,
47
            'token' => null,
48
            'method' => 'GET',
49
            'body' => null,
50
            'postVars' => null,
51
            'code' => 200
52
        ], $options);
53
        $headers = [
54
            'Accept' => 'application/json'
55
        ];
56
        if($settings['token']) {
57
            $headers['Authorization'] = "Bearer {$settings['token']}";
58
        }
59
        $response = \Director::test(
60
            \Controller::join_links($this->namespace, $path),
61
            $settings['postVars'],
62
            $settings['session'],
0 ignored issues
show
$settings['session'] 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
            $settings['method'],
64
            $settings['body'],
65
            $headers
66
        );
67
        $this->assertEquals($settings['code'], $response->getStatusCode(), "Wrong status code: {$response->getBody()}");
0 ignored issues
show
The method assertEquals() does not seem to exist on object<Ntb\RestAPI\RestTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
68
        return json_decode($response->getBody(), true);
69
    }
70
71
    /**
72
     * Creates a session for the api.
73
     *
74
     * @param string $email the email of the user
75
     * @param string $password the password for the user
76
     * @return array the current session with `token`
77
     */
78
    protected function createSession($email='[email protected]', $password='password') {
79
        $data = [
80
            'email' => $email,
81
            'password' => $password
82
        ];
83
        $dataString = json_encode($data);
84
        $result = $this->makeApiRequest('SessionRoute', ['body' => $dataString, 'method' => 'POST']);
85
        return $result['session'];
86
    }
87
}
88