Skip to content

Commit 287dfbf

Browse files
dominykasTrySound
authored andcommitted
Prevent a ReDoS vulnerability (#335)
fix: prevent a ReDoS vulnerability Ported from markdown-it/markdown-it@89c8620. fix: prevent ReDoS with comments Once again - prior art: markdown-it/markdown-it@6ab7cc3 Hat tip @DanCech #335 (comment) for pointing out #331 (comment), which I missed initially
1 parent 49e87b7 commit 287dfbf

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/common/html_re.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ var open_tag = replace(/<[A-Za-z][A-Za-z0-9]*attribute*\s*\/?>/)
4141
();
4242

4343
var close_tag = /<\/[A-Za-z][A-Za-z0-9]*\s*>/;
44-
var comment = /<!--([^-]+|[-][^-]+)*-->/;
44+
var comment = /<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->/;
4545
var processing = /<[?].*?[?]>/;
4646
var declaration = /<![A-Z]+\s+[^>]*>/;
47-
var cdata = /<!\[CDATA\[([^\]]+|\][^\]]|\]\][^>])*\]\]>/;
47+
var cdata = /<!\[CDATA\[[\s\S]*?\]\]>/;
4848

4949
var HTML_TAG_RE = replace(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/)
5050
('open_tag', open_tag)

test/fixtures/remarkable/redos.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.
2+
<a>ReDoS</a><![CDATA[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa]] >
3+
.
4+
<p><a>ReDoS</a>&lt;![CDATA[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa]] &gt;</p>
5+
.
6+
7+
.
8+
<a>z</a><!--aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa--->
9+
.
10+
<p><a>z</a>&lt;!–aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa—&gt;</p>
11+
.

0 commit comments

Comments
 (0)