Skip to content

Commit 4f53411

Browse files
author
Esben Sparre Andreasen
committed
JS: recognize HTTP URLs in js/incomplete-url-sanitization
1 parent 56fb63a commit 4f53411

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ where
1919
call.getMethodName() = name and
2020
substring = call.getArgument(0) and
2121
substring.mayHaveStringValue(target) and
22-
// target contains a domain on a common TLD, and perhaps some other URL components
23-
target.regexpMatch("(?i)([a-z]*:?//)?\\.?([a-z0-9-]+\\.)+(com|org|edu|gov|uk|net)(:[0-9]+)?/?") and
22+
(
23+
// target contains a domain on a common TLD, and perhaps some other URL components
24+
target.regexpMatch("(?i)([a-z]*:?//)?\\.?([a-z0-9-]+\\.)+(com|org|edu|gov|uk|net)(:[0-9]+)?/?") or
25+
// target is a HTTP URL to a domain on any TLD
26+
target.regexpMatch("(?i)https?://([a-z0-9-]+\\.)+([a-z]+)(:[0-9]+)?/?")
27+
) and
2428
// whitelist
2529
not (
2630
name = "indexOf" and

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
| tst-IncompleteUrlSubstringSanitization.js:32:5:32:35 | x.index ... e.com") | '$@' may be at an arbitrary position in the sanitized URL. | tst-IncompleteUrlSubstringSanitization.js:32:15:32:34 | "https://secure.com" | https://secure.com |
1111
| tst-IncompleteUrlSubstringSanitization.js:33:5:33:39 | x.index ... m:443") | '$@' may be at an arbitrary position in the sanitized URL. | tst-IncompleteUrlSubstringSanitization.js:33:15:33:38 | "https: ... om:443" | https://secure.com:443 |
1212
| tst-IncompleteUrlSubstringSanitization.js:34:5:34:36 | x.index ... .com/") | '$@' may be at an arbitrary position in the sanitized URL. | tst-IncompleteUrlSubstringSanitization.js:34:15:34:35 | "https: ... e.com/" | https://secure.com/ |
13+
| tst-IncompleteUrlSubstringSanitization.js:52:5:52:41 | x.index ... ernal") | '$@' may be at an arbitrary position in the sanitized URL. | tst-IncompleteUrlSubstringSanitization.js:52:15:52:40 | "https: ... ternal" | https://example.internal |

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,7 @@
4848

4949
x.indexOf("tar.gz") + offset // OK
5050
x.indexOf("tar.gz") - offset // OK
51+
52+
x.indexOf("https://example.internal"); // NOT OK
53+
x.indexOf("https://"); // OK
5154
});

0 commit comments

Comments
 (0)