Skip to content

Commit 735a738

Browse files
committed
Refactor HardcodedCredentialsSourceCall
1 parent 15d5ad7 commit 735a738

File tree

3 files changed

+47
-13
lines changed

3 files changed

+47
-13
lines changed

java/ql/lib/semmle/code/java/security/HardcodedCredentialsSourceCallQuery.qll

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import semmle.code.java.dataflow.DataFlow2
88
import HardcodedCredentials
99

1010
/**
11+
* DEPRECATED: Use `HardcodedCredentialSourceCallFlow` instead.
12+
*
1113
* A data-flow configuration that tracks hardcoded expressions flowing to a parameter whose name suggests
1214
* it may be a credential, excluding those which flow on to other such insecure usage sites.
1315
*/
14-
class HardcodedCredentialSourceCallConfiguration extends DataFlow::Configuration {
16+
deprecated class HardcodedCredentialSourceCallConfiguration extends DataFlow::Configuration {
1517
HardcodedCredentialSourceCallConfiguration() {
1618
this = "HardcodedCredentialSourceCallConfiguration"
1719
}
@@ -22,10 +24,28 @@ class HardcodedCredentialSourceCallConfiguration extends DataFlow::Configuration
2224
}
2325

2426
/**
27+
* A data-flow configuration that tracks hardcoded expressions flowing to a parameter whose name suggests
28+
* it may be a credential, excluding those which flow on to other such insecure usage sites.
29+
*/
30+
module HardcodedCredentialSourceCallConfig implements DataFlow::ConfigSig {
31+
predicate isSource(DataFlow::Node n) { n.asExpr() instanceof HardcodedExpr }
32+
33+
predicate isSink(DataFlow::Node n) { n.asExpr() instanceof FinalCredentialsSourceSink }
34+
}
35+
36+
/**
37+
* Tracks hardcoded expressions flowing to a parameter whose name suggests
38+
* it may be a credential, excluding those which flow on to other such insecure usage sites.
39+
*/
40+
module HardcodedCredentialSourceCallFlow = DataFlow::Global<HardcodedCredentialSourceCallConfig>;
41+
42+
/**
43+
* DEPRECATED: Use `HardcodedCredentialParameterSourceCallFlow` instead.
44+
*
2545
* A data-flow configuration that tracks flow from an argument whose corresponding parameter name suggests
2646
* a credential, to an argument to a sensitive call.
2747
*/
28-
class HardcodedCredentialSourceCallConfiguration2 extends DataFlow2::Configuration {
48+
deprecated class HardcodedCredentialSourceCallConfiguration2 extends DataFlow2::Configuration {
2949
HardcodedCredentialSourceCallConfiguration2() {
3050
this = "HardcodedCredentialSourceCallConfiguration2"
3151
}
@@ -35,17 +55,33 @@ class HardcodedCredentialSourceCallConfiguration2 extends DataFlow2::Configurati
3555
override predicate isSink(DataFlow::Node n) { n.asExpr() instanceof CredentialsSink }
3656
}
3757

58+
/**
59+
* A data-flow configuration that tracks flow from an argument whose corresponding parameter name suggests
60+
* a credential, to an argument to a sensitive call.
61+
*/
62+
module HardcodedCredentialParameterSourceCallConfig implements DataFlow::ConfigSig {
63+
predicate isSource(DataFlow::Node n) { n.asExpr() instanceof CredentialsSourceSink }
64+
65+
predicate isSink(DataFlow::Node n) { n.asExpr() instanceof CredentialsSink }
66+
}
67+
68+
/**
69+
* Tracks flow from an argument whose corresponding parameter name suggests
70+
* a credential, to an argument to a sensitive call.
71+
*/
72+
module HardcodedCredentialParameterSourceCallFlow =
73+
DataFlow::Global<HardcodedCredentialParameterSourceCallConfig>;
74+
3875
/**
3976
* An argument to a call, where the parameter name corresponding
4077
* to the argument indicates that it may contain credentials, and
4178
* where this expression does not flow on to another `CredentialsSink`.
4279
*/
4380
class FinalCredentialsSourceSink extends CredentialsSourceSink {
4481
FinalCredentialsSourceSink() {
45-
not exists(HardcodedCredentialSourceCallConfiguration2 conf, CredentialsSink other |
46-
this != other
47-
|
48-
conf.hasFlow(DataFlow::exprNode(this), DataFlow::exprNode(other))
82+
not exists(CredentialsSink other | this != other |
83+
HardcodedCredentialParameterSourceCallFlow::flow(DataFlow::exprNode(this),
84+
DataFlow::exprNode(other))
4985
)
5086
}
5187
}

java/ql/src/Security/CWE/CWE-798/HardcodedCredentialsSourceCall.ql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
import java
1414
import semmle.code.java.security.HardcodedCredentialsSourceCallQuery
15-
import DataFlow::PathGraph
15+
import HardcodedCredentialSourceCallFlow::PathGraph
1616

1717
from
18-
DataFlow::PathNode source, DataFlow::PathNode sink,
19-
HardcodedCredentialSourceCallConfiguration conf
20-
where conf.hasFlowPath(source, sink)
18+
HardcodedCredentialSourceCallFlow::PathNode source,
19+
HardcodedCredentialSourceCallFlow::PathNode sink
20+
where HardcodedCredentialSourceCallFlow::flowPath(source, sink)
2121
select source.getNode(), source, sink, "Hard-coded value flows to $@.", sink.getNode(),
2222
"sensitive call"

java/ql/test/query-tests/security/CWE-798/semmle/tests/HardcodedCredentialsSourceCall.ql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ class HardcodedCredentialsSourceCallTest extends InlineExpectationsTest {
99

1010
override predicate hasActualResult(Location location, string element, string tag, string value) {
1111
tag = "HardcodedCredentialsSourceCall" and
12-
exists(DataFlow::Node sink, HardcodedCredentialSourceCallConfiguration conf |
13-
conf.hasFlow(_, sink)
14-
|
12+
exists(DataFlow::Node sink | HardcodedCredentialSourceCallFlow::flow(_, sink) |
1513
sink.getLocation() = location and
1614
element = sink.toString() and
1715
value = ""

0 commit comments

Comments
 (0)