Skip to content

Commit 23abded

Browse files
Fix GHSL-2022-099: avoid quadratic behavior triggered by urls with underscores.
1 parent 6a6e335 commit 23abded

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

extensions/autolink.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,17 @@ static size_t check_domain(uint8_t *data, size_t size, int allow_short) {
127127
break;
128128
}
129129

130-
if (uscore1 > 0 || uscore2 > 0)
131-
return 0;
130+
if (uscore1 > 0 || uscore2 > 0) {
131+
/* If the url is very long then accept it despite the underscores,
132+
* to avoid quadratic behavior causing a denial of service. See:
133+
* https://github.com/github/cmark-gfm/security/advisories/GHSA-29g3-96g3-jg6c
134+
* Reasonable urls are unlikely to have more than 10 segments, so
135+
* this extra condition shouldn't have any impact on normal usage.
136+
*/
137+
if (np <= 10) {
138+
return 0;
139+
}
140+
}
132141

133142
if (allow_short) {
134143
/* We don't need a valid domain in the strict sense (with

0 commit comments

Comments
 (0)