Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added data: and vbscript: link fix to prevent XSS vulnerability #63

Merged
merged 1 commit into from Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 54 additions & 0 deletions __tests__/simple-markdown-test.js
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
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