Skip to content

Commit ac8dec7

Browse files
committed
Refactor UnsafeCertTrustQuery
1 parent a040ff6 commit ac8dec7

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import semmle.code.java.security.UnsafeCertTrust
66
import semmle.code.java.security.Encryption
77

88
/**
9+
* DEPRECATED: Use `SslEndpointIdentificationFlow` instead.
10+
*
911
* A taint flow configuration for SSL connections created without a proper certificate trust configuration.
1012
*/
11-
class SslEndpointIdentificationFlowConfig extends TaintTracking::Configuration {
13+
deprecated class SslEndpointIdentificationFlowConfig extends TaintTracking::Configuration {
1214
SslEndpointIdentificationFlowConfig() { this = "SslEndpointIdentificationFlowConfig" }
1315

1416
override predicate isSource(DataFlow::Node source) { source instanceof SslConnectionInit }
@@ -20,30 +22,38 @@ class SslEndpointIdentificationFlowConfig extends TaintTracking::Configuration {
2022
}
2123
}
2224

25+
private module SslEndpointIdentificationFlowConfig implements DataFlow::ConfigSig {
26+
predicate isSource(DataFlow::Node source) { source instanceof SslConnectionInit }
27+
28+
predicate isSink(DataFlow::Node sink) { sink instanceof SslConnectionCreation }
29+
30+
predicate isBarrier(DataFlow::Node sanitizer) { sanitizer instanceof SslUnsafeCertTrustSanitizer }
31+
}
32+
33+
module SslEndpointIdentificationFlow = TaintTracking::Global<SslEndpointIdentificationFlowConfig>;
34+
2335
/**
2436
* An SSL object that was assigned a safe `SSLParameters` object and can be considered safe.
2537
*/
2638
private class SslConnectionWithSafeSslParameters extends SslUnsafeCertTrustSanitizer {
2739
SslConnectionWithSafeSslParameters() {
28-
exists(SafeSslParametersFlowConfig config, DataFlow::Node safe, DataFlow::Node sanitizer |
29-
config.hasFlowTo(safe) and
40+
exists(DataFlow::Node safe, DataFlow::Node sanitizer |
41+
SafeSslParametersFlow::flowTo(safe) and
3042
sanitizer = DataFlow::exprNode(safe.asExpr().(Argument).getCall().getQualifier()) and
3143
DataFlow::localFlow(sanitizer, this)
3244
)
3345
}
3446
}
3547

36-
private class SafeSslParametersFlowConfig extends DataFlow2::Configuration {
37-
SafeSslParametersFlowConfig() { this = "SafeSslParametersFlowConfig" }
38-
39-
override predicate isSource(DataFlow::Node source) {
48+
private module SafeSslParametersFlowConfig implements DataFlow::ConfigSig {
49+
predicate isSource(DataFlow::Node source) {
4050
exists(MethodAccess ma |
4151
ma instanceof SafeSetEndpointIdentificationAlgorithm and
4252
DataFlow::getInstanceArgument(ma) = source.(DataFlow::PostUpdateNode).getPreUpdateNode()
4353
)
4454
}
4555

46-
override predicate isSink(DataFlow::Node sink) {
56+
predicate isSink(DataFlow::Node sink) {
4757
exists(MethodAccess ma, RefType t | t instanceof SslSocket or t instanceof SslEngine |
4858
ma.getMethod().hasName("setSSLParameters") and
4959
ma.getMethod().getDeclaringType().getAnAncestor() = t and
@@ -52,6 +62,8 @@ private class SafeSslParametersFlowConfig extends DataFlow2::Configuration {
5262
}
5363
}
5464

65+
private module SafeSslParametersFlow = DataFlow::Global<SafeSslParametersFlowConfig>;
66+
5567
/**
5668
* A call to `SSLParameters.setEndpointIdentificationAlgorithm` with a non-null and non-empty parameter.
5769
*/

java/ql/src/Security/CWE/CWE-273/UnsafeCertTrust.ql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,5 @@ import semmle.code.java.security.UnsafeCertTrustQuery
1818
from Expr unsafeTrust
1919
where
2020
unsafeTrust instanceof RabbitMQEnableHostnameVerificationNotSet or
21-
exists(SslEndpointIdentificationFlowConfig config |
22-
config.hasFlowTo(DataFlow::exprNode(unsafeTrust))
23-
)
21+
SslEndpointIdentificationFlow::flowTo(DataFlow::exprNode(unsafeTrust))
2422
select unsafeTrust, "Unsafe configuration of trusted certificates."

java/ql/test/query-tests/security/CWE-273/UnsafeCertTrustTest.ql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ class UnsafeCertTrustTest extends InlineExpectationsTest {
1212
exists(Expr unsafeTrust |
1313
unsafeTrust instanceof RabbitMQEnableHostnameVerificationNotSet
1414
or
15-
exists(SslEndpointIdentificationFlowConfig config |
16-
config.hasFlowTo(DataFlow::exprNode(unsafeTrust))
17-
)
15+
SslEndpointIdentificationFlow::flowTo(DataFlow::exprNode(unsafeTrust))
1816
|
1917
unsafeTrust.getLocation() = location and
2018
element = unsafeTrust.toString() and

0 commit comments

Comments
 (0)