Skip to content

Commit dbfe517

Browse files
committed
Python: Move HardcodedCredentials to new dataflow API
1 parent 46322b7 commit dbfe517

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

python/ql/src/Security/CWE-798/HardcodedCredentials.ql

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import python
1616
import semmle.python.dataflow.new.DataFlow
1717
import semmle.python.dataflow.new.TaintTracking
1818
import semmle.python.filters.Tests
19-
import DataFlow::PathGraph
2019

2120
bindingset[char, fraction]
2221
predicate fewer_characters_than(StrConst str, string char, float fraction) {
@@ -108,17 +107,19 @@ private string getACredentialRegex() {
108107
result = "(?i).*(cert)(?!.*(format|name)).*"
109108
}
110109

111-
class HardcodedCredentialsConfiguration extends TaintTracking::Configuration {
112-
HardcodedCredentialsConfiguration() { this = "Hardcoded credentials configuration" }
110+
private module HardcodedCredentialsConfig implements DataFlow::ConfigSig {
111+
predicate isSource(DataFlow::Node source) { source instanceof HardcodedValueSource }
113112

114-
override predicate isSource(DataFlow::Node source) { source instanceof HardcodedValueSource }
115-
116-
override predicate isSink(DataFlow::Node sink) { sink instanceof CredentialSink }
113+
predicate isSink(DataFlow::Node sink) { sink instanceof CredentialSink }
117114
}
118115

119-
from HardcodedCredentialsConfiguration config, DataFlow::PathNode src, DataFlow::PathNode sink
116+
module HardcodedCredentialsFlow = TaintTracking::Global<HardcodedCredentialsConfig>;
117+
118+
import HardcodedCredentialsFlow::PathGraph
119+
120+
from HardcodedCredentialsFlow::PathNode src, HardcodedCredentialsFlow::PathNode sink
120121
where
121-
config.hasFlowPath(src, sink) and
122+
HardcodedCredentialsFlow::flowPath(src, sink) and
122123
not any(TestScope test).contains(src.getNode().asCfgNode().getNode())
123124
select src.getNode(), src, sink, "This hardcoded value is $@.", sink.getNode(),
124125
"used as credentials"

0 commit comments

Comments
 (0)