Skip to content

Commit

Permalink
Merge pull request markedjs#1083 from davisjam/REDOSTests
Browse files Browse the repository at this point in the history
security: fix REDOS vulnerabilities
  • Loading branch information
joshbruce committed Feb 27, 2018
2 parents fa3998a + 7ad8c11 commit a05e19e
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ block._tag = '(?!(?:'
block.html = edit(block.html)
.replace('comment', /<!--[\s\S]*?-->/)
.replace('closed', /<(tag)[\s\S]+?<\/\1>/)
.replace('closing', /<tag(?:"[^"]*"|'[^']*'|\s[^'"\/>]*)*?\/?>/)
.replace('closing', /<tag(?:"[^"]*"|'[^']*'|\s[^'"\/>\s]*)*?\/?>/)
.replace(/tag/g, block._tag)
.getRegex();

Expand Down Expand Up @@ -461,10 +461,10 @@ var inline = {
escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
url: noop,
tag: /^<!--[\s\S]*?-->|^<\/?[a-zA-Z0-9\-]+(?:"[^"]*"|'[^']*'|\s[^<'">\/]*)*?\/?>/,
tag: /^<!--[\s\S]*?-->|^<\/?[a-zA-Z0-9\-]+(?:"[^"]*"|'[^']*'|\s[^<'">\/\s]*)*?\/?>/,
link: /^!?\[(inside)\]\(href\)/,
reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
nolink: /^!?\[((?:\[[^\]]*\]|\\[\[\]]|[^\[\]])*)\]/,
nolink: /^!?\[((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\]/,
strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
em: /^_([^\s_](?:[^_]|__)+?[^\s_])_\b|^\*((?:\*\*|[^*])+?)\*(?!\*)/,
code: /^(`+)\s*([\s\S]*?[^`]?)\s*\1(?!`)/,
Expand All @@ -481,7 +481,7 @@ inline.autolink = edit(inline.autolink)
.replace('email', inline._email)
.getRegex()

inline._inside = /(?:\[[^\]]*\]|\\[\[\]]|[^\[\]]|\](?=[^\[]*\]))*/;
inline._inside = /(?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]]|\](?=[^\[]*\]))*/;
inline._href = /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;

inline.link = edit(inline.link)
Expand Down
7 changes: 6 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,13 @@ function runTests(engine, options) {
for (i = 0; i < len; i++) {
filename = filenames[i];
file = files[filename];

var before = process.hrtime();
success = testFile(engine, file, filename, i + 1);
if (success) {
var elapsed = process.hrtime(before);
var tookLessThanOneSec = (elapsed[0] === 0);

if (success && tookLessThanOneSec) {
succeeded++;
} else {
failed++;
Expand Down
File renamed without changes.
File renamed without changes.
Empty file.
1 change: 1 addition & 0 deletions test/new/redos_html_closing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<tag "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""<" />a'a
Empty file added test/new/redos_nolink.html
Empty file.
1 change: 1 addition & 0 deletions test/new/redos_nolink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
![\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]!\

0 comments on commit a05e19e

Please sign in to comment.