I am working on a website that currently is vulnerable to XSS attacks. As I read about it, the best way to prevent it is to:
- Validate any user inputs.
- Sanitize and escape any strings that are to be displayed on web pages.
For point no: 1, I am validating user inputs both at client side (JS) and just before data persists into the database.
For point no: 2, I am not so sure. Should I sanitize and escape strings as I add them to MVC objects before sending them to the JSP? The problem I see with this approach is that there are simply too many objects with string parameters, and sanitizing each of them would be a pain.
What's the best approach SO suggests?
Thanks!