
最近使用ThinkCMF给某*开发的一个平台,因为他们需要通过国家二级信息安全等级测试
所以自己先使用Appscan测试了一下,结果扫描出一个xss安全问题
可以看到这是一个通过编码的字符串,解码后的字符串为:
http://www.xxxx.com/portal/list/index/id/1/p/index.php?>'"><script>alert(81998)<%2Fscript>=123"

正确的效果

注入后的效果

而ThinkPhp里\simplewind\Lib\Util\Page.class.php文件在分页时并没有对字符串进行处理,从而导致将URL中的script代码成功注入到页面中

解决办法:
修改\application\Common\Controller\AppframeController.class.php 文件在_initialize方法里添加自定义xss检测方法
当URL中含有非法字符时就停止继续访问并提示

/**
* [xss 检测]
* @Author HTL
* @DateTime 2016-10-25T15:36:30+0800
* @return [type] [description]
*/
private function _xss_check() {
$temp = strtoupper(urldecode(urldecode($_SERVER['REQUEST_URI'])));
if(strpos($temp, '<') !== false || strpos($temp, '"') !== false || strpos($temp, 'CONTENT-TRANSFER-ENCODING') !== false) {
die('您当前的访问请求当中含有非法字符,已经被系统拒绝');
}
return true;
}
再次访问后的效果

参考: