Skip to content

Commit 0924dec

Browse files
committed
Rust: Make the tests of the example code closer to the actual example code.
1 parent 7b04cf1 commit 0924dec

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
| main.rs:13:22:13:43 | ...::get | main.rs:13:45:13:73 | "http://api.example.com/data" | main.rs:13:22:13:43 | ...::get | This URL may be constructed with the HTTP protocol, from $@. | main.rs:13:45:13:73 | "http://api.example.com/data" | this HTTP URL |
44
| main.rs:25:21:25:42 | ...::get | main.rs:22:20:22:39 | "http://example.com" | main.rs:25:21:25:42 | ...::get | This URL may be constructed with the HTTP protocol, from $@. | main.rs:22:20:22:39 | "http://example.com" | this HTTP URL |
55
| main.rs:36:30:36:51 | ...::get | main.rs:33:20:33:28 | "http://" | main.rs:36:30:36:51 | ...::get | This URL may be constructed with the HTTP protocol, from $@. | main.rs:33:20:33:28 | "http://" | this HTTP URL |
6-
| main.rs:60:21:60:42 | ...::get | main.rs:59:15:59:49 | "http://example.com/sensitive-... | main.rs:60:21:60:42 | ...::get | This URL may be constructed with the HTTP protocol, from $@. | main.rs:59:15:59:49 | "http://example.com/sensitive-... | this HTTP URL |
6+
| main.rs:63:24:63:45 | ...::get | main.rs:60:19:60:53 | "http://example.com/sensitive-... | main.rs:63:24:63:45 | ...::get | This URL may be constructed with the HTTP protocol, from $@. | main.rs:60:19:60:53 | "http://example.com/sensitive-... | this HTTP URL |
77
edges
88
| main.rs:12:45:12:68 | "http://example.com/api" | main.rs:12:22:12:43 | ...::get | provenance | MaD:1 Sink:MaD:1 |
99
| main.rs:13:45:13:73 | "http://api.example.com/data" | main.rs:13:22:13:43 | ...::get | provenance | MaD:1 Sink:MaD:1 |
@@ -27,9 +27,9 @@ edges
2727
| main.rs:35:32:35:53 | { ... } | main.rs:35:32:35:53 | ...::must_use(...) | provenance | MaD:3 |
2828
| main.rs:36:53:36:65 | &insecure_url [&ref] | main.rs:36:30:36:51 | ...::get | provenance | MaD:1 Sink:MaD:1 |
2929
| main.rs:36:54:36:65 | insecure_url | main.rs:36:53:36:65 | &insecure_url [&ref] | provenance | |
30-
| main.rs:59:9:59:11 | url | main.rs:60:44:60:46 | url | provenance | |
31-
| main.rs:59:15:59:49 | "http://example.com/sensitive-... | main.rs:59:9:59:11 | url | provenance | |
32-
| main.rs:60:44:60:46 | url | main.rs:60:21:60:42 | ...::get | provenance | MaD:1 Sink:MaD:1 |
30+
| main.rs:60:13:60:15 | url | main.rs:63:47:63:49 | url | provenance | |
31+
| main.rs:60:19:60:53 | "http://example.com/sensitive-... | main.rs:60:13:60:15 | url | provenance | |
32+
| main.rs:63:47:63:49 | url | main.rs:63:24:63:45 | ...::get | provenance | MaD:1 Sink:MaD:1 |
3333
models
3434
| 1 | Sink: reqwest::blocking::get; Argument[0]; request-url |
3535
| 2 | Summary: alloc::fmt::format; Argument[0]; ReturnValue; taint |
@@ -61,8 +61,8 @@ nodes
6161
| main.rs:36:30:36:51 | ...::get | semmle.label | ...::get |
6262
| main.rs:36:53:36:65 | &insecure_url [&ref] | semmle.label | &insecure_url [&ref] |
6363
| main.rs:36:54:36:65 | insecure_url | semmle.label | insecure_url |
64-
| main.rs:59:9:59:11 | url | semmle.label | url |
65-
| main.rs:59:15:59:49 | "http://example.com/sensitive-... | semmle.label | "http://example.com/sensitive-... |
66-
| main.rs:60:21:60:42 | ...::get | semmle.label | ...::get |
67-
| main.rs:60:44:60:46 | url | semmle.label | url |
64+
| main.rs:60:13:60:15 | url | semmle.label | url |
65+
| main.rs:60:19:60:53 | "http://example.com/sensitive-... | semmle.label | "http://example.com/sensitive-... |
66+
| main.rs:63:24:63:45 | ...::get | semmle.label | ...::get |
67+
| main.rs:63:47:63:49 | url | semmle.label | url |
6868
subpaths

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,20 @@ fn test_localhost_exemptions() {
5656
// Additional test cases that mirror the Bad/Good examples
5757
fn test_examples() {
5858
// From UseOfHttpBad.rs - BAD case
59-
let url = "http://example.com/sensitive-data"; // $ Source
60-
let _response = reqwest::blocking::get(url).unwrap(); // $ Alert[rust/non-https-url]
59+
{
60+
let url = "http://example.com/sensitive-data"; // $ Source
61+
62+
// This makes an insecure HTTP request that can be intercepted
63+
let response = reqwest::blocking::get(url).unwrap(); // $ Alert[rust/non-https-url]
64+
println!("Response: {}", response.text().unwrap());
65+
}
6166

6267
// From UseOfHttpGood.rs - GOOD case
63-
let secure_url = "https://example.com/sensitive-data";
64-
let _secure_response = reqwest::blocking::get(secure_url).unwrap();
68+
{
69+
let url = "https://example.com/sensitive-data";
70+
71+
// This makes a secure HTTPS request that is encrypted
72+
let response = reqwest::blocking::get(url).unwrap();
73+
println!("Response: {}", response.text().unwrap());
74+
}
6575
}

0 commit comments

Comments
 (0)