11/**
22 * @name Constant password
33 * @description Finds places where a string literal is used in a function call
4- * argument named something like " password" .
4+ * argument that looks like a password.
55 * @id rust/examples/simple-constant-password
66 * @tags example
77 */
@@ -10,8 +10,23 @@ import rust
1010import codeql.rust.dataflow.DataFlow
1111import codeql.rust.dataflow.TaintTracking
1212
13+ /**
14+ * A data flow configuration for tracking flow from a string literal to a function
15+ * call argument that looks like a password. For example:
16+ * ```
17+ * fn set_password(password: &str) { ... }
18+ *
19+ * ...
20+ *
21+ * let pwd = "123456"; // source
22+ * set_password(pwd); // sink (argument 0)
23+ * ```
24+ */
1325module ConstantPasswordConfig implements DataFlow:: ConfigSig {
14- predicate isSource ( DataFlow:: Node node ) { node .asExpr ( ) .getExpr ( ) instanceof StringLiteralExpr }
26+ predicate isSource ( DataFlow:: Node node ) {
27+ // `node` is a string literal
28+ node .asExpr ( ) .getExpr ( ) instanceof StringLiteralExpr
29+ }
1530
1631 predicate isSink ( DataFlow:: Node node ) {
1732 // `node` is an argument whose corresponding parameter name matches the pattern "pass%"
@@ -23,8 +38,10 @@ module ConstantPasswordConfig implements DataFlow::ConfigSig {
2338 }
2439}
2540
41+ // instantiate the data flow configuration as a global taint tracking module
2642module ConstantPasswordFlow = TaintTracking:: Global< ConstantPasswordConfig > ;
2743
44+ // report flows from sources to sinks
2845from DataFlow:: Node sourceNode , DataFlow:: Node sinkNode
2946where ConstantPasswordFlow:: flow ( sourceNode , sinkNode )
3047select sinkNode , "The value $@ is used as a constant password." , sourceNode , sourceNode .toString ( )
0 commit comments