Issues (21)

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/ValidationService/ValidationService.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 BrightComponents\Valid\ValidationService;
4
5
use Illuminate\Contracts\Container\Container;
6
use Illuminate\Contracts\Validation\Validator;
7
use Illuminate\Validation\ValidationException;
8
use BrightComponents\Valid\Traits\SanitizesInput;
9
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
10
use BrightComponents\Valid\ValidationService\Concerns\HandlesRedirects;
11
use BrightComponents\Valid\Traits\PreparesCustomRulesForServiceValidator;
12
use BrightComponents\Valid\ValidationService\Concerns\InteractsWithValidationData;
13
use BrightComponents\Valid\Contracts\ValidationService\ValidationService as Contract;
14
15
class ValidationService implements Contract
16
{
17
    use HandlesRedirects, InteractsWithValidationData, SanitizesInput, PreparesCustomRulesForServiceValidator;
18
19
    /**
20
     * The container instance.
21
     *
22
     * @var \Illuminate\Contracts\Container\Container
23
     */
24
    protected $container;
25
26
    /**
27
     * The key to be used for the view error bag.
28
     *
29
     * @var string
30
     */
31
    protected $errorBag = 'default';
32
33
    /**
34
     * The data to be validated.
35
     *
36
     * @var array
37
     */
38
    protected $data;
39
40
    /**
41
     * Validate the class instance.
42
     *
43
     * @param  array  $data
44
     *
45
     * @throws \Illuminate\Validation\ValidationException
46
     *
47
     * @return array
48
     */
49
    public function validate(array $data)
50
    {
51
        $this->data = $data;
52
        $this->prepareCustomRules();
53
54
        $this->prepareForValidation();
55
56
        $validator = $this->getValidator();
57
58
        if (! $validator->passes()) {
59
            $this->failedValidation($validator);
60
        }
61
62
        return $this->validated();
63
    }
64
65
    /**
66
     * Get the validator for the request.
67
     *
68
     * @return \Illuminate\Contracts\Validation\Validator
69
     */
70
    protected function getValidator()
71
    {
72
        $factory = $this->container->make(ValidationFactory::class);
73
        $validator = $this->container->call([$this, 'validator'], compact('factory'));
74
75
        if (method_exists($this, 'withValidator')) {
76
            $this->withValidator($validator);
0 ignored issues
show
The method withValidator() does not exist on BrightComponents\Valid\V...rvice\ValidationService. Did you maybe mean validator()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
77
        }
78
79
        return $validator;
80
    }
81
82
    /**
83
     * Handle a failed validation attempt.
84
     *
85
     * @param  \Illuminate\Contracts\Validation\Validator  $validator
86
     *
87
     * @throws \Illuminate\Validation\ValidationException
88
     */
89
    protected function failedValidation(Validator $validator)
90
    {
91
        throw (new ValidationException($validator))
92
            ->errorBag($this->errorBag)
93
            ->redirectTo($this->getRedirectUrl());
94
    }
95
96
    /**
97
     * Create the default validator instance.
98
     *
99
     * @param  \Illuminate\Contracts\Validation\Factory  $factory
100
     *
101
     * @return \Illuminate\Contracts\Validation\Validator
102
     */
103
    public function validator(ValidationFactory $factory)
104
    {
105
        return $factory->make(
106
            $this->validationData() ?? [],
107
            $this->container->call([$this, 'rules']),
108
            $this->messages(),
109
            $this->attributes()
110
        );
111
    }
112
113
    /**
114
     * Run any needed logic prior to validation.
115
     */
116
    protected function prepareForValidation()
117
    {
118
        $this->sanitizeData();
119
120
        $this->beforeValidation();
121
122
        return $this->validationData();
123
    }
124
125
    /**
126
     * Run any logic needed prior to validation running.
127
     */
128
    protected function beforeValidation()
129
    {
130
    }
131
132
    /**
133
     * Get data to be validated from the request.
134
     *
135
     * @return array
136
     */
137
    protected function validationData()
138
    {
139
        return $this->data;
140
    }
141
142
    /**
143
     * Transform the data if necessary.
144
     *
145
     * @param  array  $data
146
     *
147
     * @return array
148
     */
149
    protected function transform($data)
150
    {
151
        return $data;
152
    }
153
154
    /**
155
     * Set the container implementation.
156
     *
157
     * @param  \Illuminate\Contracts\Container\Container  $container
158
     *
159
     * @return $this
160
     */
161
    public function setContainer(Container $container)
162
    {
163
        $this->container = $container;
164
165
        return $this;
166
    }
167
168
    /**
169
     * Get custom messages for validator errors.
170
     *
171
     * @return array
172
     */
173
    public function messages()
174
    {
175
        return [];
176
    }
177
178
    /**
179
     * Get custom attributes for validator errors.
180
     *
181
     * @return array
182
     */
183
    public function attributes()
184
    {
185
        return [];
186
    }
187
}
188