Skip to content

Commit

Permalink
Merge pull request #592 from matt-/xss_html_entities
Browse files Browse the repository at this point in the history
XSS with HTML entities
  • Loading branch information
matt- authored Jul 29, 2016
2 parents 88ce4df + 0fa05b6 commit fd0d1a2
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 fd0d1a2

Please sign in to comment.