Issues (3)

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/DefaultServicesProvider.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 Geekish\Slimbox;
4
5
use mindplay\unbox\ContainerFactory as UnboxFactory;
6
use mindplay\unbox\ProviderInterface;
7
use Interop\Container\ContainerInterface;
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Http\Message\ServerRequestInterface;
10
use Slim\CallableResolver;
11
use Slim\Handlers\PhpError;
12
use Slim\Handlers\Error;
13
use Slim\Handlers\NotFound;
14
use Slim\Handlers\NotAllowed;
15
use Slim\Handlers\Strategies\RequestResponse;
16
use Slim\Http\Environment;
17
use Slim\Http\Headers;
18
use Slim\Http\Request;
19
use Slim\Http\Response;
20
use Slim\Interfaces\CallableResolverInterface;
21
use Slim\Interfaces\Http\EnvironmentInterface;
22
use Slim\Interfaces\InvocationStrategyInterface;
23
use Slim\Interfaces\RouterInterface;
24
use Slim\Router;
25
26
/**
27
 * Slim's default Service Provider.
28
 */
29
class DefaultServicesProvider implements ProviderInterface
30
{
31
    /**
32
     * @var array
33
     */
34
    protected $settings = [];
35
36
    /**
37
     * @param array $settings
38
     */
39
    public function __construct(array $settings = [])
40
    {
41
        $this->settings = $settings;
42
    }
43
44
    /**
45
     * Register Slim's default services.
46
     *
47
     * @param UnboxFactory $factory
48
     */
49
    public function register(UnboxFactory $factory)
0 ignored issues
show
register 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...
50
    {
51
        $factory->set(
52
            Settings::class,
53
            new Settings($this->settings)
54
        );
55
56
        $factory->alias(
57
            "settings",
58
            Settings::class
59
        );
60
61
        $factory->register(
62
            Environment::class,
63
            function () {
64
                return new Environment($_SERVER);
65
            }
66
        );
67
68
        $factory->alias(
69
            EnvironmentInterface::class,
70
            Environment::class
71
        );
72
73
        $factory->alias(
74
            "environment",
75
            Environment::class
76
        );
77
78
        $factory->register(
79
            Request::class,
80
            function (Environment $environment) {
81
                return Request::createFromEnvironment($environment);
82
            }
83
        );
84
85
        $factory->alias(
86
            ServerRequestInterface::class,
87
            Request::class
88
        );
89
90
        $factory->alias(
91
            "request",
92
            Request::class
93
        );
94
95
        $factory->register(
96
            Response::class,
97
            function (Settings $settings) {
98
                $headers = new Headers(['Content-Type' => 'text/html; charset=UTF-8']);
99
                $response = new Response(200, $headers);
100
101
                return $response->withProtocolVersion($settings['httpVersion']);
102
            }
103
        );
104
105
        $factory->alias(
106
            ResponseInterface::class,
107
            Response::class
108
        );
109
110
        $factory->alias(
111
            "response",
112
            Response::class
113
        );
114
115
        $factory->register(
116
            Router::class,
117
            function (Settings $settings) {
118
                $routerCacheFile = false;
119
                if ($settings->has('routerCacheFile') && file_exists($settings['routerCacheFile'])) {
120
                    $routerCacheFile = $settings['routerCacheFile'];
121
                }
122
                return (new Router)->setCacheFile($routerCacheFile);
123
            }
124
        );
125
126
        $factory->alias(
127
            RouterInterface::class,
128
            Router::class
129
        );
130
131
        $factory->alias(
132
            "router",
133
            Router::class
134
        );
135
136
        $factory->register(
137
            RequestResponse::class
138
        );
139
140
        $factory->alias(
141
            InvocationStrategyInterface::class,
142
            RequestResponse::class
143
        );
144
145
        $factory->alias(
146
            "foundHandler",
147
            RequestResponse::class
148
        );
149
150
        $factory->register(
151
            PhpError::class,
152
            function (Settings $settings) {
153
                return new PhpError($settings['displayErrorDetails']);
154
            }
155
        );
156
157
        $factory->alias(
158
            "phpErrorHandler",
159
            PhpError::class
160
        );
161
162
        $factory->register(
163
            Error::class,
164
            function (Settings $settings) {
165
                return new Error($settings['displayErrorDetails']);
166
            }
167
        );
168
169
        $factory->alias(
170
            "errorHandler",
171
            Error::class
172
        );
173
174
        $factory->register(
175
            NotFound::class
176
        );
177
178
        $factory->alias(
179
            "notFoundHandler",
180
            NotFound::class
181
        );
182
183
        $factory->register(
184
            NotAllowed::class
185
        );
186
187
        $factory->alias(
188
            "notAllowedHandler",
189
            NotAllowed::class
190
        );
191
192
        $factory->register(
193
            CallableResolver::class,
194
            function (ContainerInterface $container) {
195
                return new CallableResolver($container);
196
            }
197
        );
198
199
        $factory->alias(
200
            CallableResolverInterface::class,
201
            CallableResolver::class
202
        );
203
204
        $factory->alias(
205
            "callableResolver",
206
            CallableResolver::class
207
        );
208
    }
209
}
210