XSS attack Solution

Source: Internet
Author: User

A man who cannot cry

<Form name = "testform" method = "post" action = "news/comment. php">
<Input type = "text" name = "userName">
<Input type = "hidden" name = "test1"/>
<Input type = "hidden" name = "test2"/>
</Form>
If the data entered by the user is "/> <script src = xxx> </script>, a malicious script is inserted. solution: 1. Verify the type and length of the data entered by the user. Others, including URL, query keyword, HTTP header, get, and post, also require reliable input verification, this can defend against some malicious scripts, but cannot completely defend against them. 2. Try to use the POST method instead of the GET method to submit the form; filter the characters such as "<", ">", ";", and; encode is required before any content is output to the page. To avoid directly disclosing user privacy, use cookies in combination with other systems or user information to reduce the risk of leakage. 3. Note that if the injection code is to remove keywords such as src href, you need to help supplement the findings without the protocol header. Style needs to focus on processing/**/expression url, as far as possible to prohibit the style attribute, all styles are defined in CSS. 4. Minimize sensitive operations such as document writing on the client. Focus on the following methods: document. URL document. URLUnencoded document. location () document. referrer window. location () document. create... () layer-by-layer Filtering of client, server, and database access layers. Each layer filters data to minimize risks. The above is a simple summary of XSS attacks. I hope you can add more. A scan result is provided!

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.