Skip to content

Commit 4625980

Browse files
CopilotUziTech
andauthored
fix: Fix catastrophic backtracking (ReDoS) in link/reflink label regex (#3918)
Co-authored-by: UziTech <97994+UziTech@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent 5e03369 commit 4625980

File tree

3 files changed

+3
-1
lines changed

3 files changed

+3
-1
lines changed

src/rules.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ const tag = edit(
373373
.replace('attribute', /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/)
374374
.getRegex();
375375

376-
const _inlineLabel = /(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/;
376+
const _inlineLabel = /(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/;
377377

378378
const link = edit(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/)
379379
.replace('label', _inlineLabel)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>[<code>code0</code> <code>code1</code> <code>code2</code> <code>code3</code> <code>code4</code> <code>code5</code> <code>code6</code> <code>code7</code> <code>code8</code> <code>code9</code> <code>code10</code> <code>code11</code> <code>code12</code> <code>code13</code> <code>code14</code></p>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[````code0```` ````code1```` ````code2```` ````code3```` ````code4```` ````code5```` ````code6```` ````code7```` ````code8```` ````code9```` ````code10```` ````code11```` ````code12```` ````code13```` ````code14````

0 commit comments

Comments
 (0)