ThinkPHP2.x XSS defense _ php instance

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.