Skip to content

Commit

Permalink
added explicit matching for HTML entities to prevent XSS
Browse files Browse the repository at this point in the history
  • Loading branch information
matt- committed May 19, 2015
1 parent 49b7eac commit 2cff859
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,8 @@ function escape(html, encode) {
}

function unescape(html) {
return html.replace(/&([#\w]+);/g, function(_, n) {
// explicitly match decimal, hex, and named HTML entities
return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(\w+))/g, function(_, n) {
n = n.toLowerCase();
if (n === 'colon') return ':';
if (n.charAt(0) === '#') {
Expand Down
4 changes: 4 additions & 0 deletions test/tests/links.sanitize.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<p></p>
<p></p>
<p></p>
<p></p>
7 changes: 7 additions & 0 deletions test/tests/links.sanitize.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[URL](javascript:alert)

[URL](vbscript:alert)

[URL](javascript&colon;alert&#40;1&#41;)

[URL](javascript&#58document;alert&#40;1&#41;)

0 comments on commit 2cff859

Please sign in to comment.