Home > php教程 > php手册 > body text

ThinkPHP2.x防范XSS跨站攻击的方法

WBOY
Release: 2016-06-06 19:42:33
Original
1562 people have browsed it

这篇文章主要介绍了ThinkPHP2.x防范XSS跨站攻击的方法,实例分析了ThinkPHP2.x针对XSS跨站攻击的防范技巧,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了ThinkPHP2.x防范XSS跨站攻击的方法。分享给大家供大家参考。具体如下:

一直使用ThinkPHP2.x,通过乌云有向提交了ThinkPHP XSS攻击的bug,抽时间看了一下。

原理是通过URL传入script标签,ThinkPHP异常错误页面直接输出了script。

原理:

?s=1%3Cbody+onload=alert(1)%3E

其中m的值是一个不存在的module,同时是一个完全的script,在异常错误页面中被执行实现XSS跨站攻击。

防范方法:

找到异常错误页面模板ThinkException.tpl.php(2,x),think_exception.tpl(3.x)有两个地方要修改:

第57行

复制代码 代码如下:

echo($_SERVER['PHP_SELF'])


改为

复制代码 代码如下:

echo strip_tags($_SERVER['PHP_SELF'])


第62行

复制代码 代码如下:

echo $e['message']


改为

复制代码 代码如下:

echo strip_tags($e['message'])

另外,,ThinkPHP自3.0开始官方已经对TP变量GROUP_NAME,MODULE_NAME,ACTION_NAME,__URL__,__SELF__,__APP__,$_SERVER['PHP_SELF']做了安全处理。

PS:安全不是框架的责任,大家在开发的时候须自己注意。

希望本文所述对大家基于ThinkPHP框架的php程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!