Skip to content

Commit e544fae

Browse files
committed
Java: Convert unsafe hostname verification sinks to CSV format
1 parent 17fd758 commit e544fae

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

java/ql/src/Security/CWE/CWE-297/UnsafeHostnameVerification.ql

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import semmle.code.java.dataflow.DataFlow
1515
import semmle.code.java.dataflow.FlowSources
1616
import semmle.code.java.security.Encryption
1717
import DataFlow::PathGraph
18+
private import semmle.code.java.dataflow.ExternalFlow
1819

1920
/**
2021
* Holds if `m` always returns `true` ignoring any exceptional flow.
@@ -49,14 +50,7 @@ class TrustAllHostnameVerifierConfiguration extends DataFlow::Configuration {
4950
source.asExpr().(ClassInstanceExpr).getConstructedType() instanceof TrustAllHostnameVerifier
5051
}
5152

52-
override predicate isSink(DataFlow::Node sink) {
53-
exists(MethodAccess ma, Method m |
54-
(m instanceof SetDefaultHostnameVerifierMethod or m instanceof SetHostnameVerifierMethod) and
55-
ma.getMethod() = m
56-
|
57-
ma.getArgument(0) = sink.asExpr()
58-
)
59-
}
53+
override predicate isSink(DataFlow::Node sink) { sinkNode(sink, "set-hostname") }
6054

6155
override predicate isBarrier(DataFlow::Node barrier) {
6256
// ignore nodes that are in functions that intentionally disable hostname verification

java/ql/src/semmle/code/java/dataflow/ExternalFlow.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,10 @@ private predicate sinkModelCsv(string row) {
207207
"java.nio.file;Files;false;createTempDirectory;;;Argument[0];create-file",
208208
"java.nio.file;Files;false;createTempFile;;;Argument[0];create-file",
209209
// Bean validation
210-
"javax.validation;ConstraintValidatorContext;true;buildConstraintViolationWithTemplate;;;Argument[0];bean-validation"
210+
"javax.validation;ConstraintValidatorContext;true;buildConstraintViolationWithTemplate;;;Argument[0];bean-validation",
211+
// Set hostname
212+
"javax.net.ssl;HttpsURLConnection;true;setDefaultHostnameVerifier;;;Argument[0];set-hostname",
213+
"javax.net.ssl;HttpsURLConnection;true;setHostnameVerifier;;;Argument[0];set-hostname"
211214
]
212215
}
213216

0 commit comments

Comments
 (0)