Skip to content

Commit dcd46c2

Browse files
committed
Refactor InsecureTrustManager
1 parent 3b2eea2 commit dcd46c2

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import semmle.code.java.dataflow.FlowSources
55
import semmle.code.java.security.InsecureTrustManager
66

77
/**
8+
* DEPRECATED: Use `InsecureTrustManagerFlow` instead.
9+
*
810
* A configuration to model the flow of an insecure `TrustManager`
911
* to the initialization of an SSL context.
1012
*/
11-
class InsecureTrustManagerConfiguration extends DataFlow::Configuration {
13+
deprecated class InsecureTrustManagerConfiguration extends DataFlow::Configuration {
1214
InsecureTrustManagerConfiguration() { this = "InsecureTrustManagerConfiguration" }
1315

1416
override predicate isSource(DataFlow::Node source) {
@@ -23,3 +25,21 @@ class InsecureTrustManagerConfiguration extends DataFlow::Configuration {
2325
c instanceof DataFlow::ArrayContent
2426
}
2527
}
28+
29+
/**
30+
* A configuration to model the flow of an insecure `TrustManager`
31+
* to the initialization of an SSL context.
32+
*/
33+
private module InsecureTrustManagerConfig implements DataFlow::ConfigSig {
34+
predicate isSource(DataFlow::Node source) { source instanceof InsecureTrustManagerSource }
35+
36+
predicate isSink(DataFlow::Node sink) { sink instanceof InsecureTrustManagerSink }
37+
38+
predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet c) {
39+
(isSink(node) or isAdditionalFlowStep(node, _)) and
40+
node.getType() instanceof Array and
41+
c instanceof DataFlow::ArrayContent
42+
}
43+
}
44+
45+
module InsecureTrustManagerFlow = DataFlow::Global<InsecureTrustManagerConfig>;

java/ql/src/Security/CWE/CWE-295/InsecureTrustManager.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
import java
1414
import semmle.code.java.dataflow.DataFlow
1515
import semmle.code.java.security.InsecureTrustManagerQuery
16-
import DataFlow::PathGraph
16+
import InsecureTrustManagerFlow::PathGraph
1717

18-
from DataFlow::PathNode source, DataFlow::PathNode sink
19-
where any(InsecureTrustManagerConfiguration cfg).hasFlowPath(source, sink)
18+
from InsecureTrustManagerFlow::PathNode source, InsecureTrustManagerFlow::PathNode sink
19+
where InsecureTrustManagerFlow::flowPath(source, sink)
2020
select sink, source, sink, "This uses $@, which is defined in $@ and trusts any certificate.",
2121
source, "TrustManager",
2222
source.getNode().asExpr().(ClassInstanceExpr).getConstructedType() as type, type.nestedName()
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import java
22
import semmle.code.java.security.InsecureTrustManagerQuery
3-
import TestUtilities.InlineFlowTest
3+
import TestUtilities.InlineExpectationsTest
44

5-
class EnableLegacy extends EnableLegacyConfiguration {
6-
EnableLegacy() { exists(this) }
7-
}
5+
class InsecureTrustManagerTest extends InlineExpectationsTest {
6+
InsecureTrustManagerTest() { this = "InsecureTrustManagerTest" }
7+
8+
override string getARelevantTag() { result = "hasValueFlow" }
89

9-
class InsecureTrustManagerTest extends InlineFlowTest {
10-
override DataFlow::Configuration getValueFlowConfig() {
11-
result = any(InsecureTrustManagerConfiguration c)
10+
override predicate hasActualResult(Location location, string element, string tag, string value) {
11+
tag = "hasValueFlow" and
12+
exists(DataFlow::Node sink | InsecureTrustManagerFlow::flowTo(sink) |
13+
sink.getLocation() = location and
14+
element = sink.toString() and
15+
value = ""
16+
)
1217
}
1318
}

0 commit comments

Comments
 (0)