Skip to content

Commit

Permalink
Added data: and vbscript: link fix to prevent XSS vulnerability
Browse files Browse the repository at this point in the history
  • Loading branch information
jedixak authored and ariabuckles committed Mar 14, 2019
1 parent 74c304d commit 8ad751f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
54 changes: 54 additions & 0 deletions __tests__/simple-markdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3341,6 +3341,34 @@ describe("simple markdown", function() {
html2,
"<div class=\"paragraph\"><a>link</a></div>"
);

var html3 = htmlFromReactMarkdown(
"[link](data:text/html;base64,PHNjcmlwdD5hbGVydCgnaGknKTwvc2NyaXB0Pg==)"
);
assert.strictEqual(html3, "<a>link</a>");

var html4 = htmlFromReactMarkdown(
"[link][1]\n\n" +
"[1]: data:text/html;base64,PHNjcmlwdD5hbGVydCgnaGknKTwvc2NyaXB0Pg==\n\n"
);
assert.strictEqual(
html4,
"<div class=\"paragraph\"><a>link</a></div>"
);

var html5 = htmlFromReactMarkdown(
"[link](vbscript:alert)"
);
assert.strictEqual(html5, "<a>link</a>");

var html6 = htmlFromReactMarkdown(
"[link][1]\n\n" +
"[1]: vbscript:alert\n\n"
);
assert.strictEqual(
html6,
"<div class=\"paragraph\"><a>link</a></div>"
);
});

it("should not sanitize safe links", function() {
Expand Down Expand Up @@ -3711,6 +3739,32 @@ describe("simple markdown", function() {
markdown2,
"<div class=\"paragraph\"><a>link</a></div>"
);

var markdown3 = "[link](data:text/html;base64,PHNjcmlwdD5hbGVydCgnaGknKTwvc2NyaXB0Pg==)";
assertParsesToHtml(
markdown3,
"<a>link</a>"
);

var markdown4 = "[link][1]\n\n" +
"[1]: data:text/html;base64,PHNjcmlwdD5hbGVydCgnaGknKTwvc2NyaXB0Pg==\n\n";
assertParsesToHtml(
markdown4,
"<div class=\"paragraph\"><a>link</a></div>"
);

var markdown5 = "[link](vbscript:alert)";
assertParsesToHtml(
markdown5,
"<a>link</a>"
);

var markdown6 = "[link][1]\n\n" +
"[1]: vbscript:alert\n\n";
assertParsesToHtml(
markdown6,
"<div class=\"paragraph\"><a>link</a></div>"
);
});

it("should not sanitize safe links", function() {
Expand Down
2 changes: 1 addition & 1 deletion simple-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ var sanitizeUrl = function(url /* : ?string */) {
var prot = decodeURIComponent(url)
.replace(/[^A-Za-z0-9/:]/g, '')
.toLowerCase();
if (prot.indexOf('javascript:') === 0) {
if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) {
return null;
}
} catch (e) {
Expand Down

0 comments on commit 8ad751f

Please sign in to comment.