Issues (16)

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.

lib/RouteDefinition.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
/*
4
 * This file is part of the ICanBoogie package.
5
 *
6
 * (c) Olivier Laviale <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ICanBoogie\Routing;
13
14
use ICanBoogie\HTTP\Request;
15
16
/**
17
 * The class defines options that can be used to define a route as well as means to normalize and
18
 * validate this definition.
19
 */
20
class RouteDefinition
21
{
22
	/**
23
	 * Pattern of the route.
24
	 */
25
	const PATTERN = 'pattern';
26
27
	/**
28
	 * A controller class name (with an optional action) or a callable.
29
	 */
30
	const CONTROLLER = 'controller';
31
32
	/**
33
	 * The controller action.
34
	 */
35
	const ACTION = 'action';
36
37
	/**
38
	 * An identifier.
39
	 */
40
	const ID = 'id';
41
42
	/**
43
	 * A redirection target.
44
	 */
45
	const LOCATION = 'location';
46
47
	/**
48
	 * Request method(s) accepted by the route.
49
	 */
50
	const VIA = 'via';
51
52
	/**
53
	 * Route constructor, a class name for now.
54
	 */
55
	const CONSTRUCTOR = 'class';
56
57
	/**
58
	 * Normalizes a route definition.
59
	 *
60
	 * @param array $definition
61
	 */
62
	static public function normalize(array &$definition)
63
	{
64
		if (isset($definition[self::CONTROLLER]))
65
		{
66
			$controller = $definition[self::CONTROLLER];
67
68
			if (is_string($controller) && strpos($controller, RouteMaker::CONTROLLER_ACTION_SEPARATOR))
69
			{
70
				list($controller, $action) = explode(RouteMaker::CONTROLLER_ACTION_SEPARATOR, $controller);
71
72
				$definition[self::CONTROLLER] = $controller;
73
				$definition[self::ACTION] = $action;
74
			}
75
		}
76
77
		if (empty($definition[self::VIA]))
78
		{
79
			$definition[self::VIA] = Request::METHOD_ANY;
80
		}
81
	}
82
83
	/**
84
	 * Ensures that a route definition has an identifier and generates one if required.
85
	 *
86
	 * @param array $definition
87
	 *
88
	 * @return string The route identifier.
89
	 */
90
	static public function ensure_has_id(array &$definition)
91
	{
92
		if (empty($definition[self::ID]))
93
		{
94
			$definition[self::ID] = self::generate_anonymous_id();
95
		}
96
97
		return $definition[self::ID];
98
	}
99
100
	static private $anonymous_id_count;
101
102
	/**
103
	 * Generates an anonymous route identifier.
104
	 *
105
	 * @return string
106
	 */
107
	static private function generate_anonymous_id()
108
	{
109
		return 'anonymous_route_' . ++self::$anonymous_id_count;
110
	}
111
112
	/**
113
	 * Asserts that a route definition is valid.
114
	 *
115
	 * @param array $definition
116
	 *
117
	 * @throws PatternNotDefined when the pattern is not defined
118
	 * @throws ControllerNotDefined when both controller and location are not defined.
119
	 */
120
	static public function assert_is_valid(array $definition)
121
	{
122 View Code Duplication
		if (empty($definition[self::PATTERN]))
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
123
		{
124
			throw new PatternNotDefined(\ICanBoogie\format("Pattern is not defined: !route", [
125
126
				'route' => $definition
127
128
			]));
129
		}
130
131 View Code Duplication
		if (empty($definition[self::CONTROLLER]) && empty($definition[self::LOCATION]))
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
132
		{
133
			throw new ControllerNotDefined(\ICanBoogie\format("Controller is not defined: !route", [
134
135
				'route' => $definition
136
137
			]));
138
		}
139
	}
140
141
	/**
142
	 * No instance should be created from this class.
143
	 *
144
	 * @codeCoverageIgnore
145
	 */
146
	private function __construct()
147
	{
148
149
	}
150
}
151