Skip to content

Commit 49aefe2

Browse files
committed
Rust: Add simple SQL injection example.
1 parent 6ce0a0d commit 49aefe2

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @name Database query built from user-controlled sources
3+
* @description Finds places where a value from a remote or local user input
4+
* is used as an argument to the `sqlx_core::query::query`
5+
* function.
6+
* @id rust/examples/simple-sql-injection
7+
* @tags example
8+
*/
9+
10+
import rust
11+
import codeql.rust.dataflow.DataFlow
12+
import codeql.rust.dataflow.TaintTracking
13+
import codeql.rust.Concepts
14+
15+
module SqlInjectionConfig implements DataFlow::ConfigSig {
16+
predicate isSource(DataFlow::Node node) { node instanceof ActiveThreatModelSource }
17+
18+
predicate isSink(DataFlow::Node node) {
19+
exists(CallExpr call |
20+
call.getStaticTarget().getCanonicalPath() = "sqlx_core::query::query" and
21+
call.getArg(0) = node.asExpr().getExpr()
22+
)
23+
}
24+
}
25+
26+
module SqlInjectionFlow = TaintTracking::Global<SqlInjectionConfig>;
27+
28+
from DataFlow::Node sourceNode, DataFlow::Node sinkNode
29+
where SqlInjectionFlow::flow(sourceNode, sinkNode)
30+
select sinkNode, "This query depends on a $@.", sourceNode, "user-provided value"

0 commit comments

Comments
 (0)