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/Forms.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 namespace Rocket\UI\Forms;
2
3
use Collective\Html\FormFacade as Form;
4
use Illuminate\Support\Facades\Log;
5
use Rocket\UI\Forms\ValidatorAdapters\ValidatorInterface;
6
7
/**
8
 * Class Forms
9
 * @method static Fields\Date date($id, $title = "")
10
 * @method static Fields\Time time($id, $title = "")
11
 * @method static Fields\Datetime datetime($id, $title = "")
12
 * @method static Fields\Textarea textarea($id, $title = "")
13
 * @method static Fields\Htmlarea htmlarea($id, $title = "")
14
 * @method static Fields\Field text($id, $title = "")
15
 * @method static Fields\Password password($id, $title = "")
16
 * @method static Fields\Radio radio($id, $title = "")
17
 * @method static Fields\Email email($id, $title = "")
18
 * @method static Fields\Autocomplete autocomplete($id, $title = "")
19
 * @method static Fields\Select select($id, $title = "")
20
 * @method static Fields\Checkbox checkbox($id, $title = "")
21
 * @method static Fields\Hidden hidden($id, $title = "")
22
 * @method static Fields\Honeypot honeypot($id, $title = "")
23
 * @method static Fields\File file($id, $title = "")
24
 * @method static Fields\Kaptcha kaptcha($id, $title = "")
25
 */
26
class Forms
27
{
28
    /**
29
     * Hold the configuration array
30
     *
31
     * @var array
32
     */
33
    public static $config;
34
35
    public static $currentValidator;
36
    public static $currentData;
37
38
    public static $adapters = [
39
        \Rocket\UI\Forms\ValidatorAdapters\LaravelValidator::class,
40
        \Rocket\UI\Forms\ValidatorAdapters\CodeIgniterFormValidator::class,
41
    ];
42
43
    /**
44
     * Set the current configuration
45
     *
46
     * @param $config
47
     */
48
    public static function setConfig($config)
49
    {
50
        self::$config = $config;
51
    }
52
53
    /**
54
     * @param object $validator
55
     * @param mixed $data
56
     * @param mixed $defaults
57
     * @return bool
58
     */
59
    public static function setFormValidator($validator, $data = [], $defaults = [])
60
    {
61
        foreach (self::$adapters as $class) {
62
            if ($class::supports($validator)) {
63
                self::$currentValidator = new $class($validator, $data, $defaults);
64
65
                return true;
66
            }
67
        }
68
69
        throw new \RuntimeException('impossible to find a form adapter for ' . get_class($validator));
70
    }
71
72
    /**
73
     * @return ValidatorInterface
74
     */
75
    public static function getFormValidator()
76
    {
77
        if (!self::$currentValidator) {
78
            Log::debug('You have no form validator defined');
79
        }
80
81
        return self::$currentValidator;
82
    }
83
84
    /**
85
     * @param string $adapter
86
     */
87
    public static function addFormValidatorAdapter($adapter)
88
    {
89
        if (!is_subclass_of($adapter, ValidatorInterface::class)) {
0 ignored issues
show
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Rocket\UI\Forms\Validat...lidatorInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
90
            throw new \RuntimeException("$adapter doesn't implement ValidatorInterface");
91
        }
92
93
        self::$adapters[] = $adapter;
94
    }
95
96
    /**
97
     * Get the list of field types
98
     *
99
     * @return mixed
100
     */
101
    public static function getFieldTypes()
102
    {
103
        return self::$config['field_types'];
104
    }
105
106
    /**
107
     * Shortcut to create a field
108
     *
109
     * @param $type
110
     * @param $arguments
111
     * @return Fields\Field
112
     */
113
    public static function __callStatic($type, $arguments)
114
    {
115
        $types = self::getFieldTypes();
116
117
        if (!array_key_exists($type, $types)) {
118
            throw new \RuntimeException("Cannot create field of type $type");
119
        }
120
121
        return self::field($arguments[0], array_key_exists(1, $arguments) ? $arguments[1] : '', $type);
122
    }
123
124
    /**
125
     * Create a field
126
     *
127
     * @param string $id
128
     * @param string $title
129
     * @param string $type
130
     * @return \Rocket\UI\Forms\Fields\Field
131
     */
132
    public static function field($id, $title = '', $type = 'text')
133
    {
134
        $types = self::getFieldTypes();
135
136
        $data = ['title' => $title];
137
138
        //Generates the class if we find the right renderer
139
        if (!array_key_exists($type, $types)) {
140
            $type = 'text';
141
        }
142
143
        return new $types[$type]($id, $data);
144
    }
145
146
    public static function getValue($field, $default = '')
147
    {
148
        $validator = static::getFormValidator();
149
150
        if ($validator) {
151
            return $validator->getValue($field, $default);
152
        }
153
    }
154
155
    public static function open(array $options = [])
156
    {
157
        if (array_key_exists('validator', $options)) {
158
            static::setFormValidator($options['validator']);
159
            unset($options['validator']);
160
        }
161
162
        return Form::open($options);
163
    }
164
165
    public static function close()
166
    {
167
        static::$currentValidator = null;
168
169
        return Form::close();
170
    }
171
172
    public static function submit($value = null, $options = [])
173
    {
174
        return Form::submit($value, $options);
175
    }
176
}
177