Skip to content

Commit 176e9a4

Browse files
committed
Rust: Model reqwest.
1 parent e64f139 commit 176e9a4

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

rust/ql/lib/codeql/rust/Concepts.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,19 @@ module EnvironmentSource {
7373
}
7474
}
7575

76+
/**
77+
* A data flow source for remote (network) data.
78+
*/
79+
class RemoteSource extends ThreatModelSource instanceof RemoteSource::Range { }
80+
81+
module RemoteSource {
82+
abstract class Range extends ThreatModelSource::Range {
83+
override string getThreatModel() { result = "remote" }
84+
85+
override string getSourceType() { result = "RemoteSource" }
86+
}
87+
}
88+
7689
/**
7790
* A data-flow node that constructs a SQL statement.
7891
*

rust/ql/lib/codeql/rust/Frameworks.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
* This file imports all models of frameworks and libraries.
33
*/
44

5+
private import codeql.rust.frameworks.Reqwest
56
private import codeql.rust.frameworks.stdlib.Env
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Provides modeling for the `reqwest` library.
3+
*/
4+
5+
private import rust
6+
private import codeql.rust.Concepts
7+
8+
/**
9+
* A call to `reqwest::get` or `reqwest::blocking::get`.
10+
*/
11+
private class ReqwestGet extends RemoteSource::Range {
12+
ReqwestGet() {
13+
this.asExpr().(CallExpr).getExpr().(PathExpr).getPath().getResolvedPath() =
14+
["crate::get", "crate::blocking::get"]
15+
}
16+
}

rust/ql/test/library-tests/dataflow/sources/TaintSources.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@
1212
| test.rs:50:15:50:37 | CallExpr | CommandLineArgs (commandargs) |
1313
| test.rs:51:15:51:37 | CallExpr | CommandLineArgs (commandargs) |
1414
| test.rs:52:16:52:35 | CallExpr | CommandLineArgs (commandargs) |
15+
| test.rs:60:26:60:70 | CallExpr | RemoteSource (remote, DEFAULT) |
16+
| test.rs:63:26:63:70 | CallExpr | RemoteSource (remote, DEFAULT) |
17+
| test.rs:66:26:66:60 | CallExpr | RemoteSource (remote, DEFAULT) |

rust/ql/test/library-tests/dataflow/sources/test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ fn test_env_dirs() {
5757
}
5858

5959
async fn test_reqwest() -> Result<(), reqwest::Error> {
60-
let remote_string1 = reqwest::blocking::get("http://example.com/")?.text()?; // $ MISSING: Alert[rust/summary/taint-sources]
60+
let remote_string1 = reqwest::blocking::get("http://example.com/")?.text()?; // $ Alert[rust/summary/taint-sources]
6161
sink(remote_string1); // $ MISSING: hasTaintFlow
6262

63-
let remote_string2 = reqwest::blocking::get("http://example.com/").unwrap().text().unwrap(); // $ MISSING: Alert[rust/summary/taint-sources]
63+
let remote_string2 = reqwest::blocking::get("http://example.com/").unwrap().text().unwrap(); // $ Alert[rust/summary/taint-sources]
6464
sink(remote_string2); // $ MISSING: hasTaintFlow
6565

66-
let remote_string3 = reqwest::get("http://example.com/").await?.text().await?; // $ MISSING: Alert[rust/summary/taint-sources]
66+
let remote_string3 = reqwest::get("http://example.com/").await?.text().await?; // $ Alert[rust/summary/taint-sources]
6767
sink(remote_string3); // $ MISSING: hasTaintFlow
6868

6969
Ok(())

0 commit comments

Comments
 (0)