Question

First time AntiXSS 4 user here. In order to make my application more secure, I've used Microsoft.Security.Application.Encoder.UrlEncode on QueryString parameters and Microsoft.Security.Application.Encoder.HtmlEncode on a parameter entered into a form field.

I have a multiple and I would appreciate it if you could try to answer all of them (doesn't have to be at once or by the same person - any abswers at all would be very helpful).

My first question is am I using these methods appropriately (that is am I using an appropriate AntiXSS method for an appropriate situation)?

My second question is once I've encoded something, should it ever be decoded. I am confused because I know that HttpUtility class provides ways to both encode and decode so why isn't the same done in AntiXSS? If this helps, the parameters that I've encoded are never going to be treated as anything other then text inside the application.

My third question is related to the third one but I wanted to emphasize it because it's important (and is probably the source of my overall confusion). I've heard that the .NET framework automatically decodes things like QueryStrings, hence no no need for explicit decode method. If that is so, then what is the point of HTML encoding something in the first place if it is going to be undone. It just... doesn't seem safe? What am I missing, especially since, as mentioned the HttpUtility class provides for decoding.

And the last question, does AntiXSS help against SQL injection at all or does it only protext against XSS attacks?

Was it helpful?

Solution

  1. It's hard to say if you're using it correctly. If you use UrlEncode when building a query string which is then output as a link in a page then yes that's correct. If you're Html Encoding when you write something out as a value then yes, that's correct (well kind of, if it's set via an HTML attribute you ought to use HtmlAttributeEncode, but they're pretty much the same.)

  2. The .NET decoders work with AntiXSS's encoded values, so there was no point in me rewriting them grin

  3. The point of encoding is that you do it when you output. So, for example, if a user has, on a form, input window.alert('Numpty!) and you just put that input raw in your output the javascript would run. If you encoded it first you would see < become &lt; and so on.

  4. No, SQL injection is an entirely different problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top