Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check for script in asp.net text box

We would like to stop users inputing html or javascript in a text box.

We can just parse the input and check for angel brackets. Was wondering is there a better way to do this?

like image 493
Shiraz Bhaiji Avatar asked Sep 15 '09 14:09

Shiraz Bhaiji


4 Answers

I have found that replacing the angel brackets with encoded angel brackets solves most problems. Here is a reference for all the ways people can cross-site script. Making a regex to stop any flavor of HTML and or Script is damn near impossible.

like image 183
rick schott Avatar answered Oct 30 '22 13:10

rick schott


If you set Page.ValidateRequest = true then it will stop this.

From .net version 1.1 onwards (I think) this is set to true by default.

like image 24
Robin Day Avatar answered Oct 30 '22 15:10

Robin Day


Can you use a regular expression validator to verify the input?

like image 39
bechbd Avatar answered Oct 30 '22 15:10

bechbd


Page.ValidateRequest will stop this unless you have it turned off.

However, OWASP guidelines (as well pretty much all competent security guidelines) tell you that you should NOT try to limit bad characters in your validation, but instead you should filter so that only specifically allowed characters are used.

http://en.wikipedia.org/wiki/Secure_input_and_output_handling

http://www.owasp.org/index.php/Top_10_2007-A1

For good secure coding practices I would start here and bookmark the site for future reference. http://www.owasp.org/index.php/Top_10_2007

like image 34
David Avatar answered Oct 30 '22 13:10

David