Issues (165)

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/Route/CRouterBasic.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
namespace Anax\Route;
4
5
/**
6
 * A container for routes.
7
 *
8
 */
9
class CRouterBasic implements \Anax\DI\IInjectionAware
10
{
11
    use \Anax\DI\TInjectionAware;
12
13
14
15
    /**
16
     * Properties
17
     *
18
     */
19
    private $routes         = [];    // All the routes
20
    private $internalRoutes = [];    // All internal routes
21
    private $defaultRoute   = null;  // A default rout to catch all
22
23
24
25
    /**
26
     * Get all routes.
27
     *
28
     * @return array with all routes.
29
     */
30
    public function getAll()
31
    {
32
        return $this->routes;
33
    }
34
35
36
37
    /**
38
     * Get all internal routes.
39
     *
40
     * @return array with internal routes.
41
     */
42
    public function getInternal()
43
    {
44
        return $this->internalRoutes;
45
    }
46
47
48
49
    /**
50
     * Add a route to the router.
51
     *
52
     * @param string $rule   for this route
53
     * @param mixed  $action null, string or callable to implement a controller for the route
54
     *
55
     * @return class as new route
56
     */
57
    public function add($rule, $action = null)
58
    {
59
        $route = $this->di->get('route');
60
        $route->set($rule, $action);
61
        $this->routes[] = $route;
62
63
        // Set as default route
64
        if ($rule == "*") {
65
            $this->defaultRoute = $route;
66
        }
67
        
68
        return $route;
69
    }
70
71
72
73
    /**
74
     * Add an internal (not exposed to url-matching) route to the router.
75
     *
76
     * @param string $rule   for this route
77
     * @param mixed  $action null, string or callable to implement a controller for the route
78
     *
79
     * @return class as new route
80
     */
81
    public function addInternal($rule, $action = null)
82
    {
83
        $route = $this->di->get('route');
84
        $route->set($rule, $action);
85
        $this->internalRoutes[$rule] = $route;
86
        return $route;
87
    }
88
89
90
91
    /**
92
     * Add an internal (not exposed to url-matching) route to the router.
93
     *
94
     * @param string $rule   for this route
95
     * @param mixed  $action null, string or callable to implement a controller for the route
0 ignored issues
show
There is no parameter named $action. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
96
     *
97
     * @return class as new route
98
     */
99
    public function handleInternal($rule)
100
    {
101
        if (isset($this->internalRoutes[$rule])) {
102
            $route = $this->internalRoutes[$rule];
103
            $route->handle();
104
        } else {
105
            throw new \Anax\Exception\NotFoundException("No internal route to handle: " . $rule);
106
        }
107
    }
108
109
110
111
    /**
112
     * Handle the routes and match them towards the request, dispatch them when a match is made.
113
     *
114
     * @return $this
115
     */
116
    public function handle()
117
    {
118
        try {
119
            $query = $this->di->request->getRoute();
120
            $parts = $this->di->request->getRouteParts();
121
122
            // Match predefined routes
123
            foreach ($this->routes as $route) {
124
                if ($route->match($query)) {
125
                    return $route->handle();
126
                }
127
            }
128
129
            // Default handling route as :controller/:action/:params using the dispatcher
130
            $dispatcher = $this->di->dispatcher;
131
            $dispatcher->setControllerName(isset($parts[0]) ? $parts[0] : 'index');
132
133
            if ($dispatcher->isValidController()) {
134
                $dispatcher->setActionName(isset($parts[1]) ? $parts[1] : 'index');
135
136
                $params = [];
137
                if (isset($parts[2])) {
138
                    $params = $parts;
139
                    array_shift($params);
140
                    array_shift($params);
141
                }
142
                $dispatcher->setParams($params);
143
144
                if ($dispatcher->isCallable()) {
145
                    return $dispatcher->dispatch();
146
                }
147
            }
148
149
            // Use the "catch-all" route
150
            if ($this->defaultRoute) {
151
                return $this->defaultRoute->handle();
152
            }
153
154
            // No route was matched
155
            $this->handleInternal('404');
156
        } catch (\Exception $e) {
157
            // Exception codes can match a route for a http status code
158
            $code = $e->getCode();
159
            $statusCodes = [403, 404, 500];
160
            if (in_array($code, $statusCodes)) {
161
                $this->di->flash->setMessage($e->getMessage());
162
                $this->handleInternal($code);
163
            } else {
164
                throw $e;
165
            }
166
        }
167
    }
168
}
169