-
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 #18129 from geoffw0/sinkmodels
Rust: Sink models for rust/sql-injection
- Loading branch information
Showing
6 changed files
with
121 additions
and
59 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
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
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,40 @@ | ||
/** | ||
* Provides modeling for the `SQLx` library. | ||
*/ | ||
|
||
private import rust | ||
private import codeql.rust.Concepts | ||
private import codeql.rust.dataflow.DataFlow | ||
|
||
/** | ||
* A call to `sqlx::query` and variations. | ||
*/ | ||
private class SqlxQuery extends SqlConstruction::Range { | ||
CallExpr call; | ||
|
||
SqlxQuery() { | ||
this.asExpr().getExpr() = call and | ||
call.getFunction().(PathExpr).getPath().getResolvedPath() = | ||
[ | ||
"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" | ||
] | ||
} | ||
|
||
override DataFlow::Node getSql() { result.asExpr().getExpr() = call.getArgList().getArg(0) } | ||
} | ||
|
||
/** | ||
* A call to `sqlx::Executor::execute`. | ||
*/ | ||
private class SqlxExecute extends SqlExecution::Range { | ||
MethodCallExpr call; | ||
|
||
SqlxExecute() { | ||
this.asExpr().getExpr() = call and | ||
call.(Resolvable).getResolvedPath() = "crate::executor::Executor::execute" | ||
} | ||
|
||
override DataFlow::Node getSql() { result.asExpr().getExpr() = call.getArgList().getArg(0) } | ||
} |
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,2 @@ | ||
testFailures | ||
failures |
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.InlineExpectationsTest | ||
|
||
module SqlSinksTest 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<SqlSinksTest> |
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