Issues (5)

Security Analysis    no request data  

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/Route.php (2 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
 * @package    Fuel\Routing
4
 * @version    2.0
5
 * @author     Fuel Development Team
6
 * @license    MIT License
7
 * @copyright  2010 - 2015 Fuel Development Team
8
 * @link       http://fuelphp.com
9
 */
10
11
namespace Fuel\Routing;
12
13
use LogicException;
14
15
class Route
16
{
17
	public $name;
18
	public $router;
19
	public $methods;
20
	public $resource;
21
	public $translation;
22
	public $parameters = array();
23
	public $filters = array();
24
25 1
	public function __construct(Router $router, array $methods, $resource, $translation, $name)
26
	{
27 1
		$this->name = $name;
28 1
		$this->router = $router;
29 1
		$this->methods = $methods;
30
31 1
		if (is_string($resource))
32
		{
33 1
			$this->resource = $this->parseTypes($resource);
34
		}
35
36 1
		$this->translation = $translation;
37 1
	}
38
39
	public function name($name)
40
	{
41
		$this->unregister();
42
		$this->name = $name;
43
		$this->router->inject($this);
44
45
		return $this;
46
	}
47
48
	public function unregister()
49
	{
50
		$this->router->unregister($this);
51
52
		return $this;
53
	}
54
55 1
	protected function parseTypes($resource)
56
	{
57 1
		$route = $this;
58 1
		$router = $this->router;
59
60
		$filter = function ($match) use ($route, $router)
61
		{
62
			list (, $type, $name) = $match;
63
			$type = $router->getType($type);
64
			$route->parameter($name, $type['regex'], $type['optional']);
65
66
			return '{'.$name.'}';
67 1
		};
68
69 1
		return preg_replace_callback('#\{([a-zA-Z_]+)\:([a-zA-Z_]+)\}#', $filter, $resource);
70
	}
71
72
	public function filters(array $filters)
73
	{
74
		$normalized = array();
75
76
		foreach ($filters as $filter => $parameters)
77
		{
78
			if (is_numeric($filter))
79
			{
80
				$normalized[$parameters] = [true];
81
			}
82
			else
83
			{
84
				$normalized[$filter] = (array) $parameters;
85
			}
86
		}
87
88
		$this->filters = array_merge($this->filters, $normalized);
89
90
		return $this;
91
	}
92
93
	public function filter($filter, $parameters = true)
94
	{
95
		$this->filters[$filter] = (array) $parameters;
96
97
		return $this;
98
	}
99
100
	public function parameter($parameter, $regex = '(.*)+', $optional = false)
101
	{
102
		if (is_string($parameter))
103
		{
104
			$parameter = new Parameter($this, $parameter, $regex, $optional);
105
		}
106
107
		$this->parameters[$parameter->name] = $parameter;
108
109
		return $parameter;
110
	}
111
112
	public function compileRegex()
113
	{
114
		$search = [];
115
		$replace = [];
116
117
		// Convert al named parameters the user
118
		// has specified as.
119
		foreach ($this->parameters as $parameter)
120
		{
121
			$search[] = '{'.$parameter->name.'}';
122
			$replace[] = $parameter->getRegex();
123
		}
124
125
		$regex = str_replace($search, $replace, $this->resource);
126
127
		// Convert remaining named parameters
128
		$regex = preg_replace('#\{([a-z\_]+)\}#', '(?P<$1>.+?)', $regex);
129
130
		return '#^'.$regex.'$#';
131
	}
132
133
	public function match($uri, $method)
134
	{
135
		if ( ! is_string($this->resource) or $method !== '*' and ! in_array($method, $this->methods))
136
		{
137
			return false;
138
		}
139
140
		$regex = $this->compileRegex();
141
142
		if ( ! preg_match($regex, $uri, $matches))
143
		{
144
			return false;
145
		}
146
147
		$translation = $this->translation;
148
		$parameters = $this->filterNamedParameters($matches);
149
150
		if (is_string($translation))
151
		{
152
			$translation = preg_replace($regex, $translation, $uri);
153
			$translation = str_replace('#/{2,}#', '/', $translation);
154
		}
155
156
		return new Match($this, $method, $uri, $translation, $parameters, $this->name);
157
	}
158
159
	public function filterNamedParameters(array $parameters)
160
	{
161
		foreach ($parameters as $key => $value)
162
		{
163
			if (is_numeric($key))
164
			{
165
				unset($parameters[$key]);
166
			}
167
		}
168
169
		return $parameters + $this->getDefaultNamedParameters();
170
	}
171
172
	public function getParameterDefault($name, $strict = true)
0 ignored issues
show
The parameter $strict is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
173
	{
174
		if ( ! isset($this->parameters[$name]))
175
		{
176
			return null;
177
		}
178
179
		$parameter = $this->parameters[$name];
180
181
		if ($parameter->optional)
182
		{
183
			return '';
184
		}
185
186
		return $parameter->default;
187
	}
188
189
	public function getDefaultNamedParameters()
190
	{
191
		return array_map(function ($parameter)
192
		{
193
			return $parameter->default;
194
		},
195
		$this->parameters);
196
	}
197
198
	public function compile(array $parameters = array())
199
	{
200
		$resource = $this->resource;
0 ignored issues
show
$resource is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
201
202
		$callback = function ($match) use ($parameters)
203
		{
204
			if (isset($parameters[$match[1]]))
205
			{
206
				return $parameters[$match[1]];
207
			}
208
209
			if ($default = $this->getParameterDefault($match[1]))
210
			{
211
				return $default;
212
			}
213
214
			throw new LogicException('Could not resolve parameter ['.$match[1].'] for route ['.$this->name.']');
215
		};
216
217
		return preg_replace_callback('#\{([a-zA-Z_-]+)\}#', $callback,	$this->resource);
218
	}
219
}
220