Issues (19)

Security Analysis    no request data  

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/Forms/ValidatorAdapters/LaravelValidator.php (2 issues)

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 namespace Rocket\UI\Forms\ValidatorAdapters;
2
3
use Illuminate\Validation\Validator;
4
5
class LaravelValidator implements ValidatorInterface
6
{
7
    /**
8
     * @var Validator
9
     */
10
    protected $validator;
11
    protected $data;
12
    protected $defaults;
13
14
    /**
15
     * @var \Illuminate\Session\Store
16
     */
17
    protected $session;
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function __construct($validator, $data, $defaults)
23
    {
24
        $this->validator = $validator;
25
        $this->data = $data;
26
        $this->defaults = $defaults;
27
    }
28
29
    /**
30
     * @return \Illuminate\Session\Store
31
     */
32
    protected function getSession()
33
    {
34
        //TODO :: do that by injection
35
        if (!$this->session) {
36
            $this->session = app('session');
37
        }
38
39
        return $this->session;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function hasError($name)
46
    {
47
        // The errors must be taken from the session, or else we have errors even if the form wasn't sent
48
        $session = $this->getSession();
49
        if ($session->has('errors')) {
50
            return $session->get('errors')->has($name);
51
        }
52
53
        return false;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function getErrors($name)
60
    {
61
        // The errors must be taken from the session, or else we have errors even if the form wasn't sent
62
        $session = $this->getSession();
63
        if ($session->has('errors')) {
64
            $errors = $session->get('errors');
65
66
            if ($errors->has($name)) {
67
                return $errors->get($name);
68
            }
69
        }
70
71
        return '';
72
    }
73
74
    /**
75
     * Transform key from array to dot syntax.
76
     *
77
     * @param  string $key
78
     *
79
     * @return string
80
     */
81
    protected function transformKey($key)
82
    {
83
        return str_replace(['.', '[]', '[', ']'], ['_', '', '.', ''], $key);
84
    }
85
86
    /**
87
     * Get the current value.
88
     *
89
     * With the following priority:
90
     * 1. If the field was posted, take that value
91
     * 2. If there is a model that has a value, take it
92
     * 3. If there is a value defined when showing the field
93
     * 4. If there is a default set in the validator
94
     *
95
     * @param string $name
96
     * @param string $default
97
     * @return mixed
98
     */
99
    public function getValue($name, $default = '')
100
    {
101
        // 1.
102
        $old = $this->getSession()->getOldInput($this->transformKey($name));
103
        if (!is_null($old)) {
104
            return $old;
105
        }
106
107
        // 2.
108
        if (!empty($this->data) && $value = data_get($this->model, $this->transformKey($name))) {
0 ignored issues
show
The property model does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
109
            return $value;
110
        }
111
112
        // 3.
113
        if (!empty($default)) {
114
            return $default;
115
        }
116
117
        // 4.
118
        if (!empty($this->defaults) && $value = data_get($this->defaults, $this->transformKey($name))) {
119
            return $value;
120
        }
121
122
        return '';
123
    }
124
125
    /**
126
     * {@inheritdoc}
127
     */
128
    public function isRequired($name)
129
    {
130
        $rules = $this->validator->getRules($name);
131
        if (array_key_exists($name, $rules)) {
132
            return is_array($rules[$name]) ? in_array('required', $rules[$name]) :
133
                str_contains($rules[$name], 'required');
134
        }
135
136
        return false;
137
    }
138
139
    /**
140
     * {@inheritdoc}
141
     */
142
    public static function supports($object)
143
    {
144
        return $object instanceof Validator;
0 ignored issues
show
The class Illuminate\Validation\Validator does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
145
    }
146
}
147