-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Rust: Update SqlxQuery, SqlxExecute to use getCanonicalPath #19802
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
dc08274
f3b5cc7
6f5e4ef
87deab8
62b7d84
944fd2a
69064b7
27bea33
67c170f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…calPath.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,6 +5,8 @@ | |||||
private import rust | ||||||
private import codeql.rust.Concepts | ||||||
private import codeql.rust.dataflow.DataFlow | ||||||
private import codeql.rust.internal.TypeInference | ||||||
private import codeql.rust.internal.Type | ||||||
|
||||||
/** | ||||||
* A call to `sqlx::query` and variations. | ||||||
|
@@ -14,11 +16,12 @@ private class SqlxQuery extends SqlConstruction::Range { | |||||
|
||||||
SqlxQuery() { | ||||||
this.asExpr().getExpr() = call and | ||||||
call.getFunction().(PathExpr).getResolvedPath() = | ||||||
call.getStaticTarget().(Addressable).getCanonicalPath() = | ||||||
[ | ||||||
"crate::query::query", "crate::query_as::query_as", "crate::query_with::query_with", | ||||||
"crate::query_as_with::query_as_with", "crate::query_scalar::query_scalar", | ||||||
"crate::query_scalar_with::query_scalar_with", "crate::raw_sql::raw_sql" | ||||||
"sqlx_core::query::query", "sqlx_core::query_as::query_as", | ||||||
"sqlx_core::query_with::query_with", "sqlx_core::query_as_with::query_as_with", | ||||||
"sqlx_core::query_scalar::query_scalar", "sqlx_core::query_scalar_with::query_scalar_with", | ||||||
"sqlx_core::raw_sql::raw_sql" | ||||||
] | ||||||
} | ||||||
|
||||||
|
@@ -33,7 +36,8 @@ private class SqlxExecute extends SqlExecution::Range { | |||||
|
||||||
SqlxExecute() { | ||||||
this.asExpr().getExpr() = call and | ||||||
call.(Resolvable).getResolvedPath() = "crate::executor::Executor::execute" | ||||||
call.getStaticTarget().(Addressable).getCanonicalPath() = | ||||||
"sqlx_core::executor::Executor::execute" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this should be something like
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's difficult to be confident without the test working, but All reactions |
||||||
} | ||||||
|
||||||
override DataFlow::Node getSql() { result.asExpr().getExpr() = call.getArgList().getArg(0) } | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,14 +61,14 @@ async fn test_sqlx_mysql(url: &str, enable_remote: bool) -> Result<(), sqlx::Err | |
let prepared_query_1 = String::from("SELECT * FROM people WHERE firstname=?"); // (prepared arguments are safe) | ||
|
||
// direct execution | ||
let _ = conn.execute(safe_query_1.as_str()).await?; // $ sql-sink | ||
let _ = conn.execute(safe_query_2.as_str()).await?; // $ sql-sink | ||
let _ = conn.execute(safe_query_3.as_str()).await?; // $ sql-sink SPURIOUS: Alert[rust/sql-injection]=remote1 | ||
let _ = conn.execute(unsafe_query_1.as_str()).await?; // $ sql-sink Alert[rust/sql-injection]=args1 | ||
let _ = conn.execute(safe_query_1.as_str()).await?; // $ MISSING: sql-sink | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While we are able to infer that Once we are able to do that, we need implicit dereferencing via
to get to the type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added explicit types to some of the test cases and that is indeed not enough by itself, but it should increase the chances we see a change in test results as improvements are made. I'm not sure whether we should aim to merge this PR (i.e. accept the regression for now) or wait for type inference to catch up. Guess I'll bring it out of draft and start a DCA run to help decide... |
||
let _ = conn.execute(safe_query_2.as_str()).await?; // $ MISSING: sql-sink | ||
let _ = conn.execute(safe_query_3.as_str()).await?; // $ MISSING: sql-sink | ||
let _ = conn.execute(unsafe_query_1.as_str()).await?; // $ MISSING: sql-sink Alert[rust/sql-injection]=args1 | ||
if enable_remote { | ||
let _ = conn.execute(unsafe_query_2.as_str()).await?; // $ sql-sink Alert[rust/sql-injection]=remote1 | ||
let _ = conn.execute(unsafe_query_3.as_str()).await?; // $ sql-sink MISSING: Alert[rust/sql-injection]=remote1 | ||
let _ = conn.execute(unsafe_query_4.as_str()).await?; // $ sql-sink Alert[rust/sql-injection]=remote1 | ||
let _ = conn.execute(unsafe_query_2.as_str()).await?; // $ MISSING: sql-sink Alert[rust/sql-injection]=remote1 | ||
let _ = conn.execute(unsafe_query_3.as_str()).await?; // $ MISSING: sql-sink Alert[rust/sql-injection]=remote1 | ||
let _ = conn.execute(unsafe_query_4.as_str()).await?; // $ MISSING: sql-sink Alert[rust/sql-injection]=remote1 | ||
} | ||
|
||
// prepared queries | ||
|
@@ -103,9 +103,9 @@ async fn test_sqlx_sqlite(url: &str, enable_remote: bool) -> Result<(), sqlx::Er | |
let prepared_query_1 = String::from("SELECT * FROM people WHERE firstname=?"); // (prepared arguments are safe) | ||
|
||
// direct execution (with extra variants) | ||
let _ = conn.execute(safe_query_1.as_str()).await?; // $ sql-sink | ||
let _ = conn.execute(safe_query_1.as_str()).await?; // $ MISSING: sql-sink | ||
if enable_remote { | ||
let _ = conn.execute(unsafe_query_1.as_str()).await?; // $ sql-sink MISSING: Alert[rust/sql-injection]=remote2 | ||
let _ = conn.execute(unsafe_query_1.as_str()).await?; // $ MISSING: sql-sink Alert[rust/sql-injection]=remote2 | ||
} | ||
// ... | ||
let _ = sqlx::raw_sql(safe_query_1.as_str()).execute(&mut conn).await?; // $ sql-sink | ||
|
@@ -176,9 +176,9 @@ async fn test_sqlx_postgres(url: &str, enable_remote: bool) -> Result<(), sqlx:: | |
let prepared_query_1 = String::from("SELECT * FROM people WHERE firstname=$1"); 59EC // (prepared arguments are safe) | ||
|
||
// direct execution | ||
let _ = conn.execute(safe_query_1.as_str()).await?; // $ sql-sink | ||
let _ = conn.execute(safe_query_1.as_str()).await?; // $ MISSING: sql-sink | ||
if enable_remote { | ||
let _ = conn.execute(unsafe_query_1.as_str()).await?; // $ sql-sink MISSING: Alert[rust/sql-injection]=remote3 | ||
let _ = conn.execute(unsafe_query_1.as_str()).await?; // $ MISSING: sql-sink Alert[rust/sql-injection]=remote3 | ||
} | ||
|
||
// prepared queries | ||
|
Uh oh!
There was an error while loading. Please reload this page.