Issues (21)

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/Routing/Route.php (2 issues)

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
namespace JetFire\Routing;
4
5
/**
6
 * Class Route
7
 * @package JetFire\Routing
8
 * @method getParameters()
9
 * @method getBlock()
10
 * @method getKeys()
11
 * @method getPath()
12
 * @method string getParams()
13
 */
14
class Route
15
{
16
17
    /**
18
     * @var
19
     */
20
    private $url;
21
    /**
22
     * @var
23
     */
24
    private $name;
25
    /**
26
     * @var
27
     */
28
    private $callback;
29
    /**
30
     * @var string
31
     */
32
    private $method;
33
    /**
34
     * @var array
35
     */
36
    private $target = [];
37
    /**
38
     * @var array
39
     */
40
    private $detail = [];
41
42
    /**
43
     */
44
    public function __construct()
0 ignored issues
show
__construct 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...
__construct uses the super-global variable $_POST 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...
45
    {
46
        $this->method = (isset($_SERVER['REQUEST_METHOD'])) ? $_SERVER['REQUEST_METHOD'] : 'GET';
47
        if ($this->method == 'POST' && isset($_SERVER['X-HTTP-METHOD-OVERRIDE'])) {
48
            $this->method = strtoupper($_SERVER['X-HTTP-METHOD-OVERRIDE']);
49
        }
50
        if (isset($_POST['_METHOD']) && in_array($_POST['_METHOD'], array('PUT', 'PATCH', 'HEAD', 'DELETE'))) {
51
            $this->method = $_POST['_METHOD'];
52
        }
53
    }
54
55
    /**
56
     * @param array $args
57
     */
58
    public function set($args = [])
59
    {
60
        if (isset($args['name'])) $this->name = $args['name'];
61
        if (isset($args['callback'])) $this->callback = $args['callback'];
62
        if (isset($args['target'])) $this->target = $args['target'];
63
        if (isset($args['detail'])) $this->detail = $args['detail'];
64
    }
65
66
    /**
67
     * @return null
68
     */
69
    public function getUrl()
70
    {
71
        return $this->url;
72
    }
73
74
    /**
75
     * @param $url
76
     */
77
    public function setUrl($url)
78
    {
79
        $this->url = $url;
80
    }
81
82
    /**
83
     * @return null
84
     */
85
    public function getName()
86
    {
87
        return $this->name;
88
    }
89
90
    /**
91
     * @param $name
92
     */
93
    public function setName($name)
94
    {
95
        $this->name = $name;
96
    }
97
98
    /**
99
     * @return mixed
100
     */
101
    public function getCallback()
102
    {
103
        return $this->callback;
104
    }
105
106
    /**
107
     * @param $callback
108
     */
109
    public function setCallback($callback)
110
    {
111
        $this->callback = $callback;
112
    }
113
114
    /**
115
     * @return array
116
     */
117
    public function getMethod()
118
    {
119
        return $this->method;
120
    }
121
122
    /**
123
     * @return array
124
     */
125
    public function getDetail()
126
    {
127
        return $this->detail;
128
    }
129
130
    /**
131
     * @param $detail
132
     */
133
    public function setDetail($detail)
134
    {
135
        $this->detail = array_merge($detail, $this->detail);
136
    }
137
138
    /**
139
     * @param $key
140
     * @param $value
141
     */
142
    public function addDetail($key, $value)
143
    {
144
        $this->detail[$key] = $value;
145
    }
146
147
    /**
148
     * @param null $key
149
     * @return array|string
150
     */
151
    public function getTarget($key = null)
152
    {
153
        if (!is_null($key))
154
            return isset($this->target[$key]) ? $this->target[$key] : '';
155
        return empty($this->target) ? '' : $this->target;
156
    }
157
158
    /**
159
     * @param $target
160
     */
161
    public function setTarget($target = [])
162
    {
163
        $this->target = $target;
164
    }
165
166
    /**
167
     * @param $key
168
     * @param $value
169
     */
170
    public function addTarget($key, $value)
171
    {
172
        $this->target[$key] = $value;
173
    }
174
175
    /**
176
     * @param null $key
177
     * @return bool
178
     */
179
    public function hasTarget($key = null)
180
    {
181
        if (!is_null($key))
182
            return isset($this->target[$key]) ? true : false;
183
        return empty($this->target) ? false : true;
184
    }
185
186
    /**
187
     * @return array
188
     */
189
    public function getData()
190
    {
191
        return (isset($this->getDetail()['data']) && is_array($this->getDetail()['data'])) ? $this->getDetail()['data'] : [];
192
    }
193
194
    /**
195
     * @param $name
196
     * @param $arguments
197
     * @return null
198
     */
199
    public function __call($name, $arguments)
200
    {
201
        if (substr($name, 0, 3) === "get") {
202
            $key = strtolower(str_replace('get', '', $name));
203
            return isset($this->detail[$key]) ? $this->detail[$key] : '';
204
        } elseif (substr($name, 0, 3) === "set") {
205
            $key = strtolower(str_replace('set', '', $name));
206
            $this->detail[$key] = $arguments[0];
207
        }
208
        return '';
209
    }
210
}
211