Issues (183)

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

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
namespace FMUP;
3
4
use FMUP\Routing\Route;
5
6
/**
7
 * Class Routing - Routing system where we'll be able to handle multiple route to be handled in a controller
8
 * @package FMUP
9
 */
10
class Routing
11
{
12
    const WAY_APPEND = 'WAY_APPEND';
13
    const WAY_PREPEND = 'WAY_PREPEND';
14
    /**
15
     * List of routes to check on routing
16
     * @var array
17
     */
18
    private $routes = array();
19
20
    /**
21
     * @var Request
22
     */
23
    private $originalRequest;
24
25
    /**
26
     * Dispatch routes and return the first available route
27
     * @param Request $request
28
     * @return Route|null
29
     */
30 9
    public function dispatch(Request $request)
31
    {
32 9
        $this->setOriginalRequest($request);
33 9
        $redispatch = false;
34 9
        $routeSelected = null;
35 9
        $this->defaultRoutes();
0 ignored issues
show
The call to the method FMUP\Routing::defaultRoutes() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
36
        do {
37 9
            foreach ($this->getRoutes() as $route) {
38 2
                if ($route->setRequest($request)->canHandle()) {
39
                    //this will handle the request - not fluent interface because we don't know how developer will write
40 2
                    $route->handle();
41 2
                    $redispatch = $route->hasToBeReDispatched();
42 2
                    if (!$redispatch) {
43 2
                        $routeSelected = $route;
44
                    }
45 2
                    break;
46
                }
47
            }
48 9
        } while ($redispatch);
49 9
        return $routeSelected;
50
    }
51
52
    /**
53
     * Define the original request
54
     * @param Request $request
55
     * @return $this
56
     */
57 9
    private function setOriginalRequest(Request $request)
58
    {
59 9
        $this->originalRequest = clone $request;
60 9
        return $this;
61
    }
62
63
    /**
64
     * Retrieve original request (nothing has been modified)
65
     * @return Request|null
66
     */
67 1
    public function getOriginalRequest()
68
    {
69 1
        return $this->originalRequest;
70
    }
71
72
    /**
73
     * Retrieve defined routes
74
     * @return Route[]
75
     */
76 11
    public function getRoutes()
77
    {
78 11
        return $this->routes;
79
    }
80
81
82
    /**
83
     * Clear all routes defined
84
     * @return $this
85
     */
86 1
    public function clearRoutes()
87
    {
88 1
        $this->routes = array();
89 1
        return $this;
90
    }
91
92
    /**
93
     * Add a route in stack
94
     * @param Route $route
95
     * @param string $way
96
     * @return $this
97
     */
98 4
    public function addRoute(Route $route, $way = self::WAY_APPEND)
99
    {
100 4
        if ($way == self::WAY_PREPEND) {
101 4
            array_unshift($this->routes, $route);
102
        } else {
103 4
            array_push($this->routes, $route);
104
        }
105 4
        return $this;
106
    }
107
108
    /**
109
     * Can be used to define routes initialized by default
110
     * @return $this
111
     */
112 8
    public function defaultRoutes()
113
    {
114 8
        return $this;
115
    }
116
}
117