Skip to content

Commit f78002b

Browse files
Fixed a false-positive in CWE-297/IgnoredHostnameVerification.ql
1 parent e11cb94 commit f78002b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

java/ql/src/experimental/Security/CWE/CWE-297/IgnoredHostnameVerification.ql

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import java
1414
import semmle.code.java.controlflow.Guards
15-
import semmle.code.java.dataflow.DataFlow
15+
import semmle.code.java.dataflow.TaintTracking
1616

1717
private class HostnameVerificationCall extends MethodAccess {
1818
HostnameVerificationCall() {
@@ -27,12 +27,14 @@ private class HostnameVerificationCall extends MethodAccess {
2727
not exists(
2828
DataFlow::Node source, DataFlow::Node sink, CheckFailedHostnameVerificationConfig config
2929
|
30-
this = source.asExpr() and config.hasFlow(source, sink)
30+
this = source.asExpr()
31+
|
32+
config.hasFlow(source, sink)
3133
)
3234
}
3335
}
3436

35-
private class CheckFailedHostnameVerificationConfig extends DataFlow::Configuration {
37+
private class CheckFailedHostnameVerificationConfig extends TaintTracking::Configuration {
3638
CheckFailedHostnameVerificationConfig() { this = "CheckFailedHostnameVerificationConfig" }
3739

3840
override predicate isSource(DataFlow::Node source) {
@@ -43,6 +45,7 @@ private class CheckFailedHostnameVerificationConfig extends DataFlow::Configurat
4345
exists(Guard guard, ThrowStmt throwStmt |
4446
guard.controls(throwStmt.getBasicBlock(), _) and
4547
(
48+
guard = sink.asExpr() or
4649
guard.(EqualityTest).getAnOperand() = sink.asExpr() or
4750
guard.(HostnameVerificationCall) = sink.asExpr()
4851
)

java/ql/test/experimental/query-tests/security/CWE-297/IgnoredHostnameVerification.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ public static SSLSocket connectWithHostnameVerification02(
6262

6363
SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket(host, port);
6464
socket.startHandshake();
65-
boolean successful = verifier.verify(host, socket.getSession());
65+
boolean successful = false;
66+
if (verifier != null) {
67+
successful = verifier.verify(host, socket.getSession());
68+
}
6669
if (!successful) {
6770
socket.close();
6871
throw new SSLException("Oops! Hostname verification failed!");

0 commit comments

Comments
 (0)