Issues (13)

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.

Middleware/RequestDeserializationMiddleware.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
namespace Realshadow\RequestDeserializer\Http\Middleware;
4
5
use Dingo\Api\Http\Request;
6
use Realshadow\RequestDeserializer\Contracts\RequestInterface;
7
use Realshadow\RequestDeserializer\Http\Request\RequestHandler;
8
use Closure;
9
10
11
/**
12
 * Class RequestDeserializationMiddleware
13
 *
14
 * @package Realshadow\RequestDeserializer\Http\Middleware
15
 * @author Lukáš Homza <[email protected]>
16
 */
17
class RequestDeserializationMiddleware
18
{
19
20
    /**
21
     * Request handler for deserialization of incoming requests
22
     *
23
     * @var RequestHandler $requestHandler
24
     */
25
    private $requestHandler;
26
27
    /**
28
     * Request entity class
29
     *
30
     * @var null|string $requestEntity
31
     */
32
    private $requestEntity;
33
34
    /**
35
     * Argument position in controllers arguments
36
     *
37
     * @var int $argumentPosition
38
     */
39
    private $argumentPosition = 0;
40
41
    /**
42
     * Determine matched controller and action from request
43
     *
44
     * @param Request|\Illuminate\Http\Request $request
45
     *
46
     * @return array
47
     */
48
    private function parseMatchedRoute(Request $request)
49
    {
50
        $action = $request->route()->getAction()['uses'];
51
52
        return explode('@', $action instanceof \Closure ? '@' : $action);
53
    }
54
55
    /**
56
     * @param Request|\Illuminate\Http\Request $request
57
     *
58
     * @return bool
59
     * @throws \ReflectionException
60
     */
61
    private function shouldValidate(Request $request)
62
    {
63
        $shouldValidate = false;
64
65
        list($controller, $action) = $this->parseMatchedRoute($request);
66
67
        if ($controller && $action) {
68
            $reflection = new \ReflectionMethod($controller, $action);
69
            foreach ($reflection->getParameters() AS $position => $param) {
70
                if ($param->getClass() === null) {
71
                    continue;
72
                }
73
74
                # -- requests have to implement RequestInterface
75
                if (in_array(RequestInterface::class, $param->getClass()->getInterfaceNames(), true)) {
76
                    if ($param->getClass()->isInterface()) {
77
                        $this->requestEntity = get_class(
78
                            app($param->getClass()->getName())
79
                        );
80
                    } else {
81
                        $this->requestEntity = $param->getClass()->getName();
82
                    }
83
84
                    $this->argumentPosition = $position;
85
86
                    $shouldValidate = true;
87
88
                    break;
89
                }
90
            }
91
        }
92
93
        return $shouldValidate;
94
    }
95
96
    /**
97
     * RequestDeserializationMiddleware constructor.
98
     *
99
     * @param RequestHandler $requestHandler
100
     */
101
    public function __construct(RequestHandler $requestHandler)
102
    {
103
        $this->requestHandler = $requestHandler;
104
    }
105
106
    /**
107
     * Handle an incoming request.
108
     *
109
     * @param \Illuminate\Http\Request $request
110
     * @param \Closure $next
111
     *
112
     * @return mixed
113
     * @throws \ReflectionException
114
     *
115
     * @throws \LogicException
116
     * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
117
     * @throws \Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException
118
     */
119
    public function handle($request, Closure $next)
120
    {
121
        if ( ! $this->shouldValidate($request)) {
0 ignored issues
show
$request of type object<Illuminate\Http\Request> is not a sub-type of object<Dingo\Api\Http\Request>. It seems like you assume a child class of the class Illuminate\Http\Request to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
122
            return $next($request);
123
        }
124
125
        $this->requestHandler->setArgumentPosition($this->argumentPosition);
126
127
        if ($request->method() === Request::METHOD_GET) {
128
            $this->requestHandler->hydrate($this->requestEntity, $request->query->all());
129
        } else {
130
            $this->requestHandler->deserialize($this->requestEntity, $request->getContent());
0 ignored issues
show
It seems like $request->getContent() targeting Symfony\Component\HttpFo...n\Request::getContent() can also be of type resource; however, Realshadow\RequestDeseri...tHandler::deserialize() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
131
        }
132
133
        return $next($request);
134
    }
135
136
}
137