diff options
author | Ryan Grove <ryan@wonko.com> | 2011-04-25 11:14:26 -0700 |
---|---|---|
committer | Ryan Grove <ryan@wonko.com> | 2011-04-25 11:15:53 -0700 |
commit | b291a1ad8c9a33f834d126450635f0b6ca546a0c (patch) | |
tree | 43c069a0191d49bef40f054a7c0cff9e77f26ef1 /lib/handlebars/utils.js | |
parent | 038d9b3feed51bc12db95af0e0ef8b69776b42c9 (diff) | |
download | handlebars.js-b291a1ad8c9a33f834d126450635f0b6ca546a0c.zip handlebars.js-b291a1ad8c9a33f834d126450635f0b6ca546a0c.tar.gz handlebars.js-b291a1ad8c9a33f834d126450635f0b6ca546a0c.tar.bz2 |
Add ", ', and / to the list of chars that need HTML escaping.
Previously, only < and > were escaped. This meant that any Handlebars
template that used user input in an HTML attribute value was wide open
to a trivial XSS exploit. Note that unquoted attribute values are still
open to attack, but this set of characters at least brings Handlebars in
line with other Mustache implementations and other template languages.
See the OWASP XSS prevention cheat sheet (rule #1) for the rationale
behind escaping these characters:
https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet
Diffstat (limited to 'lib/handlebars/utils.js')
-rw-r--r-- | lib/handlebars/utils.js | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/handlebars/utils.js b/lib/handlebars/utils.js index 981bb1f..1584986 100644 --- a/lib/handlebars/utils.js +++ b/lib/handlebars/utils.js @@ -16,11 +16,14 @@ Handlebars.SafeString.prototype.toString = function() { (function() { var escape = { "<": "<", - ">": ">" + ">": ">", + '"': """, + "'": "'", + "/": "/" }; - var badChars = /&(?!\w+;)|[<>]/g; - var possible = /[&<>]/ + var badChars = /&(?!\w+;)|[<>"'\/]/g; + var possible = /[&<>"'\/]/; var escapeChar = function(chr) { return escape[chr] || "&" |