Issues (1752)

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.

demo/form-validator-v2.php (7 issues)

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
$pathToRoot = '../';
3
require __DIR__ . '/' . $pathToRoot . 'config.default.php';
4
5
use Fwlib\Base\ReturnValue;
6
use Fwlib\Config\GlobalConfig;
7
use Fwlib\Html\Generator\Component\Form\Form;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Form.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
8
use Fwlib\Html\Generator\Element\Text;
9
use Fwlib\Html\Generator\Element\Textarea;
10
use Fwlib\Html\Generator\ElementMode;
11
use Fwlib\Net\Curl;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Curl.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
12
use Fwlib\Util\UtilContainer;
13
use Fwlib\Validator\ConstraintContainer;
14
use FwlibTest\Aide\TestServiceContainer;
15
16
/***************************************
17
 * Read post data
18
 **************************************/
19
$utilContainer = UtilContainer::getInstance();
20
$httpUtil = $utilContainer->getHttp();
21
22
$userTitle = $httpUtil->getPost('userTitle');
23
$userAge = $httpUtil->getPost('userAge');
24
$hiddenValue = $httpUtil->getPost('hiddenValue');
25
$remark = $httpUtil->getPost('remark');
26
27
$frontendCheck = 'checked="checked"';
28
if (!empty($_POST) && is_null($httpUtil->getPost('frontendCheck'))) {
29
    $frontendCheck = '';
30
}
31
32
33
/***************************************
34
 * Treat ajax post
35
 **************************************/
36
$action = $httpUtil->getGet('a');
37 View Code Duplication
if ('checkAge' == $action) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
    $age = trim($userAge);
39
40
    // Age must be positive, between 0~200
41
    // Assign message when new ReturnValue instance is not needed, but keep
42
    // return additional information is good for debug.
43
    if (is_numeric($age) && 0 <= $age && 200 >= $age) {
44
        $rv = new ReturnValue(0, 'success');
45
    } else {
46
        $rv = new ReturnValue(-1, 'fail');
47
    }
48
49
    echo $rv->toJson();
50
    exit;
51
}
52
53
54
/***************************************
55
 * Prepare FormValidator instance
56
 **************************************/
57
$curl = new Curl;
58
$curl->setSslVerify(false);
59
$serviceContainer = TestServiceContainer::getInstance();
60
$serviceContainer->register('Curl', $curl);
61
62
$constraintContainer = ConstraintContainer::getInstance();
63
$urlConstraint = $constraintContainer->getUrl();
64
65
$validator = $serviceContainer->getValidator();
66
$validator->setConstraintContainer($constraintContainer);
67
68
$form = new Form();
69
$form->setMode(ElementMode::EDIT)
70
    ->setClass('formWithValidator')
71
    ->setId('demoForm');
72
$form->getValidator()->setValidator($validator);
73
74
(new Text('userTitle'))->setTitle('名称')
75
    ->setValidateRules(['required'])
0 ignored issues
show
array('required') is of type array<integer,string,{"0":"string"}>, but the function expects a array<integer,object<string>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
76
    ->setTip('Should not be empty')
77
    ->setCheckOnKeyup(true)
78
    ->appendTo($form);
79
(new Text('userAge'))->setTitle('Age')
80
    ->setValidateRules(['required', 'url: ?a=checkAge , userAge , '])
0 ignored issues
show
array('required', 'url: ...checkAge , userAge , ') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a array<integer,object<string>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
81
    ->setTip('Age should be a valid age')
82
    ->appendTo($form);
83
// :TODO: Need drop down list select box
84
(new Text('hiddenValue'))->setTitle('Hidden Input')
85
    ->setValidateRules(['required', 'regex: /11/'])
0 ignored issues
show
array('required', 'regex: /11/') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a array<integer,object<string>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
86
    ->setTip('Must select one, must equals 11')
87
    ->appendTo($form);
88
(new Textarea('remark'))->setTitle('Remark')
89
    ->setValidateRules(['required', 'regex: /g/i'])
0 ignored issues
show
array('required', 'regex: /g/i') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a array<integer,object<string>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
90
    ->setTip('不能为空,必须包含字母 g 或者 G')
91
    ->setCheckOnKeyup(true)
92
    ->appendTo($form);
93
94
95
/***************************************
96
 * Prepare for output, backend validate
97
 **************************************/
98
if (!empty($_POST)) {
99
    $form->validate();
100
}
101
102
103
?>
104
105
<!DOCTYPE HTML>
106
<html lang='en'>
107
<head>
108
    <meta charset='utf-8'/>
109
    <title>FormValidator Demo</title>
110
111
    <link rel='stylesheet' href='<?php echo $pathToRoot; ?>css/reset.css'
112
          type='text/css' media='all'/>
113
    <link rel='stylesheet' href='<?php echo $pathToRoot; ?>css/default.css'
114
          type='text/css' media='all'/>
115
116
    <style type='text/css' media='all'>
117
        /* Write CSS below */
118
119
        form {
120
            margin: auto;
121
            margin-top: 2em;
122
            text-align: left;
123
            width: 33em;
124
        }
125
126
        form label {
127
            display: inline-block;
128
            font-weight: bold;
129
            text-align: right;
130
            width: 8em;
131
        }
132
133
        form label.right-side-label {
134
            font-weight: normal;
135
            text-align: left;
136
            width: 30em;
137
        }
138
139
        form input, form textarea {
140
            line-height: 150%;
141
            margin-bottom: 0.5em;
142
            margin-top: 0.5em;
143
        }
144
145
        .submit {
146
            margin-top: 0.5em;
147
            text-align: center;
148
        }
149
150
        #div-remark label, #div-remark textarea {
151
            vertical-align: middle;
152
        }
153
154
        #validate-fail-message {
155
            margin: auto;
156
            margin-bottom: -2em;
157
            width: 33em;
158
        }
159
    </style>
160
161
162
    <script type="text/javascript"
163
            src="<?php echo GlobalConfig::getInstance()->get('lib.path.jquery'); ?>">
164
    </script>
165
166
    <script type="text/javascript"
167
            src="<?php echo $pathToRoot; ?>js/form-validator.js">
168
    </script>
169
170
171
</head>
172
<body>
173
174
<h2>FormValidator Demo</h2>
175
176
177
<?php echo $form->getOutput(); ?>
178
179
180
<script type="text/javascript">
181
    <!--
182
183
    /* Attach event for frontendCheck option */
184
    (function (global) {
185
        var setCheckOnSubmit = function (event) {
186
            /* Html element maybe faster */
187
            /*if ($(this).prop('checked')) {*/
188
            if (event.target.checked) {
189
                global.formValidator_demoForm.enableCheckOnSubmit();
190
            } else {
191
                global.formValidator_demoForm.disableCheckOnSubmit();
192
            }
193
        };
194
195
        $('#frontendCheck')
196
            /* Need not click event */
197
            /*.on('click', setCheckOnSubmit)*/
198
            .on('change', setCheckOnSubmit)
199
            .trigger('change');
200
    })(window);
201
202
    -->
203
</script>
204
205
206
</body>
207
</html>
208