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

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 Proengsoft\JsValidation\Javascript;
4
5
use Exception;
6
use Illuminate\Contracts\Support\Arrayable;
7
use Illuminate\Support\Facades\View;
8
use Proengsoft\JsValidation\Exceptions\PropertyNotFoundException;
9
10
class JavascriptValidator implements Arrayable
11
{
12
    /**
13
     * Registered validator instance.
14
     *
15
     * @var ValidatorHandler
16
     */
17
    protected $validator;
18
19
    /**
20
     * Selector used in javascript generation.
21
     *
22
     * @var string
23
     */
24
    protected $selector;
25
26
    /**
27
     * View that renders Javascript.
28
     *
29
     * @var
30
     */
31
    protected $view;
32
33
    /**
34
     * Enable or disable remote validations.
35
     *
36
     * @var bool
37
     */
38
    protected $remote;
39
40
    /**
41
     * 'ignore' option for jQuery Validation Plugin.
42
     *
43
     * @var string
44
     */
45
    protected $ignore;
46
47
    /**
48
     * Constructor.
49
     *
50
     * @param ValidatorHandler $validator
51 192
     * @param array            $options
52
     */
53 192
    public function __construct(ValidatorHandler $validator, $options = [])
54 192
    {
55 192
        $this->validator = $validator;
56
        $this->setDefaults($options);
57
    }
58
59
    /**
60
     * Set default parameters.
61
     *
62
     * @param $options
63 192
     * @return void
64
     */
65 192
    protected function setDefaults($options)
66 192
    {
67 192
        $this->selector = empty($options['selector']) ? 'form' : $options['selector'];
68 192
        $this->view = empty($options['view']) ? 'jsvalidation::bootstrap' : $options['view'];
69
        $this->remote = isset($options['remote']) ? $options['remote'] : true;
70
71
        if (isset($options['ignore'])) {
72
            $this->ignore = $options['ignore'];
73
        }
74
    }
75
76
    /**
77 48
     * Render the specified view with validator data.
78
     *
79 48
     * @param null|\Illuminate\Contracts\View\View|string $view
80 48
     * @param null|string $selector
81
     * @return string
82 48
     */
83 36
    public function render($view = null, $selector = null)
84
    {
85
        $this->view($view);
86
        $this->selector($selector);
87
88
        return View::make($this->view, ['validator' => $this->getViewData()])
89
            ->render();
90
    }
91 48
92
    /**
93 48
     * Get the view data as an array.
94
     *
95
     * @return array
96
     */
97
    public function toArray()
98
    {
99
        return $this->getViewData();
100
    }
101 24
102
    /**
103
     * Get the string resulting of render default view.
104 24
     *
105 12
     * @return string
106 12
     */
107
    public function __toString()
108
    {
109
        try {
110
            return $this->render();
111
        } catch (Exception $exception) {
112
            return trigger_error($exception->__toString(), E_USER_ERROR);
113
        }
114
    }
115
116
    /**
117
     * Gets value from view data.
118 24
     *
119
     * @param $name
120 24
     * @return string
121 24
     *
122 12
     * @throws \Proengsoft\JsValidation\Exceptions\PropertyNotFoundException
123
     */
124
    public function __get($name)
125 12
    {
126
        $data = $this->getViewData();
127
        if (! array_key_exists($name, $data)) {
128
            throw new PropertyNotFoundException($name, get_class());
129
        }
130
131
        return $data[$name];
132
    }
133 120
134
    /**
135 120
     * Gets view data.
136 120
     *
137 108
     * @return array
138
     */
139 108
    protected function getViewData()
140 12
    {
141
        $this->validator->setRemote($this->remote);
142
        $data = $this->validator->validationData();
143 108
        $data['selector'] = $this->selector;
144
145
        if (! is_null($this->ignore)) {
146
            $data['ignore'] = $this->ignore;
147
        }
148
149
        return $data;
150
    }
151
152
    /**
153
     * Set the form selector to validate.
154
     *
155
     * @param string $selector
156
     * @deprecated
157
     */
158
    public function setSelector($selector)
159
    {
160
        $this->selector = $selector;
161
    }
162
163 48
    /**
164
     * Set the form selector to validate.
165 48
     *
166
     * @param string $selector
167 48
     * @return \Proengsoft\JsValidation\Javascript\JavascriptValidator
168
     */
169
    public function selector($selector)
170
    {
171
        $this->selector = is_null($selector) ? $this->selector : $selector;
172
173
        return $this;
174
    }
175
176 12
    /**
177
     * Set the input selector to ignore for validation.
178 12
     *
179
     * @param string $ignore
180 12
     * @return \Proengsoft\JsValidation\Javascript\JavascriptValidator
181
     */
182
    public function ignore($ignore)
183
    {
184
        $this->ignore = $ignore;
185
186
        return $this;
187
    }
188
189 48
    /**
190
     * Set the view to render Javascript Validations.
191 48
     *
192
     * @param null|\Illuminate\Contracts\View\View|string $view
193 48
     * @return \Proengsoft\JsValidation\Javascript\JavascriptValidator
194
     */
195
    public function view($view)
196
    {
197
        $this->view = is_null($view) ? $this->view : $view;
198
199
        return $this;
200
    }
201
202 12
    /**
203
     * Enables or disables remote validations.
204 12
     *
205
     * @param null|bool $enabled
206 12
     * @return \Proengsoft\JsValidation\Javascript\JavascriptValidator
207
     */
208
    public function remote($enabled = true)
209
    {
210
        $this->remote = $enabled;
211
212
        return $this;
213
    }
214
215
    /**
216
     * Validate Conditional Validations using Ajax in specified fields.
217 12
     *
218
     * @param string       $attribute
219 12
     * @param string|array $rules
220
     * @param null         $callback Dummy attribute to make API seamless with Laravel sometimes()
221 12
     * @return \Proengsoft\JsValidation\Javascript\JavascriptValidator
222
     */
223
    public function sometimes($attribute, $rules, $callback = null)
0 ignored issues
show
The parameter $callback is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
224
    {
225
        $this->validator->sometimes($attribute, $rules);
226
227
        return $this;
228
    }
229
}
230