Issues (48)

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.

src/Eole/RestApi/Application.php (4 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 Eole\RestApi;
4
5
use Eole\Silex\Application as BaseApplication;
6
7
class Application extends BaseApplication
8
{
9
    /**
10
     * {@InheritDoc}
11
     */
12
    public function __construct(array $values = array())
13
    {
14
        parent::__construct($values);
15
16
        $this->registerServices();
0 ignored issues
show
The call to the method Eole\RestApi\Application::registerServices() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
17
        $this->registerEventListeners();
18
        $this->mountOAuth2Controller();
19
        $this->loadRestApis();
20
        $this->handleErrors();
21
    }
22
23
    /**
24
     * Register RestApi services
25
     */
26
    private function registerServices()
0 ignored issues
show
Consider using a different method name as you override a private method of the parent class.

Overwriting private methods is generally fine as long as you also use private visibility. It might still be preferable for understandability to use a different method name.

Loading history...
27
    {
28
        $this['eole.api_response_filter'] = function () {
29
            return new \Alcalyn\SerializableApiResponse\ApiResponseFilter(
30
                $this['serializer']
31
            );
32
        };
33
    }
34
35
    private function registerEventListeners()
36
    {
37
        $corsOrigin = $this['environment']['cors']['access_control_allow_origin'];
38
39
        if ($corsOrigin) {
40
            $this->register(new \JDesrosiers\Silex\Provider\CorsServiceProvider(), array(
41
                'cors.allowOrigin' => $corsOrigin,
42
            ));
43
44
            $this->after($this['cors']);
45
        }
46
47
        $this->on(\Symfony\Component\HttpKernel\KernelEvents::VIEW, function ($event) {
48
            $this['eole.api_response_filter']->onKernelView($event);
49
        });
50
    }
51
52
    /**
53
     * Mount /oauth
54
     */
55
    private function mountOAuth2Controller()
56
    {
57
        $this->mount('oauth', new ControllerProvider\OAuth2ControllerProvider());
0 ignored issues
show
new \Eole\RestApi\Contro...th2ControllerProvider() is of type object<Eole\RestApi\Cont...uth2ControllerProvider>, but the function expects a callable.

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...
58
    }
59
60
    /**
61
     * Mount Eole and games RestApi endpoints.
62
     */
63
    private function loadRestApis()
64
    {
65
        foreach ($this['environment']['mods'] as $modName => $modConfig) {
66
            $modClass = $modConfig['provider'];
67
            $mod = new $modClass();
68
            $provider = $mod->createControllerProvider();
69
            $prefix = 'api';
70
71
            if ($mod instanceof \Eole\Silex\GameProvider) {
72
                $prefix = 'api/games/'.$modName;
73
            }
74
75
            if ($provider instanceof \Pimple\ServiceProviderInterface) {
76
                $this->register($provider);
77
            }
78
79
            if ($provider instanceof \Silex\Api\ControllerProviderInterface) {
80
                $this->mount($prefix, $provider);
0 ignored issues
show
$provider is of type object<Silex\Api\ControllerProviderInterface>, but the function expects a callable.

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...
81
            }
82
        }
83
    }
84
85
    /**
86
     * Handle errors to display json exception.
87
     */
88
    private function handleErrors()
89
    {
90
        $this->error(function (\Exception $e) {
91
            // Returns Api response on HttpException.
92
            if ($e instanceof \Symfony\Component\HttpKernel\Exception\HttpException) {
93
                $errorData = [
94
                    'status_code' => $e->getStatusCode(),
95
                    'message' => $e->getMessage(),
96
                ];
97
98
                return new \Alcalyn\SerializableApiResponse\ApiResponse($errorData, $errorData['status_code']);
99
            }
100
101
            // Hide internal exception if no debug.
102
            if (!$this['debug']) {
103
                $errorData = [
104
                    'status_code' => 500,
105
                    'message' => 'Internal Server Error.',
106
                ];
107
108
                return new \Alcalyn\SerializableApiResponse\ApiResponse($errorData, $errorData['status_code']);
109
            }
110
        });
111
    }
112
}
113