I need to review quite a large .Net 4.0 project and re-factor to prevent XSS attacks. The first thing I did was to turn on requestValidation
for the site, is there anything else I can do at a global level or is this going to be a case of trawling through every page, validating input and html encoding the output.
There are lots of pages, and probably 300 classic asp pages still in use.
Is HtmlEncode() safe to use or do I need to install Microsofts AntiXSS package.
requestValidation
is a good approach.At a global level one more thing I can think of is enabling X-XSS-Protection header at all http responses. It is easy to implement and gives you some native defences that the browser (IE 8+, Chrome) has to offer based on xss patterns.
X-XSS-Protection: 1; mode=block
You may look at Content-Security-Policy, but I think in your scenario it may be a big roll out for the entire site.
Those are something I could think of from a HTTP header based XSS mitigations. They are generic and does not apply just to ASP.Net.
Answering your other question
Is HtmlEncode() safe to use or do I need to install Microsofts AntiXSS package
from What is the benefit to make encoderType to AntiXssEncoder in a MVC application?