I am working on some one page apps coded in JavaScript that currently use lodash. I would like to prevent Cross Site Scripting (XSS) using a standard library by:
1) Escaping all untrusted content
2) Encoding output depending on its destination CSS, HTML, HTMLAttribute JavaScript, JSON etc
I have seen a number of stack overflow answers but they don't provide a complete canonicalization / encoding solution in a standard library that I can write static test to make sure developers are using the library.
Is there an esapi or similar "light" library that I can use just for JavaScript?
I have seen the OWASP Esapi and the jQuery Encoder Plugin https://github.com/chrisisbeef/jquery-encoder and the SalesForce Encoder https://github.com/salesforce/secure-filters
At this moment I'm only interested canonicalizing input and encoding output. I'm also looking for something current, well maintained and ideally not dependent on other libraries.
Can anyone suggest the best approach to use?