HandlebarsJS-helpers
HandlebarsJS-helpers copied to clipboard
Security
By not escaping the input to the helpers, you're opening up for the newly constructed string to include XSS. For example, <scr\nipt>
will become <script>
, no? Since you're returning a SafeString, it won't be escaped.
See http://handlebarsjs.com/ and search for "Handlebars will not escape a".
Thanks for noticing but in most cases SafeString is returned on purpose and I believe that escaping is in developer responsibilities. The best approach here I think would be optional arguments for escaping/not escaping. Or maybe i misunderstand something ?
If I'm running {{truncate variable 25}}
and that variable has HTML in it, that HTML will be parsed by the browser, thus not escaped. That is insecure.
If I'm running {{variable}}
and that variable has HTML in it, that HTML will be NOT parsed by the browser, thus it is escaped. That is secure.
I don't see how this should be the dev's responsibility. If I wanted it unescaped, I'd use triple-quotes instead. Don't know how that works with helpers, though.