Passing vars from ejs to javascript (server to client on render) while avoiding XSS issues
问题 It seems like the accepted way to pass variables to JavaScript using ejs is like so: <script> var foo = <%- JSON.stringify(foo) %>; </script> But I've ran into XSS issues using this method, and wanted to know if there was a better/safer way. This example shows the vulnerability. This works since JSON.stringify("</script><script>alert('test')</script><script>") returns "</script><script>alert('test')</script><script>" and the <%- %> operators do not escape the result. It also works for objects