Issues (45)

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/Application.php (1 issue)

Labels
Severity

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
/**
4
 * This file is part of slick/mvc package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Mvc;
11
12
use Interop\Container\ContainerInterface;
13
use Slick\Configuration\Configuration;
14
use Slick\Di\Container;
15
use Slick\Di\ContainerBuilder;
16
use Slick\Http\PhpEnvironment\MiddlewareRunnerInterface;
17
use Slick\Http\PhpEnvironment\Request;
18
use Slick\Http\PhpEnvironment\Response;
19
20
/**
21
 * Class Application
22
 * @package Slick\Mvc
23
 */
24
class Application
25
{
26
27
    /**
28
     * @var ContainerInterface
29
     */
30
    private static $container;
31
32
    /**
33
     * @var string
34
     */
35
    private $configPath;
36
37
    /**
38
     * @var Request
39
     */
40
    private $request;
41
42
    /**
43
     * @var MiddlewareRunnerInterface
44
     */
45
    private $runner;
46
47
    /**
48
     * @var Response
49
     */
50
    private $response;
51
52
    /**
53
     * @var ContainerInterface
54
     */
55
    private static $defaultContainer;
56
57
    /**
58
     * Creates an application with an HTTP request
59
     *
60
     * If no request is provided then a Slick\Http\PhpEnvironment\Request is
61
     * created with values form current php environment settings.
62
     *
63
     * @param Request $request
64
     */
65 8
    public function __construct(Request $request = null)
66
    {
67 8
        $this->request = $request;
68 8
        Configuration::addPath(__DIR__.'/Configuration');
69 8
        $definitions = include __DIR__.'/Configuration/services.php';
70 8
        self::$defaultContainer = (
71 8
            new ContainerBuilder($definitions)
72 1
        )
73 8
        ->getContainer();
74 8
    }
75
76
    /**
77
     * Sets a new request
78
     *
79
     * @param Request $request
80
     *
81
     * @return Application
82
     */
83 2
    public function setRequest(Request $request)
84
    {
85 2
        $this->request = $request;
86 2
        $this->getContainer()->register('request', $request);
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Interop\Container\ContainerInterface as the method register() does only exist in the following implementations of said interface: Slick\Di\Container.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
87 2
        return $this;
88
    }
89
90
    /**
91
     * Gets the application dependency injection container
92
     *
93
     * @return ContainerInterface|Container
94
     */
95 6
    public function getContainer()
96
    {
97 6
        if (is_null(self::$container)) {
98 2
            self::$container = $this->checkContainer();
99 1
        }
100 6
        return self::$container;
101
    }
102
103
    /**
104
     * Sets the dependency injection container
105
     *
106
     * @param ContainerInterface $container
107
     */
108 22
    public static function setContainer(ContainerInterface $container)
109
    {
110 22
        self::$container = $container;
111 22
    }
112
113
    /**
114
     * Returns the application dependency container
115
     *
116
     * @return ContainerInterface|Container
117
     */
118 20
    public static function container()
119
    {
120 20
        if (null == self::$container) {
121 2
            $app = new static;
122 2
            $app->getContainer();
123 1
        }
124 20
        return self::$container;
125
    }
126
127
    /**
128
     * Set middleware runner
129
     *
130
     * @param MiddlewareRunnerInterface $runner
131
     *
132
     * @return $this|self|Application
133
     */
134 2
    public function setRunner(MiddlewareRunnerInterface $runner)
135
    {
136 2
        $this->runner = $runner;
137 2
        return $this;
138
    }
139
140
    /**
141
     * Returns the processed response
142
     *
143
     * @return Response
144
     */
145 2
    public function getResponse()
146
    {
147 2
        if (is_null($this->response)) {
148 2
            $this->response = $this->getRunner()->run();
149 1
        }
150 2
        return $this->response;
151
    }
152
153
    /**
154
     * Gets the HTTP middleware runner for this application
155
     *
156
     * @return MiddlewareRunnerInterface
157
     */
158 2
    public function getRunner()
159
    {
160 2
        if (null === $this->runner) {
161 2
            $runner = $this->getContainer()
162 2
                ->get('middleware.runner')
163 2
                ->setRequest($this->getRequest())
164 1
            ;
165 2
            $this->setRunner($runner);
166 1
        }
167 2
        return $this->runner;
168
    }
169
170
    /**
171
     * Set configuration path
172
     * 
173
     * @param string $configPath
174
     * 
175
     * @return Application|self
176
     */
177
    public function setConfigPath($configPath)
178
    {
179
        $this->configPath = $configPath;
180
        Configuration::addPath($configPath);
181
        return $this;
182
    }
183
184
    /**
185
     * Gets configuration path
186
     * 
187
     * @return string
188
     */
189
    public function getConfigPath()
190
    {
191
        if (null == $this->configPath) {
192
            $this->configPath = getcwd().'/Configuration';
193
            Configuration::addPath($this->configPath);
194
        }
195
        return $this->configPath;
196
    }
197
198
    /**
199
     * Gets HTTP request object
200
     *
201
     * @return Request
202
     */
203 4
    public function getRequest()
204
    {
205 4
        if (null === $this->request) {
206 2
            $this->request = $this->getContainer()
207 2
                ->get('request');
208 1
        }
209 4
        return $this->request;
210
    }
211
212
    /**
213
     * Gets container with user overridden settings
214
     * 
215
     * @return ContainerInterface|\Slick\Di\Container
216
     */
217 2
    protected function checkContainer()
218
    {
219 2
        $container = self::$defaultContainer;
220
        if (
221 2
            null != $this->configPath &&
222 1
            file_exists($this->configPath.'/services.php')
223 1
        ) {
224
            $definitions = include $this->configPath.'/services.php';
225
            $container = (
226
                new ContainerBuilder(
227
                    $definitions,
228
                    true
229
                )
230
            )->getContainer();
231
        }
232 2
        return $container;
233
    }
234
235
}