tags:

views:

232

answers:

2

Hi folks:

We got a long-running website where XSS lurks. The problem comes from that some developers directly - without using HtmlEncode/Decode() - retrieve Request["sth"] to do the process, putting on the web.

I wonder if there is any mechanism like HTTPModule to help us HtmlEncode() all the items in a Http request to avoid XSS to some extent.

Appreciate for any suggestion.

Rgds, Ricky

+1  A: 

The problem is not retrieving Request data without HTML-encoding. In fact that's perfectly correct. You should not encode any text until the final output stage when you spit it into an HTML page.

Trying to blanket-encode incoming parameters, whether that's HTML-encoding or SQL-encoding, is totally the wrong thing. It may hide XSS holes in your app but it does not fix them. You will still have a hole if you output content that hasn't come from parameters, or has been processed since then. Meanwhile the automatic encoding will fill your database with multiply-escaped & crud.

You need to fix the output stage, that's where the problem lies.

bobince
Is there off-the-shelf solution prevent XSS in a universal way for a web site?
Ricky
No(*). There is no magic bullet, XSS can only be corrected by fixing the actual bugs. There are tools that will test your site by submitting HTML to every parameter they can find and seeing if they end up back on the page without encoding; these aren't completely foolproof either but they can give you some clues as to what areas of your code need looking at.
bobince
*: well technically yes. There are options to block or filter all incoming data for HTML, for example ASP.NET's default-on “Request Validation” feature. But they're utterly bogus and don't really protect you from the root problem of missing output-escaping, whilst also breaking your application whenever the user submits something that looks like an HTML or XML tag. This is only really of use as a temporary band-aid on a live site whilst you fix the errors in it.
bobince
A: 

Like bobince said, this is an output problem, not an input problem. If you can isolate where this data is being output on the page, you could create a Filter and add it to the Response object. This filter would isolate the areas that are common output and then HtmlEncode them.

Mike J
Is there off-the-shelf solution preventing XSS in a universal way for a web site?
Ricky