Discussion on the secure use of ASP. net2.0 verification controls

Source: Internet
Author: User
The Asp.net verification control is widely used with its powerful functions. However, improper use of the control can easily lead to security risks. Some time ago, because the job needs to know a little about its verification policy, I would like to remind you of this question: By default, these verification controls only perform client verification on user input, whileCodeMust be manually added. Next we will take a look at how to bypass the default client authentication to submit illegal data to the server:

We drag four controls to a test page: a label, A Textbox, A requiredfieldvalidator, and a button. Here, requiredfieldvalidator is used to verify the Textbox Control. The response code for The onclick event of the button is also very simple (the code for server verification is not added here ):

Protected   Void Button#click ( Object Sender, eventargs E)
{
If ( This . Textbox1.text =   Null   |   This . Textbox1.text =   "" )
This . Label1.text =   " Input value is empty " ;
}

Our expectation is:Because the requiredfieldvalidator control is verified, the textbox value submitted to the server cannot be blank, so the label cannot be displayed as "input value is empty ". However, in fact, the above practice has a vulnerability that allows us to submit an empty textbox to the server:

 

RunProgramThen we can get a page, save it as an HTML document, open it in notepad, and make the following modifications:

Function webform_onsubmit (){
If (typeof (validatoronsubmit) = "function" & validatoronsubmit () = false)
Return false;
Return true;
}
Changed:

Function webform_onsubmit (){

// Skip the JS Code that executes client Verification

Return true;

}

 

<Form ID = form1 name = form1 onsubmit = "javascript: Return webform_onsubmit ();"
Action = validator. aspx method = post>
Change the action attribute to the complete submitted URL.

After doing this, we can use IE to open the saved HTML file. If you do not enter any value in the textbox, click the button to submit the page. Then we can see that the label displays what we expected:Input value is emptyThis proves that we have successfully bypassed the client's JavaScript verification.

To prevent the above problems, you only need to add the following lines to the onclick event processing code of the button:

If ( ! page. isvalid)
{
// raise an error here
}

After writing so much, I found that this small problem was too complicated. :) However, I personally think this may be a problem that is easily overlooked, I think this is also a small defect in Asp.net design, because it violates a very basic principle of information security: by default, anything that is not explicitly permitted should be prohibited. In short, I hope it will be helpful if I write so much nonsense.


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.