Issues (1)

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

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
declare(strict_types=1);
4
5
namespace Burzum\FastRouteMiddleware;
6
7
use Burzum\FastRouteMiddleware\Handler\FoundHandlerInterface;
8
use Burzum\FastRouteMiddleware\Handler\NotAllowedHandlerInterface;
9
use Burzum\FastRouteMiddleware\Handler\NotFoundHandlerInterface;
10
use Psr\Http\Server\MiddlewareInterface;
11
use Psr\Http\Message\ServerRequestInterface;
12
use Psr\Http\Server\RequestHandlerInterface;
13
use Psr\Http\Message\ResponseInterface;
14
use FastRoute\Dispatcher as DispatcherInterface;
15
16
/**
17
 * FastRoute Dispatcher Middleware
18
 *
19
 * @link https://github.com/nikic/FastRoute
20
 */
21
class FastRouteMiddleware implements MiddlewareInterface
22
{
23
    /**
24
     * Fast Route Dispatcher
25
     *
26
     * @var \FastRoute\Dispatcher
27
     */
28
    protected $dispatcher;
29
30
    /**
31
     * Route not allowed Handler
32
     *
33
     * @var null|\Burzum\FastRouteMiddleware\Handler\NotAllowedHandlerInterface
34
     */
35
    protected $notAllowedHandler;
36
37
    /**
38
     * Route not found Handler
39
     *
40
     * @var null|\Burzum\FastRouteMiddleware\Handler\NotFoundHandlerInterface
41
     */
42
    protected $notFoundHandler;
43
44
    /**
45
     * Route Found Handler
46
     *
47
     * @var null|\Burzum\FastRouteMiddleware\Handler\FoundHandlerInterface
48
     */
49
    protected $foundHandler;
50
51
    /**
52
     * Constructor
53
     *
54
     * @param \FastRoute\Dispatcher $dispatcher Fastroute Dispatcher
55
     * @param null|\Burzum\FastRouteMiddleware\Handler\FoundHandlerInterface $foundHandler Found Handler
56
     * @param null|\Burzum\FastRouteMiddleware\Handler\NotFoundHandlerInterface $notAllowedHandler Not Found Handler
57
     * @param null|\Burzum\FastRouteMiddleware\Handler\NotAllowedHandlerInterface $notAllowedHandler Not Allowed Handler
58
     */
59 1
    public function __construct(
60
        DispatcherInterface $dispatcher,
61
        ?FoundHandlerInterface $foundHandler = null,
62
        ?NotFoundHandlerInterface $notFoundHandler = null,
63
        ?NotAllowedHandlerInterface $notAllowedHandler = null
64
    ) {
65 1
        $this->dispatcher = $dispatcher;
66 1
        $this->foundHandler = $foundHandler;
67 1
        $this->notFoundHandler = $notFoundHandler;
68 1
        $this->notAllowedHandler = $notAllowedHandler;
0 ignored issues
show
Documentation Bug introduced by
It seems like $notAllowedHandler can also be of type object<Burzum\FastRouteM...tFoundHandlerInterface>. However, the property $notAllowedHandler is declared as type null|object<Burzum\FastR...llowedHandlerInterface>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
69 1
    }
70
71
    /**
72
     * Process an incoming server request and return a response, optionally
73
     * delegating response creation to a handler.
74
     *
75
     * @param \Psr\Http\Message\ServerRequestInterface $request Request
76
     * @param \Psr\Http\Server\RequestHandlerInterface $requestHandler Request Handler
77
     * @return \Psr\Http\Message\ResponseInterface
78
     */
79 1
    public function process(
80
        ServerRequestInterface $request,
81
        RequestHandlerInterface $requestHandler
82
    ): ResponseInterface {
83 1
        $routeInfo = $this->dispatch();
84 1
        $result = null;
85
86 1
        switch ($routeInfo[0]) {
87 1
            case DispatcherInterface::NOT_FOUND:
88 1
                if ($this->notFoundHandler !== null) {
89 1
                    $result = $this->notFoundHandler->handle($request);
90
                }
91
92 1
                break;
93 1
            case DispatcherInterface::METHOD_NOT_ALLOWED:
94
                if ($this->notAllowedHandler !== null) {
95
                    $result = $this->notAllowedHandler->handle($request, $routeInfo[1]);
96
                }
97
98
                break;
99 1
            case DispatcherInterface::FOUND:
100 1
                if ($this->foundHandler !== null) {
101 1
                    $result = $this->foundHandler->handle($request, $routeInfo[1], $routeInfo[2]);
102
                }
103
104 1
                break;
105
        }
106
107 1
        if ($request instanceof ResponseInterface) {
108
            return $result;
109
        }
110
111 1
        return $requestHandler->handle($request);
112
    }
113
114
    /**
115
     * Dispatches the Request URI
116
     *
117
     * @return array
118
     */
119 1
    protected function dispatch(): array
120
    {
121 1
        $httpMethod = $_SERVER['REQUEST_METHOD'];
122 1
        $uri = $_SERVER['REQUEST_URI'];
123
124
        // Strip query string (?foo=bar) and decode URI
125 1
        if (false !== $pos = strpos($uri, '?')) {
126
            $uri = substr($uri, 0, $pos);
127
        }
128
129 1
        $uri = rawurldecode($uri);
130
131 1
        return $this->dispatcher->dispatch($httpMethod, $uri);
132
    }
133
}
134