Skip to content

Commit 7b6e06e

Browse files
committed
Rust: Add simple constant password example.
1 parent 49aefe2 commit 7b6e06e

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 Constant password
3+
* @description Finds places where a string literal is used in a function call
4+
* argument named something like "password".
5+
* @id rust/examples/simple-constant-password
6+
* @tags example
7+
*/
8+
9+
import rust
10+
import codeql.rust.dataflow.DataFlow
11+
import codeql.rust.dataflow.TaintTracking
12+
13+
module ConstantPasswordConfig implements DataFlow::ConfigSig {
14+
predicate isSource(DataFlow::Node node) { node.asExpr().getExpr() instanceof StringLiteralExpr }
15+
16+
predicate isSink(DataFlow::Node node) {
17+
// `node` is an argument whose corresponding parameter name matches the pattern "pass%"
18+
exists(CallExpr call, Function target, int argIndex |
19+
call.getStaticTarget() = target and
20+
target.getParam(argIndex).getPat().(IdentPat).getName().getText().matches("pass%") and
21+
call.getArg(argIndex) = node.asExpr().getExpr()
22+
)
23+
}
24+
}
25+
26+
module ConstantPasswordFlow = TaintTracking::Global<ConstantPasswordConfig>;
27+
28+
from DataFlow::Node sourceNode, DataFlow::Node sinkNode
29+
where ConstantPasswordFlow::flow(sourceNode, sinkNode)
30+
select sinkNode, "The value $@ is used as a constant password.", sourceNode, sourceNode.toString()

0 commit comments

Comments
 (0)