Skip to content

Commit a05e19e

Browse files
authored
Merge pull request markedjs#1083 from davisjam/REDOSTests
security: fix REDOS vulnerabilities
2 parents fa3998a + 7ad8c11 commit a05e19e

8 files changed

+12
-5
lines changed

lib/marked.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ block._tag = '(?!(?:'
5555
block.html = edit(block.html)
5656
.replace('comment', /<!--[\s\S]*?-->/)
5757
.replace('closed', /<(tag)[\s\S]+?<\/\1>/)
58-
.replace('closing', /<tag(?:"[^"]*"|'[^']*'|\s[^'"\/>]*)*?\/?>/)
58+
.replace('closing', /<tag(?:"[^"]*"|'[^']*'|\s[^'"\/>\s]*)*?\/?>/)
5959
.replace(/tag/g, block._tag)
6060
.getRegex();
6161

@@ -461,10 +461,10 @@ var inline = {
461461
escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
462462
autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
463463
url: noop,
464-
tag: /^<!--[\s\S]*?-->|^<\/?[a-zA-Z0-9\-]+(?:"[^"]*"|'[^']*'|\s[^<'">\/]*)*?\/?>/,
464+
tag: /^<!--[\s\S]*?-->|^<\/?[a-zA-Z0-9\-]+(?:"[^"]*"|'[^']*'|\s[^<'">\/\s]*)*?\/?>/,
465465
link: /^!?\[(inside)\]\(href\)/,
466466
reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
467-
nolink: /^!?\[((?:\[[^\]]*\]|\\[\[\]]|[^\[\]])*)\]/,
467+
nolink: /^!?\[((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\]/,
468468
strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
469469
em: /^_([^\s_](?:[^_]|__)+?[^\s_])_\b|^\*((?:\*\*|[^*])+?)\*(?!\*)/,
470470
code: /^(`+)\s*([\s\S]*?[^`]?)\s*\1(?!`)/,
@@ -481,7 +481,7 @@ inline.autolink = edit(inline.autolink)
481481
.replace('email', inline._email)
482482
.getRegex()
483483

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

487487
inline.link = edit(inline.link)

test/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,13 @@ function runTests(engine, options) {
110110
for (i = 0; i < len; i++) {
111111
filename = filenames[i];
112112
file = files[filename];
113+
114+
var before = process.hrtime();
113115
success = testFile(engine, file, filename, i + 1);
114-
if (success) {
116+
var elapsed = process.hrtime(before);
117+
var tookLessThanOneSec = (elapsed[0] === 0);
118+
119+
if (success && tookLessThanOneSec) {
115120
succeeded++;
116121
} else {
117122
failed++;
File renamed without changes.
File renamed without changes.

test/new/redos_html_closing.html

Whitespace-only changes.

test/new/redos_html_closing.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<tag "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""<" />a'a

test/new/redos_nolink.html

Whitespace-only changes.

test/new/redos_nolink.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
![\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]!\

0 commit comments

Comments
 (0)