Issues (5)

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/InputRequest.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
/*
4
 * This file is part of questocat/lumen-request package.
5
 *
6
 * (c) questocat <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Questocat\LumenRequest;
13
14
use Illuminate\Contracts\Container\Container;
15
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
16
use Illuminate\Contracts\Validation\ValidatesWhenResolved;
17
use Illuminate\Contracts\Validation\Validator;
18
use Illuminate\Http\JsonResponse;
19
use Illuminate\Http\Request;
20
use Illuminate\Validation\ValidatesWhenResolvedTrait;
21
use Illuminate\Validation\ValidationException;
22
23
abstract class InputRequest extends Request implements ValidatesWhenResolved
24
{
25
    use ValidatesWhenResolvedTrait;
26
27
    /**
28
     * The container instance.
29
     *
30
     * @var \Illuminate\Contracts\Container\Container
31
     */
32
    protected $container;
33
34
    /**
35
     * Get the validation rules that apply to the request.
36
     *
37
     * @return array
38
     */
39
    abstract public function rules();
40
41
    /**
42
     * Get custom messages for validator errors.
43
     *
44
     * @return array
45
     */
46
    public function messages()
47
    {
48
        return [];
49
    }
50
51
    /**
52
     * Get custom attributes for validator errors.
53
     *
54
     * @return array
55
     */
56 3
    public function attributes()
57
    {
58 3
        return [];
59
    }
60
61
    /**
62
     * Set the container implementation.
63
     *
64
     * @param \Illuminate\Contracts\Container\Container $container
65
     *
66
     * @return $this
67
     */
68 3
    public function setContainer(Container $container)
69
    {
70 3
        $this->container = $container;
71
72 3
        return $this;
73
    }
74
75
    /**
76
     * Get the validator instance for the request.
77
     *
78
     * @return \Illuminate\Contracts\Validation\Validator
79
     */
80 3
    protected function getValidatorInstance()
81
    {
82 3
        $factory = $this->container->make(ValidationFactory::class);
83
84 3
        if (method_exists($this, 'validator')) {
85
            $validator = $this->container->call([$this, 'validator'], compact('factory'));
86
        } else {
87 3
            $validator = $this->createDefaultValidator($factory);
88
        }
89
90 3
        if (method_exists($this, 'withValidator')) {
91
            $this->withValidator($validator);
0 ignored issues
show
Documentation Bug introduced by
The method withValidator does not exist on object<Questocat\LumenRequest\InputRequest>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
92
        }
93
94 3
        return $validator;
95
    }
96
97
    /**
98
     * Create the default validator instance.
99
     *
100
     * @param \Illuminate\Contracts\Validation\Factory $factory
101
     *
102
     * @return \Illuminate\Contracts\Validation\Validator
103
     */
104 3
    protected function createDefaultValidator(ValidationFactory $factory)
105
    {
106 3
        return $factory->make(
107 3
            $this->validationData(), $this->container->call([$this, 'rules']),
108 3
            $this->messages(), $this->attributes()
109
        );
110
    }
111
112
    /**
113
     * Get data to be validated from the request.
114
     *
115
     * @return array
116
     */
117 3
    protected function validationData()
118
    {
119 3
        return $this->all();
120
    }
121
122
    /**
123
     * Handle a failed validation attempt.
124
     *
125
     * @throws \Illuminate\Validation\ValidationException
126
     *
127
     * @param \Illuminate\Contracts\Validation\Validator $validator
128
     */
129 1
    protected function failedValidation(Validator $validator)
130
    {
131 1
        throw new ValidationException($validator, $this->buildFailedValidationResponse(
132 1
            $this->formatValidationErrors($validator)
133
        ));
134
    }
135
136
    /**
137
     * Build a failed validation response.
138
     *
139
     * @param $errors
140
     *
141
     * @return JsonResponse
142
     */
143 1
    protected function buildFailedValidationResponse($errors)
144
    {
145 1
        return new JsonResponse($errors, 422);
146
    }
147
148
    /**
149
     * Format the errors from the given Validator instance.
150
     *
151
     * @param \Illuminate\Contracts\Validation\Validator $validator
152
     *
153
     * @return array
154
     */
155 1
    protected function formatValidationErrors(Validator $validator)
156
    {
157 1
        return $validator->errors()->getMessages();
158
    }
159
}
160