mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Rust: Add simple SQL injection example.
This commit is contained in:
30
rust/ql/examples/snippets/simple_sql_injection.ql
Normal file
30
rust/ql/examples/snippets/simple_sql_injection.ql
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* @name Database query built from user-controlled sources
|
||||
* @description Finds places where a value from a remote or local user input
|
||||
* is used as an argument to the `sqlx_core::query::query`
|
||||
* function.
|
||||
* @id rust/examples/simple-sql-injection
|
||||
* @tags example
|
||||
*/
|
||||
|
||||
import rust
|
||||
import codeql.rust.dataflow.DataFlow
|
||||
import codeql.rust.dataflow.TaintTracking
|
||||
import codeql.rust.Concepts
|
||||
|
||||
module SqlInjectionConfig implements DataFlow::ConfigSig {
|
||||
predicate isSource(DataFlow::Node node) { node instanceof ActiveThreatModelSource }
|
||||
|
||||
predicate isSink(DataFlow::Node node) {
|
||||
exists(CallExpr call |
|
||||
call.getStaticTarget().getCanonicalPath() = "sqlx_core::query::query" and
|
||||
call.getArg(0) = node.asExpr().getExpr()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
module SqlInjectionFlow = TaintTracking::Global<SqlInjectionConfig>;
|
||||
|
||||
from DataFlow::Node sourceNode, DataFlow::Node sinkNode
|
||||
where SqlInjectionFlow::flow(sourceNode, sinkNode)
|
||||
select sinkNode, "This query depends on a $@.", sourceNode, "user-provided value"
|
||||
Reference in New Issue
Block a user