Skip to content

Commit f052a2c

Browse files
committed
security: fix unsafe heading regex
Problem: REDOS could be triggered through exploitation of the 'heading' regex. Solution: Refactor regex. It matches the same language as before but is less vulnerable to REDOS. It is now safe using the bounds suggested by those disclosing it. It remains super-linear but a successful exploit requires a much longer attack string. Fixes: Issue disclosed privately. Credit: This issue was pointed out by Nick Starke and Adam Cazzolla of Sonatype Security research.
1 parent 3130e62 commit f052a2c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/marked.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var block = {
1616
code: /^( {4}[^\n]+\n*)+/,
1717
fences: noop,
1818
hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
19-
heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,
19+
heading: /^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/,
2020
nptable: noop,
2121
blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
2222
list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,

0 commit comments

Comments
 (0)