Skip to content

Commit d4e4bc6

Browse files
author
Esben Sparre Andreasen
committed
JS: sharpen js/incomplete-url-regexp by not matching .* or .+
1 parent c65c7e7 commit d4e4bc6

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

javascript/ql/src/Security/CWE-020/IncompleteUrlRegExp.ql

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@ bindingset[pattern]
4343
predicate isIncompleteHostNameRegExpPattern(string pattern, string hostPart) {
4444
hostPart = pattern.regexpCapture(
4545
"(?i).*" +
46-
// Either:
47-
// - an unescaped and repeated `.`, followed by anything
48-
// - a unescaped single `.`
49-
"(?:(?<!\\\\)[.][+*].*?|(?<!\\\\)[.])" +
50-
// a sequence of subdomains, perhaps with some regex characters mixed in, followed by a known TLD
46+
// an unescaped single `.`
47+
"(?<!\\\\)[.]" +
48+
// immediately followed by a sequence of subdomains, perhaps with some regex characters mixed in, followed by a known TLD
5149
"([():|?a-z0-9-]+(\\\\)?[.](com|org|edu|gov|uk|net))" +
5250
".*", 1)
5351
}

javascript/ql/test/query-tests/Security/CWE-020/IncompleteUrlRegExp.expected

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
| tst-IncompleteUrlRegExp.js:3:2:3:28 | /http:\\ ... le.com/ | This regular expression has an unescaped '.', which means that 'example.com' might not match the intended host of a matched URL. |
22
| tst-IncompleteUrlRegExp.js:5:2:5:28 | /http:\\ ... le.net/ | This regular expression has an unescaped '.', which means that 'example.net' might not match the intended host of a matched URL. |
33
| tst-IncompleteUrlRegExp.js:6:2:6:42 | /http:\\ ... b).com/ | This regular expression has an unescaped '.', which means that '(example-a\|example-b).com' might not match the intended host of a matched URL. |
4-
| tst-IncompleteUrlRegExp.js:7:2:7:30 | /http:\\ ... le.com/ | This regular expression has an unescaped '.', which means that 'example.com' might not match the intended host of a matched URL. |
5-
| tst-IncompleteUrlRegExp.js:9:2:9:39 | /http:\\ ... le.com/ | This regular expression has an unescaped '.', which means that 'example.com' might not match the intended host of a matched URL. |
64
| tst-IncompleteUrlRegExp.js:11:13:11:37 | "http:/ ... le.com" | This regular expression has an unescaped '.', which means that 'example.com' might not match the intended host of a matched URL. |
75
| tst-IncompleteUrlRegExp.js:12:10:12:34 | "http:/ ... le.com" | This regular expression has an unescaped '.', which means that 'example.com' might not match the intended host of a matched URL. |
86
| tst-IncompleteUrlRegExp.js:15:22:15:46 | "http:/ ... le.com" | This regular expression has an unescaped '.', which means that 'example.com' might not match the intended host of a matched URL. |
@@ -11,7 +9,6 @@
119
| tst-IncompleteUrlRegExp.js:19:17:19:34 | 'test.example.com' | This regular expression has an unescaped '.', which means that 'example.com' might not match the intended host of a matched URL. |
1210
| tst-IncompleteUrlRegExp.js:22:27:22:44 | 'test.example.com' | This regular expression has an unescaped '.', which means that 'example.com' might not match the intended host of a matched URL. |
1311
| tst-IncompleteUrlRegExp.js:28:22:28:39 | 'test.example.com' | This regular expression has an unescaped '.', which means that 'example.com' might not match the intended host of a matched URL. |
14-
| tst-IncompleteUrlRegExp.js:36:2:36:37 | /(.+\\.( ... \\.com)/ | This regular expression has an unescaped '.', which means that '(?:example-a\|example-b)\\.com' might not match the intended host of a matched URL. |
1512
| tst-IncompleteUrlRegExp.js:37:2:37:54 | /^(http ... =$\|\\/)/ | This regular expression has an unescaped '.', which means that ')?example.com' might not match the intended host of a matched URL. |
1613
| tst-IncompleteUrlRegExp.js:38:2:38:44 | /^(http ... p\\/f\\// | This regular expression has an unescaped '.', which means that 'example.com' might not match the intended host of a matched URL. |
1714
| tst-IncompleteUrlRegExp.js:39:2:39:34 | /\\(http ... m\\/\\)/g | This regular expression has an unescaped '.', which means that 'example.com' might not match the intended host of a matched URL. |

javascript/ql/test/query-tests/Security/CWE-020/tst-IncompleteUrlRegExp.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
/http:\/\/test\\.example.com/; // OK
55
/http:\/\/test.example.net/; // NOT OK
66
/http:\/\/test.(example-a|example-b).com/; // NOT OK
7-
/http:\/\/(.+)\\.example.com/; // NOT OK
7+
/http:\/\/(.+)\\.example.com/; // NOT OK, but not yet supported with enough precision
88
/http:\/\/(\\.+)\\.example.com/; // OK
9-
/http:\/\/(?:.+)\\.test\\.example.com/; // NOT OK
9+
/http:\/\/(?:.+)\\.test\\.example.com/; // NOT OK, but not yet supported with enough precision
1010
/http:\/\/test.example.com\/(?:.*)/; // OK
1111
new RegExp("http://test.example.com"); // NOT OK
1212
s.match("http://test.example.com"); // NOT OK
@@ -33,7 +33,7 @@
3333
}
3434
domains.map(d => convert(d));
3535

36-
/(.+\.(?:example-a|example-b)\.com)/; // NOT OK
36+
/(.+\.(?:example-a|example-b)\.com)/; // NOT OK, but not yet supported with enough precision
3737
/^(https?:)?\/\/((service|www).)?example.com(?=$|\/)/; // NOT OK
3838
/^(http|https):\/\/www.example.com\/p\/f\//; // NOT OK
3939
/\(http:\/\/sub.example.com\/\)/g; // NOT OK

0 commit comments

Comments
 (0)