Skip to content

Commit 0ee3aa9

Browse files
authored
Merge pull request #1515 from UziTech/link-label-security
Link label security
2 parents cc9efe4 + e987a4d commit 0ee3aa9

File tree

6 files changed

+20
-16
lines changed

6 files changed

+20
-16
lines changed

lib/marked.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ var inline = {
542542
+ '|^<\\?[\\s\\S]*?\\?>' // processing instruction, e.g. <?php ?>
543543
+ '|^<![a-zA-Z]+\\s[\\s\\S]*?>' // declaration, e.g. <!DOCTYPE html>
544544
+ '|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>', // CDATA section
545-
link: /^!?\[(label)\]\(href(?:\s+(title))?\s*\)/,
545+
link: /^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,
546546
reflink: /^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,
547547
nolink: /^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,
548548
strong: /^__([^\s_])__(?!_)|^\*\*([^\s*])\*\*(?!\*)|^__([^\s][\s\S]*?[^\s])__(?!_)|^\*\*([^\s][\s\S]*?[^\s])\*\*(?!\*)/,
@@ -574,8 +574,8 @@ inline.tag = edit(inline.tag)
574574
.replace('attribute', inline._attribute)
575575
.getRegex();
576576

577-
inline._label = /(?:\[[^\[\]]*\]|\\[\[\]]?|`[^`]*`|`(?!`)|[^\[\]\\`])*?/;
578-
inline._href = /\s*(<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*)/;
577+
inline._label = /(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
578+
inline._href = /<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/;
579579
inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/;
580580

581581
inline.link = edit(inline.link)

test/specs/commonmark/commonmark.0.29.json

+3-6
Original file line numberDiff line numberDiff line change
@@ -2775,8 +2775,7 @@
27752775
"example": 342,
27762776
"start_line": 6012,
27772777
"end_line": 6016,
2778-
"section": "Code spans",
2779-
"shouldFail": true
2778+
"section": "Code spans"
27802779
},
27812780
{
27822781
"markdown": "`<a href=\"`\">`\n",
@@ -4266,8 +4265,7 @@
42664265
"example": 521,
42674266
"start_line": 7887,
42684267
"end_line": 7891,
4269-
"section": "Links",
4270-
"shouldFail": true
4268+
"section": "Links"
42714269
},
42724270
{
42734271
"markdown": "[foo<http://example.com/?search=](uri)>\n",
@@ -4368,8 +4366,7 @@
43684366
"example": 533,
43694367
"start_line": 8041,
43704368
"end_line": 8047,
4371-
"section": "Links",
4372-
"shouldFail": true
4369+
"section": "Links"
43734370
},
43744371
{
43754372
"markdown": "[foo<http://example.com/?search=][ref]>\n\n[ref]: /uri\n",

test/specs/gfm/commonmark.0.29.json

+3-6
Original file line numberDiff line numberDiff line change
@@ -2775,8 +2775,7 @@
27752775
"example": 342,
27762776
"start_line": 6012,
27772777
"end_line": 6016,
2778-
"section": "Code spans",
2779-
"shouldFail": true
2778+
"section": "Code spans"
27802779
},
27812780
{
27822781
"markdown": "`<a href=\"`\">`\n",
@@ -4266,8 +4265,7 @@
42664265
"example": 521,
42674266
"start_line": 7887,
42684267
"end_line": 7891,
4269-
"section": "Links",
4270-
"shouldFail": true
4268+
"section": "Links"
42714269
},
42724270
{
42734271
"markdown": "[foo<http://example.com/?search=](uri)>\n",
@@ -4368,8 +4366,7 @@
43684366
"example": 533,
43694367
"start_line": 8041,
43704368
"end_line": 8047,
4371-
"section": "Links",
4372-
"shouldFail": true
4369+
"section": "Links"
43734370
},
43744371
{
43754372
"markdown": "[foo<http://example.com/?search=][ref]>\n\n[ref]: /uri\n",

test/specs/new/nested_square_link.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[the `]` character](/url)
22

3-
[the ` character](/url)
3+
[the \` character](/url)

test/specs/redos/link_code.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>INDEX(string, pattern[, start)<code>: searches for the first occurrence of pattern in string, starting from start:</code>INDEX(&quot;123123&quot;, &quot;23&quot;, 3)<code>==</code>5<code></code>INSERT(new, old[, start][, length][, pad])<code>: inserts the new string into the old string after the specified position (default is 0), new string is truncated or padded (default is &quot; &quot;) to the specified length, if start is beyond the end of old old will be padded</code>LASTPOS(pattern, string[, start])<code>: searches backwards for the last occurrence of pattern in string, starting from start:</code>LASTPOS(&quot;123123&quot;, &quot;23&quot;, 4)<code>==</code>2<code></code>LINES(file)<code>: returns the number of lines typed ahead at the interactive stream:</code>push(&quot;a line&quot;); push(&quot;second line&quot;); lines(STDIN); /* == 2 */<code></code>MAX(number, number[, number,...])<code>: obvious</code>MIN(number, number[, number,...])<code>: obvious</code>OPEN(filehandle, filename[, &quot;APPEND&quot;|&quot;READ&quot;|&quot;WRITE&quot;])<code>: opens file, returns boolean for success:</code>OPEN(&quot;MyCon&quot;, &quot;CON:160/50/320/100/MyCon/CDS&quot;)<code>==</code>1<code></code>OVERLAY(new, old[, start][, length][, pad])<code>: overlays new string onto old one at start for length chars padding with pad if necessary:</code>OVERLAY(&quot;4&quot;, &quot;123&quot;, 5, 5)<code>==</code>&quot;123-4----&quot;<code></code>POS(pattern, string[, start])` : same as index</p>

test/specs/redos/link_code.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
INDEX(string, pattern[, start)` : searches for the first occurrence of pattern in string, starting from start: `INDEX("123123", "23", 3)` == `5`
2+
`INSERT(new, old[, start][, length][, pad])` : inserts the new string into the old string after the specified position (default is 0), new string is truncated or padded (default is " ") to the specified length, if start is beyond the end of old old will be padded
3+
`LASTPOS(pattern, string[, start])` : searches backwards for the last occurrence of pattern in string, starting from start: `LASTPOS("123123", "23", 4)` == `2`
4+
`LINES(file)` : returns the number of lines typed ahead at the interactive stream: `push("a line"); push("second line"); lines(STDIN); /* == 2 */`
5+
`MAX(number, number[, number,...])` : obvious
6+
`MIN(number, number[, number,...])` : obvious
7+
`OPEN(filehandle, filename[, "APPEND"|"READ"|"WRITE"])` : opens file, returns boolean for success: `OPEN("MyCon", "CON:160/50/320/100/MyCon/CDS")` == `1`
8+
`OVERLAY(new, old[, start][, length][, pad])` : overlays new string onto old one at start for length chars padding with pad if necessary: `OVERLAY("4", "123", 5, 5)` == `"123-4----"`
9+
`POS(pattern, string[, start])` : same as index

0 commit comments

Comments
 (0)