Issues (2)

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/QueryBuilderForm.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
namespace leandrogehlen\querybuilder;
4
5
6
use yii\base\InvalidConfigException;
7
use yii\base\Widget;
8
use Yii;
9
use yii\helpers\Html;
10
use yii\helpers\Inflector;
11
use yii\helpers\Json;
12
13
14
/**
15
 * QueryBuilderForm renders a form for to submit rule information.
16
 *
17
 * This form renders hidden input with name defined into [[rulesParam]].
18
 * The hidden input will be used to send JSON rules into string format.
19
 *
20
 * The typical usage of QueryBuilderForm is as follows,
21
 *
22
 * ```php
23
 * <?php QueryBuilderForm::begin([
24
 *    'rules' => $rules,
25
 *    'builder' => [
26
 *        'id' => 'query-builder',
27
 *        'pluginOptions' => [
28
 *            'filters' => [
29
 *                ['id' => 'id', 'label' => 'Id', 'type' => 'integer'],
30
 *                ['id' => 'name', 'label' => 'Name', 'type' => 'string'],
31
 *                ['id' => 'lastName', 'label' => 'Last Name', 'type' => 'string']
32
 *            ]
33
 *        ]
34
 *    ]
35
 * ])?>
36
 *
37
 *    <?= Html::submitButton('Apply'); ?>
38
 *
39
 * <?php QueryBuilderForm::end() ?>
40
 * ```
41
 *
42
 * @author Leandro Gehlen <[email protected]>
43
 */
44
class QueryBuilderForm extends Widget
45
{
46
    /**
47
     * @param array|string $action the form action URL. This parameter will be processed by [[\yii\helpers\Url::to()]].
48
     * @see method for specifying the HTTP method for this form.
49
     */
50
    public $action = [''];
51
52
    /**
53
     * @var string the form submission method. This should be either 'post' or 'get'. Defaults to 'get'.
54
     *
55
     * When you set this to 'get' you may see the url parameters repeated on each request.
56
     * This is because the default value of [[action]] is set to be the current request url and each submit
57
     * will add new parameters instead of replacing existing ones.
58
     */
59
    public $method = 'get';
60
61
    /**
62
     * @var array the HTML attributes (name-value pairs) for the form tag.
63
     * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
64
     */
65
    public $options = [];
66
67
    /**
68
     * @var string the hidden input name that will be used to send JSON rules into string format
69
     */
70
    public $rulesParam = 'rules';
71
72
    /**
73
     * @var array|QueryBuilder QueryBuilder column configuration.
74
     * For example,
75
     *
76
     * ```php
77
     * <?= QueryBuilderForm::widget([
78
     *    'builder' => [
79
     *        'id' => 'query-builder',
80
     *        'filters' => [
81
     *            ['id' => 'id', 'label' => 'Id', 'type' => 'integer'],
82
     *            ['id' => 'name', 'label' => 'Name', 'type' => 'string'],
83
     *            ['id' => 'lastName', 'label' => 'Last Name', 'type' => 'string']
84
     *        ]
85
     *    ]
86
     *]) ?>
87
     * ```
88
     */
89
    public $builder;
90
91
    /**
92
     * @var string JSON rules representation into array format
93
     */
94
    public $rules;
95
96
    /**
97
     * @inheritdoc
98
     */
99
    public function init()
100
    {
101
        if (is_array($this->builder)) {
102
            $this->builder = Yii::createObject(array_merge([
103
                    'class' => QueryBuilder::className()
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
104
                ], $this->builder)
105
            );
106
        }
107
108
        if (!$this->builder instanceof QueryBuilder) {
109
            throw new InvalidConfigException('The "builder" property must be instance of "QueryBuilder');
110
        }
111
112
        if (!isset($this->options['id'])) {
113
            $this->options['id'] = $this->getId();
114
        }
115
116
        echo $this->builder->run();
117
        echo Html::beginForm($this->action, $this->method, $this->options);
118
        echo Html::hiddenInput($this->rulesParam);
119
    }
120
121
    /**
122
     * @inheritdoc
123
     */
124
    public function run()
125
    {
126
        echo Html::endForm();
127
128
        $id = $this->options['id'];
129
        $builderId = $this->builder->getId();
130
        $view = $this->getView();
131
132
        if ($this->rules) {
133
            $rules = Json::encode($this->rules);
134
            $view->registerJs("$('#{$builderId}').queryBuilder('setRules', {$rules});");
135
        }
136
137
        $frm = Inflector::variablize("frm-$id-querybuilder");
138
        $btn = Inflector::variablize("btn-$id-querybuilder-reset");
139
140
        $view->registerJs("var $frm = $('#{$id}');");
141
        $view->registerJs(<<<JS
142
    var $btn = {$frm}.find('button:reset:first');
143
    if ($btn.length){
144
        $btn.on('click', function(){
145
            $('#{$builderId}').queryBuilder('reset');
146
        });
147
    }
148
JS
149
        );
150
151
        $view->registerJs(<<<JS
152
{$frm}.on('submit', function(){
153
    var rules = $('#{$builderId}').queryBuilder('getRules');
154
    if ($.isEmptyObject(rules)) {
155
        return false;
156
    } else {
157
        var input = $(this).find("input[name='{$this->rulesParam}']:first");
158
        input.val(JSON.stringify(rules));
159
    }
160
});
161
JS
162
        );
163
    }
164
}
165