Просмотр исходного кода

Improve HTML escaping.

This closes a couple of potential exploit scenarios.
Backtick (`) for older IEs and equals (=) for unquoted attributes.

Refs 83b8e846a3
Closes https://github.com/janl/mustache.js/pull/388
tags/v2.2.1
Phillip Johnsen 10 лет назад
Родитель
Сommit
378bcca8a5
3 измененных файлов: 6 добавлений и 4 удалений
  1. +4
    -2
      mustache.js
  2. +1
    -1
      test/_files/escaped.js
  3. +1
    -1
      test/_files/escaped.txt

+ 4
- 2
mustache.js Просмотреть файл

@@ -63,11 +63,13 @@
'>': '>',
'"': '"',
"'": ''',
'/': '/'
'/': '/',
'`': '`',
'=': '='
};

function escapeHtml (string) {
return String(string).replace(/[&<>"'\/]/g, function fromEntityMap (s) {
return String(string).replace(/[&<>"'`=\/]/g, function fromEntityMap (s) {
return entityMap[s];
});
}


+ 1
- 1
test/_files/escaped.js Просмотреть файл

@@ -2,5 +2,5 @@
title: function () {
return "Bear > Shark";
},
entities: "&quot; \"'<>/"
entities: "&quot; \"'<>`=/"
})

+ 1
- 1
test/_files/escaped.txt Просмотреть файл

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

Загрузка…
Отмена
Сохранить