-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18536 from GeekMasher/rust-postgres
Rust: Add Postgres crate Models
- Loading branch information
Showing
7 changed files
with
96 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
extensions: | ||
- addsTo: | ||
pack: codeql/rust-all | ||
extensible: sinkModel | ||
data: | ||
- ["repo:https://github.com/sfackler/rust-postgres:postgres", "<crate::client::Client>::execute", "Argument[0]", "sql-injection", "manual"] | ||
- ["repo:https://github.com/sfackler/rust-postgres:postgres", "<crate::client::Client>::batch_execute", "Argument[0]", "sql-injection", "manual"] | ||
- ["repo:https://github.com/sfackler/rust-postgres:postgres", "<crate::client::Client>::prepare", "Argument[0]", "sql-injection", "manual"] | ||
- ["repo:https://github.com/sfackler/rust-postgres:postgres", "<crate::client::Client>::prepare_typed", "Argument[0]", "sql-injection", "manual"] | ||
- ["repo:https://github.com/sfackler/rust-postgres:postgres", "<crate::client::Client>::query", "Argument[0]", "sql-injection", "manual"] | ||
- ["repo:https://github.com/sfackler/rust-postgres:postgres", "<crate::client::Client>::query_one", "Argument[0]", "sql-injection", "manual"] | ||
- ["repo:https://github.com/sfackler/rust-postgres:postgres", "<crate::client::Client>::query_opt", "Argument[0]", "sql-injection", "manual"] | ||
- ["repo:https://github.com/sfackler/rust-postgres:postgres", "<crate::client::Client>::query_raw", "Argument[0]", "sql-injection", "manual"] | ||
- ["repo:https://github.com/sfackler/rust-postgres:postgres", "<crate::client::Client>::query_typed", "Argument[0]", "sql-injection", "manual"] | ||
- ["repo:https://github.com/sfackler/rust-postgres:postgres", "<crate::client::Client>::query_typed_raw", "Argument[0]", "sql-injection", "manual"] |
6 changes: 3 additions & 3 deletions
6
rust/ql/test/library-tests/dataflow/taint/TaintFlowStep.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
19 changes: 19 additions & 0 deletions
19
rust/ql/test/library-tests/frameworks/postgres/Postgres.ql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import rust | ||
import codeql.rust.security.SqlInjectionExtensions | ||
import utils.test.InlineExpectationsTest | ||
|
||
module PostgresTest implements TestSig { | ||
string getARelevantTag() { result = "sql-sink" } | ||
|
||
predicate hasActualResult(Location location, string element, string tag, string value) { | ||
exists(SqlInjection::Sink sink | | ||
location = sink.getLocation() and | ||
location.getFile().getBaseName() != "" and | ||
element = sink.toString() and | ||
tag = "sql-sink" and | ||
value = "" | ||
) | ||
} | ||
} | ||
|
||
import MakeTest<PostgresTest> |
13 changes: 13 additions & 0 deletions
13
rust/ql/test/library-tests/frameworks/postgres/cargo.toml.manual
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[workspace] | ||
|
||
[package] | ||
name = "postgres-test" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
postgres = { version = "0.19" } | ||
|
||
[[bin]] | ||
name = "postgres" | ||
path = "./main.rs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
// Get input from CLI | ||
let args: Vec<String> = std::env::args().collect(); | ||
let name = &args[1]; | ||
let age = &args[2]; | ||
|
||
let mut conn = postgres::Client::connect("host=localhost user=postgres", postgres::NoTls)?; | ||
|
||
conn.execute( // $ sql-sink | ||
"CREATE TABLE person ( | ||
id SERIAL PRIMARY KEY, | ||
name VARCHAR NOT NULL, | ||
age INT NOT NULL | ||
)", | ||
&[], | ||
)?; | ||
|
||
let query = format!("INSERT INTO person (name, age) VALUES ('{}', '{}')", name, age); | ||
|
||
conn.execute(query.as_str(), &[])?; // $ sql-sink | ||
conn.batch_execute(query.as_str())?; // $ sql-sink | ||
|
||
conn.prepare(query.as_str())?; // $ sql-sink | ||
// conn.prepare_typed(query.as_str(), &[])?; | ||
|
||
conn.query(query.as_str(), &[])?; // $ sql-sink | ||
conn.query_one(query.as_str(), &[])?; // $ sql-sink | ||
conn.query_opt(query.as_str(), &[])?; // $ sql-sink | ||
// conn.query_raw(query.as_str(), &[])?; | ||
// conn.query_typed(query.as_str(), &[])?; | ||
// conn.query_typed_raw(query.as_str(), &[])?; | ||
|
||
for row in &conn.query("SELECT id, name, age FROM person", &[])? { // $ sql-sink | ||
let id: i32 = row.get("id"); | ||
let name: &str = row.get("name"); | ||
let age: i32 = row.get("age"); | ||
println!("found person: {} {} {}", id, name, age); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
qltest_cargo_check: true | ||
qltest_dependencies: | ||
- postgres = { version = "0.19" } |