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/Controller.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 Aura\Router\Route;
13
use Psr\Http\Message\ResponseInterface;
14
use Psr\Http\Message\ServerRequestInterface;
15
use Slick\Http\PhpEnvironment\Request;
16
use Slick\Http\PhpEnvironment\Response;
17
use Slick\Mvc\Controller\UrlUtils;
18
19
/**
20
 * Controller
21
 *
22
 * @package Slick\Mvc
23
 * @author  Filipe Silva <[email protected]>
24
 */
25
abstract class Controller implements ControllerInterface
26
{
27
28
    /**
29
     * @var ServerRequestInterface|Request
30
     */
31
    protected $request;
32
33
    /**
34
     * @var ResponseInterface|Response
35
     */
36
    protected $response;
37
38
    /**
39
     * @var array
40
     */
41
    protected $vars = [];
42
43
    /**
44
     * For URL parsing
45
     */
46
    use UrlUtils;
47
48
    /**
49
     * Registers the current HTTP request and response
50
     *
51
     * @param ServerRequestInterface $request
52
     * @param ResponseInterface      $response
53
     *
54
     * @return Controller|$this|self|ControllerInterface
55
     */
56 26
    public function register(
57
        ServerRequestInterface $request, ResponseInterface $response
58
    ) {
59 26
        $this->request = $request;
60 26
        $this->response = $response;
61 26
        return $this;
62
    }
63
64
    /**
65
     * Gets updated HTTP response
66
     *
67
     * @return ResponseInterface
68
     */
69 10
    public function getResponse()
70
    {
71 10
        return $this->response;
72
    }
73
74
    /**
75
     * Gets updated HTTP request
76
     *
77
     * @return ServerRequestInterface
78
     */
79 10
    public function getRequest()
80
    {
81 10
        return $this->request;
82
    }
83
84
    /**
85
     * Sets a value to be used by render
86
     *
87
     * The key argument can be an associative array with values to be set
88
     * or a string naming the passed value. If an array is given then the
89
     * value will be ignored.
90
     *
91
     * Those values must be set in the request attributes so they can be used
92
     * latter by any other middle ware in the stack.
93
     *
94
     * @param string|array $key
95
     * @param mixed        $value
96
     *
97
     * @return Controller|$this|self|ControllerInterface
98
     */
99 8
    public function set($key, $value = null)
100
    {
101 8
        if (is_string($key)) {
102 6
            return $this->registerVar($key, $value);
103
        }
104
105 2
        foreach ($key as $name => $value) {
106 2
            $this->registerVar($name, $value);
107 1
        }
108 2
        return $this;
109
    }
110
111
    /**
112
     * Returns the data that was set on controller action
113
     *
114
     * @return array
115
     */
116 8
    public function getViewVars()
117
    {
118 8
        return $this->vars;
119
    }
120
121
    /**
122
     * Enables or disables rendering
123
     *
124
     * @param bool $disable
125
     * @return ControllerInterface|self|$this
126
     */
127 6
    public function disableRendering($disable = true)
128
    {
129 6
        $this->request = $this->request->withAttribute('render', !$disable);
130 6
        return $this;
131
    }
132
133
    /**
134
     * Changes the current rendering template
135
     *
136
     * @param string $template
137
     * @return ControllerInterface|self|$this
138
     */
139 2
    public function setView($template)
140
    {
141 2
        $this->request = $this->request->withAttribute('template', $template);
142 2
        return $this;
143
    }
144
145
    /**
146
     * Redirects the flow to another route/path
147
     *
148
     * @param string $path the route or path to redirect to
149
     *
150
     * @return Controller|self|$this
151
     */
152 4
    public function redirect($path)
153
    {
154 4
        $args = func_get_args();
155 4
        $url = call_user_func_array([$this, 'getUrl'], $args);
156 4
        $this->response = $this->createRedirectResponse($url);
157 4
        $this->disableRendering();
158 4
        return $this;
159
    }
160
161
    /**
162
     * Get the routed request attributes
163
     *
164
     * @param null|string $name
165
     * @param mixed       $default
166
     *
167
     * @return mixed
168
     */
169 6
    public function getRouteAttributes($name = null, $default = null)
170
    {
171
        /** @var Route $route */
172 6
        $route = $this->request->getAttribute('route', false);
173 3
        $attributes = $route
174 6
            ? $route->attributes
175 6
            : [];
176
        
177 6
        if (null == $name) {
0 ignored issues
show
It seems like you are loosely comparing $name of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
178 2
            return $attributes;
179
        }
180
        
181 4
        return array_key_exists($name, $attributes)
182 3
            ? $attributes[$name]
183 4
            : $default;
184
    }
185
186
    /**
187
     * Register a variable value
188
     *
189
     * @param string $key
190
     * @param mixed $value
191
     *
192
     * @return Controller|$this|self
193
     */
194 8
    protected function registerVar($key, $value)
195
    {
196 8
        $this->vars[$key] = $value;
197 8
        return $this;
198
    }
199
200
    /**
201
     * Creates a redirect response for provided path
202
     * 
203
     * @param string $path
204
     * 
205
     * @return Response
206
     */
207 4
    protected function createRedirectResponse($path)
208
    {
209 4
        $response = $this->response->withStatus(302)
210 4
            ->withHeader('Location', $path);
211 4
        return $response;
212
    }
213
}