
Ensuring Input Safety | 207
ASP.NET
Security
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
since it is likely this input will later be displayed by the application such that the
script will be executed.
Request Validation
To solve the majority of problems with input safety, the ASP.NET team added a
new feature to Version 1.1 of the .NET Framework called request validation.
Request validation, which is enabled by default in ASP.NET 1.1, automatically
checks all forms of input in the Request object for HTML characters, or content,
and raises an exception if such content is found.
You should never turn off request validation unless you need to
allow users to provide HTML input, and you have provided your
own filtering or input checking logic. It is also important to always
filter out anything other than the expected input. If you attempt
only to filter out known dangerous content, you will most certainly
miss something.
Request validation is enabled at the machine level through the validateRequest
attribute of the <pages> element in machine.config. You can disable request vali-
dation at the application level by adding a
<pages> element to the application’s
web.config file with the
validateRequest attribute set to False. You can disable
request validation at the page level by adding the
validateRequest attribute to
the
@ Page directive, with ...