In ASP.NET MVC views, it is typical to bind model values using Razor's syntax:
@Html.DisplayFor(m => m.Name)
We know that Razor will html encode the value by default. But imagine a malicious user inputting scripts in a textbox and submitting it:
<script>alert('Executing evil script')</script>
Now if we do not use the [ValidateInput(false)]
or [AllowHtml]
attributes, we will be hit with a HttpRequestValidationException
which means this exception have to be caught every time a user submits a form.
From the answer in another stackoverflow question, I know we can disable request validation on an application level but many are suggesting this is a bad practice.
My question is, given we have Razor to escape all >
and <
, can we assume the site will still be secure if we turn off request validation?