Mon*_*eus 5 php forms xss codeigniter html-encode
CodeIgniters的安全类直接操纵您的Globals $_POST,它会发现file()并file ()成为威胁,因此HTML会对其进行编码.
// config.php from my apps folder is the culprit
$config['global_xss_filtering'] = TRUE;
Run Code Online (Sandbox Code Playgroud)
自己动手(少数人,勇敢者)
在CodeIgniter 2.1.4中,转到system/core/security.php#430-442行:
/*
* Sanitize naughty scripting elements
*
* Similar to above, only instead of looking for
* tags it looks for PHP and JavaScript commands
* that are disallowed. Rather than removing the
* code, it simply converts the parenthesis to entities
* rendering the code un-executable.
*
* For example: eval('some code')
* Becomes: eval('some code')
*/
$str = preg_replace('#(alert|cmd|passthru|eval|exec|expression|system|fopen|fsockopen|file|file_get_contents|readfile|unlink)(\s*)\((.*?)\)#si', "\\1\\2(\\3)", $str);
Run Code Online (Sandbox Code Playgroud)
基本上,似乎PHP或Apache看到file ()或file()作为威胁.
有没有人以前经历过这个或有文档资源为什么会发生这种情况?
任何人都可以在他们的服务器上测试这个,看他们是否经历过相同的行为 我在开发和测试机器上测试了这个.我没有机会在生产机器上进行测试,因为我们的客户连接到它.
HTML
<input name="q1" type="text" value="Profile (61) (D)">
<input name="q2" type="text" value="(61) (D)">
<input name="q3" type="text" value="file (61)">
<input name="q4" type="text" value="fil (61)">
<input name="q5" type="text" value="file ()">
<input name="q6" type="text" value="file()">
Run Code Online (Sandbox Code Playgroud)
JS - 可能无关紧要
$.ajax({
url: '/test_post'
,async: true
,cache: false
,type: 'POST'
,data: {
q1: $('input[name="q1"]').val(),
q2: $('input[name="q2"]').val(),
q3: $('input[name="q3"]').val(),
q4: $('input[name="q4"]').val(),
q5: $('input[name="q5"]').val(),
q6: $('input[name="q6"]').val()
}
,dataType: 'json'
,success: function(data){
console.log('irrelevant');
}
});
Run Code Online (Sandbox Code Playgroud)
网络 - Chrome中的标题标签 - 表单数据部分
q1: Profile (61) (D)
q2: (61) (D)
q3: file (61)
q4: fil (61)
q5: file ()
q6: file()
Run Code Online (Sandbox Code Playgroud)
PHP - CodeIgniter 2.1.4框架
echo '<pre>'.$_POST['q1'].'</pre>'; // produces: Profile (61) (D)
echo '<pre>'.$_POST['q2'].'</pre>'; // produces: (61) (D)
echo '<pre>'.$_POST['q3'].'</pre>'; // produces: file (61)
echo '<pre>'.$_POST['q4'].'</pre>'; // produces: fil (61)
echo '<pre>'.$_POST['q5'].'</pre>'; // produces: file ()
echo '<pre>'.$_POST['q6'].'</pre>'; // produces: file()
echo '<pre>'.html_entity_decode($_POST['q1']).'</pre>'; // produces: Profile (61) (D)
echo '<pre>'.html_entity_decode($_POST['q2']).'</pre>'; // produces: (61) (D)
echo '<pre>'.html_entity_decode($_POST['q3']).'</pre>'; // produces: file (61)
echo '<pre>'.html_entity_decode($_POST['q4']).'</pre>'; // produces: fil (61)
echo '<pre>'.html_entity_decode($_POST['q5']).'</pre>'; // produces: file ()
echo '<pre>'.html_entity_decode($_POST['q6']).'</pre>'; // produces: file()
// Both of these produce same exact result
echo '<pre>'.print_r($_POST, true).'</pre>';
echo '<pre>'.print_r($this->input->post(), true).'</pre>';
Run Code Online (Sandbox Code Playgroud)
开发
测试
根据用户指南,您可以通过设置来摆脱这个问题
$config['global_xss_filtering'] = FALSE;
Run Code Online (Sandbox Code Playgroud)
或者直接删除这一行。
恕我直言,修改$_POST阵列是设计失败,但你就可以了。