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.php (3 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\FormValidator;
8
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...
9
use Fwlib\Util\UtilContainer;
10
use Fwlib\Validator\ConstraintContainer;
11
use FwlibTest\Aide\TestServiceContainer;
12
13
/***************************************
14
 * Read post data
15
 **************************************/
16
$utilContainer = UtilContainer::getInstance();
17
$httpUtil = $utilContainer->getHttp();
18
19
$userTitle = $httpUtil->getPost('userTitle');
20
$userAge = $httpUtil->getPost('userAge');
21
$hiddenValue = $httpUtil->getPost('hiddenValue');
22
$remark = $httpUtil->getPost('remark');
23
24
$frontendCheck = 'checked="checked"';
25
if (!empty($_POST) && is_null($httpUtil->getPost('frontendCheck'))) {
26
    $frontendCheck = '';
27
}
28
29
30
/***************************************
31
 * Treat ajax post
32
 **************************************/
33
$action = $httpUtil->getGet('a');
34 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...
35
    $age = trim($userAge);
36
37
    // Age must be positive, between 0~200
38
    // Assign message when new ReturnValue instance is not needed, but keep
39
    // return additional information is good for debug.
40
    if (is_numeric($age) && 0 <= $age && 200 >= $age) {
41
        $rv = new ReturnValue(0, 'success');
42
    } else {
43
        $rv = new ReturnValue(-1, 'fail');
44
    }
45
46
    echo $rv->toJson();
47
    exit;
48
}
49
50
51
/***************************************
52
 * Prepare FormValidator instance
53
 **************************************/
54
$curl = new Curl;
55
$curl->setSslVerify(false);
56
$serviceContainer = TestServiceContainer::getInstance();
57
$serviceContainer->register('Curl', $curl);
58
59
$constraintContainer = ConstraintContainer::getInstance();
60
$urlConstraint = $constraintContainer->getUrl();
61
62
$validator = $serviceContainer->getValidator();
63
$validator->setConstraintContainer($constraintContainer);
64
65
$formValidator = new FormValidator;
0 ignored issues
show
Deprecated Code introduced by
The class Fwlib\Html\FormValidator has been deprecated with message: Use new {@see Form}, keep for back compatible.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
66
$formValidator->setValidator($validator);
67
68
$rules = [
69
    'userTitle' => [
70
        'title' => '名称',
71
        'check' => 'required',
72
        'tip'   => 'Should not be empty',
73
        'checkOnKeyup'  => true,
74
    ],
75
    'userAge' => [
76
        'check' => [
77
            'required',
78
            'url: ?a=checkAge , userAge , ',
79
        ],
80
        'tip'   => 'Age should be a valid age',
81
    ],
82
    'hiddenValue' => [
83
        'title' => 'Hidden Input',
84
        'check' => [
85
            'required',
86
            'regex: /11/',
87
        ],
88
        'tip'   => 'Must select one, must equals 11',
89
        'puppet' => 'puppetOfHidden',
90
    ],
91
    'remark' => [
92
        'check' => [
93
            'required',
94
            'regex: /g/i',
95
        ],
96
        'tip'   => '不能为空,必须包含字母 g 或者 G',
97
        'checkOnKeyup'  => true,
98
    ],
99
];
100
101
$formValidator->setRules($rules);
102
103
104
/***************************************
105
 * Prepare for output, backend validate
106
 **************************************/
107
$validateJs = $formValidator->getJs();
108
109
// Backend validate
110
$validateMessage = '';
111
if (!empty($_POST)) {
112
    $postData = [
113
        'userTitle'   => $userTitle,
114
        'userAge'     => $userAge,
115
        'hiddenValue' => $hiddenValue,
116
        'remark'      => $remark,
117
    ];
118
119
    if (!$formValidator->validate($postData)) {
120
        $validateMessage = '
121
<ul id="validate-fail-message">';
122
123
        foreach ($formValidator->getMessages() as $name => $message) {
124
            if (isset($rule[$name]['title'])) {
125
                $message = $rule[$name]['title'] . ': ' . $message;
126
            }
127
128
            $validateMessage .= "
129
  <li>$message</li>";
130
        }
131
132
        $validateMessage .= '
133
</ul>';
134
    }
135
}
136
137
138
?>
139
140
<!DOCTYPE HTML>
141
<html lang='en'>
142
<head>
143
  <meta charset='utf-8' />
144
  <title>FormValidator Demo</title>
145
146
  <link rel='stylesheet' href='<?php echo $pathToRoot; ?>css/reset.css'
147
    type='text/css' media='all' />
148
    <link rel='stylesheet' href='<?php echo $pathToRoot; ?>css/default.css'
149
    type='text/css' media='all' />
150
151
  <style type='text/css' media='all'>
152
  /* Write CSS below */
153
154
  form {
155
    margin: auto;
156
    margin-top: 2em;
157
    text-align: left;
158
    width: 33em;
159
  }
160
161
  form label {
162
    display: inline-block;
163
    font-weight: bold;
164
    text-align: right;
165
    width: 8em;
166
  }
167
168
  form label.right-side-label {
169
    font-weight: normal;
170
    text-align: left;
171
    width: 30em;
172
  }
173
174
  form input, form textarea {
175
    line-height: 150%;
176
    margin-bottom: 0.5em;
177
    margin-top: 0.5em;
178
  }
179
180
  .submit {
181
    margin-top: 0.5em;
182
    text-align: center;
183
  }
184
185
  #div-remark label, #div-remark textarea {
186
    vertical-align: middle;
187
  }
188
189
  #validate-fail-message {
190
    margin: auto;
191
    margin-bottom: -2em;
192
    width: 33em;
193
  }
194
  </style>
195
196
197
  <script type="text/javascript"
198
    src="<?php echo GlobalConfig::getInstance()->get('lib.path.jquery'); ?>">
199
  </script>
200
201
  <script type="text/javascript"
202
    src="<?php echo $pathToRoot; ?>js/form-validator.js">
203
  </script>
204
205
206
</head>
207
<body>
208
209
  <h2>FormValidator Demo</h2>
210
211
212
<?php echo $validateMessage; ?>
213
214
215
  <form method='post'>
216
217
    <label for='userTitle'>User Title:</label>
218
    <input type='text' name='userTitle' id='userTitle'
219
      value='<?php echo $userTitle; ?>' />
220
221
    <br />
222
223
    <label for='userAge'>User Age:</label>
224
    <input type='text' name='userAge' id='userAge'
225
      value='<?php echo $userAge; ?>' />
226
227
    <br />
228
229
    <!-- Hidden element value may not equals its puppet input -->
230
    <label for='puppetOfHidden'>Hidden Value:</label>
231
    <input type='text' name='hiddenValue' id='hiddenValue'
232
      value='<?php echo $hiddenValue; ?>' readonly='readonly' />
233
    <select id='puppetOfHidden'>
234
      <option value=''<?php echo ('' == $hiddenValue - 10) ? ' selected' : '';?>>
235
        Please Select</option>
236
      <option value='1'<?php echo (1 == $hiddenValue - 10) ? ' selected' : '';?>>
237
        Option One: 1</option>
238
      <option value='2'<?php echo (2 == $hiddenValue - 10) ? ' selected' : '';?>>
239
        Option Two: 2</option>
240
    </select>
241
    <script type='text/javascript'>
242
    <!--
243
    (function () {
244
      $('#puppetOfHidden').on('change', function () {
245
        $('#hiddenValue').val($('#puppetOfHidden').val() * 1 + 10);
246
      });
247
    }) ();
248
    -->
249
    </script>
250
251
    <br />
252
253
    <div id='div-remark'>
254
      <label for='remark'>Remark:</label>
255
      <textarea rows='3' cols='30' name='remark' id='remark'
256
        ><?php echo $remark; ?></textarea>
257
    </div>
258
259
    <input type='checkbox' name='frontendCheck' id='frontendCheck'
260
    value='1' <?php echo $frontendCheck; ?> />
261
    <label for='frontendCheck' class='right-side-label'>
262
      Enable frontend validate, un-check to see backend validate.
263
    </label>
264
265
    <div class='submit'>
266
      <input type='submit' value='Submit' />
267
    </div>
268
269
  </form>
270
271
272
<?php echo $validateJs; ?>
273
274
275
  <script type="text/javascript">
276
  <!--
277
278
  /* Attach event for frontendCheck option */
279
  (function (global) {
280
    var setCheckOnSubmit = function(event)
281
    {
282
      /* Html element maybe faster */
283
      /*if ($(this).prop('checked')) {*/
284
      if (event.target.checked) {
285
        global.formValidator.enableCheckOnSubmit();
286
      } else {
287
        global.formValidator.disableCheckOnSubmit();
288
      }
289
    };
290
291
    $('#frontendCheck')
292
      /* Need not click event */
293
      /*.on('click', setCheckOnSubmit)*/
294
      .on('change', setCheckOnSubmit)
295
      .trigger('change');
296
  }) (window);
297
298
  -->
299
  </script>
300
301
302
</body>
303
</html>
304