Skip to content

Commit 1592b57

Browse files
committed
Swift: Use DataFlow::ConfigSig in ConstantPassword.ql
1 parent 31512b8 commit 1592b57

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

swift/ql/src/queries/Security/CWE-259/ConstantPassword.ql

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import swift
1414
import codeql.swift.dataflow.DataFlow
1515
import codeql.swift.dataflow.TaintTracking
1616
import codeql.swift.dataflow.FlowSteps
17-
import DataFlow::PathGraph
17+
import ConstantPasswordFlow::PathGraph
1818

1919
/**
2020
* A constant password is created through either a byte array or string literals.
@@ -60,18 +60,16 @@ class ConstantPasswordSink extends Expr {
6060
* A taint configuration from the source of constants passwords to expressions that use
6161
* them to initialize password-based encryption keys.
6262
*/
63-
class ConstantPasswordConfig extends TaintTracking::Configuration {
64-
ConstantPasswordConfig() { this = "ConstantPasswordConfig" }
63+
module ConstantPasswordConfig implements DataFlow::ConfigSig {
64+
predicate isSource(DataFlow::Node node) { node.asExpr() instanceof ConstantPasswordSource }
6565

66-
override predicate isSource(DataFlow::Node node) {
67-
node.asExpr() instanceof ConstantPasswordSource
68-
}
69-
70-
override predicate isSink(DataFlow::Node node) { node.asExpr() instanceof ConstantPasswordSink }
66+
predicate isSink(DataFlow::Node node) { node.asExpr() instanceof ConstantPasswordSink }
7167
}
7268

69+
module ConstantPasswordFlow = TaintTracking::Global<ConstantPasswordConfig>;
70+
7371
// The query itself
74-
from ConstantPasswordConfig config, DataFlow::PathNode sourceNode, DataFlow::PathNode sinkNode
75-
where config.hasFlowPath(sourceNode, sinkNode)
72+
from ConstantPasswordFlow::PathNode sourceNode, ConstantPasswordFlow::PathNode sinkNode
73+
where ConstantPasswordFlow::flowPath(sourceNode, sinkNode)
7674
select sinkNode.getNode(), sourceNode, sinkNode,
7775
"The value '" + sourceNode.getNode().toString() + "' is used as a constant password."

0 commit comments

Comments
 (0)