This article mainly introduces ThinkPHP2.x's defense against XSS cross-site attacks. The example analyzes ThinkPHP2.x's defense techniques against XSS cross-site attacks, which has some reference value, for more information about how ThinkPHP2.x defends against XSS attacks, see the examples in this article. Share it with you for your reference. The details are as follows:
I have been using ThinkPHP2.x and submitted the ThinkPHP XSS attack bug through wooyun. I took some time to read it.
The principle is to pass in the script tag through the URL. The ThinkPHP Exception error page directly outputs the script.
Principle:
Http://ask.lenovo.com.cn/index.php? S = 1% 3 Cbody + onload = alert (1) % 3E
The m value is a non-existent module and a complete script, which is executed on the error page to implement XSS cross-site attacks.
Defense methods:
Find the error page template ThinkException. tpl. php (2, x), think_exception.tpl (3.x), which has two points to be modified:
57th rows
The Code is as follows:
Echo ($ _ SERVER ['php _ SELF '])
Change
The Code is as follows:
Echo strip_tags ($ _ SERVER ['php _ SELF '])
62nd rows
The Code is as follows:
Echo $ e ['message']
Change
The Code is as follows:
Echo strip_tags ($ e ['message'])
In addition, ThinkPHP has been officially directed to the TP variable GROUP_NAME, MODULE_NAME, ACTION_NAME,/index since 3.0. php/Article,/php-weizijiaocheng-140515.html,/index. php, $ _ SERVER ['php _ SELF '] performs security processing.
PS: security is not the responsibility of the Framework. You must pay attention to it during development.
I hope this article will help you design php programs based on the ThinkPHP framework.