Skip to content

Rust: Re-categorize tokio-postgres sources as remote. #18752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rust/ql/lib/codeql/rust/frameworks/tokio-postgres.model.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ extensions:
pack: codeql/rust-all
extensible: sourceModel
data:
- ["repo:https://github.com/sfackler/rust-postgres:tokio-postgres", "<crate::row::Row>::get", "ReturnValue", "database", "manual"]
- ["repo:https://github.com/sfackler/rust-postgres:tokio-postgres", "<crate::row::Row>::try_get", "ReturnValue.Variant[crate::result::Result::Ok(0)]", "database", "manual"]
- ["repo:https://github.com/sfackler/rust-postgres:tokio-postgres", "<crate::row::Row>::get", "ReturnValue", "remote", "manual"]
- ["repo:https://github.com/sfackler/rust-postgres:tokio-postgres", "<crate::row::Row>::try_get", "ReturnValue.Variant[crate::result::Result::Ok(0)]", "remote", "manual"]
6 changes: 3 additions & 3 deletions rust/ql/test/library-tests/frameworks/postgres/Postgres.ql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import codeql.rust.security.SqlInjectionExtensions
import utils.test.InlineExpectationsTest

module PostgresTest implements TestSig {
string getARelevantTag() { result = ["sql-sink", "database-read"] }
string getARelevantTag() { result = ["sql-sink", "source"] }

predicate hasActualResult(Location location, string element, string tag, string value) {
exists(SqlInjection::Sink sink |
Expand All @@ -15,11 +15,11 @@ module PostgresTest implements TestSig {
value = ""
)
or
exists(ModeledDatabaseSource source |
exists(ThreatModelSource source |
location = source.getLocation() and
location.getFile().getBaseName() != "" and
element = source.toString() and
tag = "database-read" and
tag = "source" and
value = ""
)
}
Expand Down
12 changes: 6 additions & 6 deletions rust/ql/test/library-tests/frameworks/postgres/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

fn main() -> Result<(), Box<dyn std::error::Error>> {
// Get input from CLI
let args: Vec<String> = std::env::args().collect();
let args: Vec<String> = std::env::args().collect(); // $ source
let name = &args[1];
let age = &args[2];

Expand All @@ -16,7 +16,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
)",
&[],
)?;

let query = format!("INSERT INTO person (name, age) VALUES ('{}', '{}')", name, age);

conn.execute(query.as_str(), &[])?; // $ sql-sink
Expand All @@ -33,11 +33,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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"); // $ database-read
let name: &str = row.try_get("name")?; // $ database-read
let age: i32 = row.try_get("age").unwrap(); // $ database-read
let id: i32 = row.get("id"); // $ source
let name: &str = row.try_get("name")?; // $ source
let age: i32 = row.try_get("age").unwrap(); // $ source
println!("found person: {} {} {}", id, name, age);
}

Ok(())
}
}