tags:

views:

72

answers:

2

If I have the xml/html data to post we need to encode the data to avoid the XSS validation. So should we use HTMLencode or URI encoding for this.

If URI encoding is used will it cause issues as form POST automatically URI encode all the data before sending.

+1  A: 

XSS is a problem caused by giving tainted data to the client. It can't be solved at the point where data is posted.

To protect against it, HTML encode the data (immediately) before placing it in an HTML document.

David Dorward
Thanks david, and what about uri encode ? is it ok to use it instead of HTML encode ? i mean uri encode data and then placed in the forms hidden element and decode on the server end ?
Anil Namde
That just renders it hard to read. Use HTML encoding for putting things in HTML.
David Dorward
+1  A: 

Remember: filter input, escape output.

  1. Always filter input before placing it in a database (to avoid SQL injection etc)
  2. Escape output before sending it to the client by filtering / encoding any HTML in the dynamic content.
Mathias Bynens
Umm - to avoid SQL injection, you escape the data for your database.
David Dorward
@David: That’s right. What’s your point? Should I have said “escape input, escape output” instead?
Mathias Bynens
Filter (especially when you put it next to escaping) suggests removing things from data rather than replacing them with safe equivalents. You use filtering to, for instance, stop spam being inserted into the database.
David Dorward