简体   繁体   English

Codeigniter中的XSS过滤

[英]XSS Filtering in codeigniter

I just want to ask because I'm currently new in codeginiter and based on the documentation shown on XSS Filtering, it says that: 我只想问一下,因为我是Codeginiter中的新手,并且基于XSS Filtering上显示的文档,它表示:

By default it does not run globally since it requires a bit of processing overhead, 
and since you may not need it in all cases.

What this actually means? 这实际上是什么意思? Because I setup xss filtering globally thru config.php: 因为我通过config.php设置了xss全局过滤,所以:

$config['global_xss_filtering'] = TRUE;

What does the documentation means on the downside on doing the above instead of doing this? 该文档对执行上述操作(而不是执行此操作)的负面影响是什么?

$this->security->xss_clean()

xss_clean() is an extensive, and is also silly. xss_clean()很广泛,而且很愚蠢。 90% of this function does nothing to prevent xss. 此功能的90%不能阻止xss。 Such as looking for the word alert but not document.cookie . 例如寻找单词alert而不是document.cookie No hacker is going to use alert in their exploit, they are going to hijack the cookie with xss or read a CSRF token to make an XHR. 没有黑客会在他们的漏洞利用中使用alert ,他们会使用xss劫持cookie或读取CSRF令牌来制作XHR。

However running htmlentities() or htmlspecialchars() with it is just nothing but redundant. 但是,使用它运行htmlentities()htmlspecialchars()只是多余而已。 A case where xss_clean() fixes the issue and htmlentities($text, ENT_COMPAT, 'UTF-8') fails is the following: xss_clean()解决了该问题,而htmlentities($text, ENT_COMPAT, 'UTF-8')失败的情况如下:

<?php
print "<img src='$var'>";
?>

A simple poc is: 一个简单的poc是:

 http://localhost/xss.php?var=http://domain/some_image.gif'%20onload=alert(/xss/)

This will add the onload= event handler to the image tag. 这会将onload=事件处理程序添加到image标签。 A method of stoppipng this form of xss is htmlspecialchars($var,ENT_QUOTES); 这种形式的xss的stoppipng方法是htmlspecialchars($var,ENT_QUOTES); or in this case xss_clean() will also prevent this. 或者在这种情况下, xss_clean()也可以防止这种情况。

However, quoting from the xss_clean() documentation: 但是,引用xss_clean()文档:

Nothing is ever 100% foolproof, of course, but I haven't been able to get anything passed the filter. 当然,没有什么是百分百的万无一失的,但是我无法使任何东西通过过滤器。

That being said, XSS is an output problem not a input problem . 话虽如此,XSS是一个output problem 而不是一个input problem For instance this function cannot take into account that the variable is already within a <script> tag or event handler. 例如,此函数不能考虑变量已经在<script>标记或事件处理程序中。 It also doesn't stop DOM Based XSS. 它还不会停止基于DOM的XSS。 You need to take into consideration how you are using the data in order to use the best function. 您需要考虑如何使用数据才能使用最佳功能。 Filtering all the data on input is a bad practice . 过滤输入中的所有数据是一个坏习惯 Not only is it insecure but it also corrupts data which can make comparisons difficult. 它不仅不安全,而且还会破坏数据,从而使比较变得困难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM