Skip to content

Commit 378bcca

Browse files
committed
Improve HTML escaping.
This closes a couple of potential exploit scenarios. Backtick (`) for older IEs and equals (=) for unquoted attributes. Refs handlebars-lang/handlebars.js@83b8e84 Closes #388
1 parent 53b1c95 commit 378bcca

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

mustache.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,13 @@
6363
'>': '>',
6464
'"': '"',
6565
"'": ''',
66-
'/': '/'
66+
'/': '/',
67+
'`': '`',
68+
'=': '='
6769
};
6870

6971
function escapeHtml (string) {
70-
return String(string).replace(/[&<>"'\/]/g, function fromEntityMap (s) {
72+
return String(string).replace(/[&<>"'`=\/]/g, function fromEntityMap (s) {
7173
return entityMap[s];
7274
});
7375
}

test/_files/escaped.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
title: function () {
33
return "Bear > Shark";
44
},
5-
entities: "&quot; \"'<>/"
5+
entities: "&quot; \"'<>`=/"
66
})

test/_files/escaped.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<h1>Bear &gt; Shark</h1>
2-
And even &amp;quot; &quot;&#39;&lt;&gt;&#x2F;, but not &quot; "'<>/.
2+
And even &amp;quot; &quot;&#39;&lt;&gt;&#x60;&#x3D;&#x2F;, but not &quot; "'<>`=/.

0 commit comments

Comments
 (0)