Skip to content

Commit 80ce55a

Browse files
committed
Rust: Make the private address spaces URL more accurate.
1 parent 0f5aa85 commit 80ce55a

File tree

3 files changed

+2
-6
lines changed

3 files changed

+2
-6
lines changed

rust/ql/lib/codeql/rust/security/UseOfHttpExtensions.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module UseOfHttp {
3838
exists(string s | this.getTextValue() = s |
3939
// Match HTTP URLs that are not private/local
4040
s.regexpMatch("\"http://.*\"") and
41-
not s.regexpMatch("\"http://(localhost|127\\.0\\.0\\.1|192\\.168\\.[0-9]+\\.[0-9]+|10\\.[0-9]+\\.[0-9]+\\.[0-9]+|172\\.16\\.[0-9]+\\.[0-9]+|\\[::1\\]|\\[0:0:0:0:0:0:0:1\\]).*\"")
41+
not s.regexpMatch("\"http://(localhost|127\\.0\\.0\\.1|192\\.168\\.[0-9]+\\.[0-9]+|10\\.[0-9]+\\.[0-9]+\\.[0-9]+|172\\.(1[6-9]|2[0-9]|3[01])\\.[0-9]+|\\[::1\\]|\\[0:0:0:0:0:0:0:1\\]).*\"")
4242
)
4343
}
4444
}

rust/ql/test/query-tests/security/CWE-319/UseOfHttp.expected

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
| main.rs:14:22:14:43 | ...::get | main.rs:14:45:14:73 | "http://api.example.com/data" | main.rs:14:22:14:43 | ...::get | This URL may be constructed with the HTTP protocol, from $@. | main.rs:14:45:14:73 | "http://api.example.com/data" | this HTTP URL |
44
| main.rs:26:21:26:42 | ...::get | main.rs:23:20:23:39 | "http://example.com" | main.rs:26:21:26:42 | ...::get | This URL may be constructed with the HTTP protocol, from $@. | main.rs:23:20:23:39 | "http://example.com" | this HTTP URL |
55
| main.rs:37:30:37:51 | ...::get | main.rs:34:20:34:28 | "http://" | main.rs:37:30:37:51 | ...::get | This URL may be constructed with the HTTP protocol, from $@. | main.rs:34:20:34:28 | "http://" | this HTTP URL |
6-
| main.rs:53:19:53:40 | ...::get | main.rs:53:42:53:68 | "http://172.31.255.255/bar" | main.rs:53:19:53:40 | ...::get | This URL may be constructed with the HTTP protocol, from $@. | main.rs:53:42:53:68 | "http://172.31.255.255/bar" | this HTTP URL |
76
| main.rs:60:20:60:41 | ...::get | main.rs:60:43:60:65 | "http://172.32.0.0/baz" | main.rs:60:20:60:41 | ...::get | This URL may be constructed with the HTTP protocol, from $@. | main.rs:60:43:60:65 | "http://172.32.0.0/baz" | this HTTP URL |
87
| main.rs:71:24:71:45 | ...::get | main.rs:68:19:68:53 | "http://example.com/sensitive-... | main.rs:71:24:71:45 | ...::get | This URL may be constructed with the HTTP protocol, from $@. | main.rs:68:19:68:53 | "http://example.com/sensitive-... | this HTTP URL |
98
edges
@@ -29,7 +28,6 @@ edges
2928
| main.rs:36:32:36:53 | { ... } | main.rs:36:32:36:53 | ...::must_use(...) | provenance | MaD:3 |
3029
| main.rs:37:53:37:65 | &insecure_url [&ref] | main.rs:37:30:37:51 | ...::get | provenance | MaD:1 Sink:MaD:1 |
3130
| main.rs:37:54:37:65 | insecure_url | main.rs:37:53:37:65 | &insecure_url [&ref] | provenance | |
32-
| main.rs:53:42:53:68 | "http://172.31.255.255/bar" | main.rs:53:19:53:40 | ...::get | provenance | MaD:1 Sink:MaD:1 |
3331
| main.rs:60:43:60:65 | "http://172.32.0.0/baz" | main.rs:60:20:60:41 | ...::get | provenance | MaD:1 Sink:MaD:1 |
3432
| main.rs:68:13:68:15 | url | main.rs:71:47:71:49 | url | provenance | |
3533
| main.rs:68:19:68:53 | "http://example.com/sensitive-... | main.rs:68:13:68:15 | url | provenance | |
@@ -65,8 +63,6 @@ nodes
6563
| main.rs:37:30:37:51 | ...::get | semmle.label | ...::get |
6664
| main.rs:37:53:37:65 | &insecure_url [&ref] | semmle.label | &insecure_url [&ref] |
6765
| main.rs:37:54:37:65 | insecure_url | semmle.label | insecure_url |
68-
| main.rs:53:19:53:40 | ...::get | semmle.label | ...::get |
69-
| main.rs:53:42:53:68 | "http://172.31.255.255/bar" | semmle.label | "http://172.31.255.255/bar" |
7066
| main.rs:60:20:60:41 | ...::get | semmle.label | ...::get |
7167
| main.rs:60:43:60:65 | "http://172.32.0.0/baz" | semmle.label | "http://172.32.0.0/baz" |
7268
| main.rs:68:13:68:15 | url | semmle.label | url |

rust/ql/test/query-tests/security/CWE-319/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn test_localhost_exemptions() {
5050
let _local4 = reqwest::blocking::get("http://192.168.1.100/internal").unwrap();
5151
let _local5 = reqwest::blocking::get("http://10.0.0.1/admin").unwrap();
5252
let _local6 = reqwest::blocking::get("http://172.16.0.0/foo").unwrap();
53-
let _local7 = reqwest::blocking::get("http://172.31.255.255/bar").unwrap(); // $ SPURIOUS: Alert[rust/non-https-url]
53+
let _local7 = reqwest::blocking::get("http://172.31.255.255/bar").unwrap();
5454

5555
// GOOD: test IPv6 localhost variants
5656
let _local8 = reqwest::blocking::get("http://[::1]:8080/api").unwrap();

0 commit comments

Comments
 (0)