Skip to content

Commit 825fe17

Browse files
Fixed another false-positive in CWE-297/IgnoredHostnameVerification.ql
1 parent 6dad0e2 commit 825fe17

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
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
@@ -51,8 +51,11 @@ private class CheckFailedHostnameVerificationConfig extends DataFlow::Configurat
5151
}
5252

5353
override predicate isSink(DataFlow::Node sink) {
54-
exists(Guard guard, ThrowStmt throwStmt |
55-
guard.controls(throwStmt.getBasicBlock(), _) and
54+
exists(Guard guard, ThrowStmt throwStmt, ReturnStmt returnStmt |
55+
(
56+
guard.controls(throwStmt.getBasicBlock(), false) or
57+
guard.controls(returnStmt.getBasicBlock(), true)
58+
) and
5659
(
5760
guard = sink.asExpr() or
5861
guard.(EqualityTest).getAnOperand() = sink.asExpr() or
@@ -64,4 +67,4 @@ private class CheckFailedHostnameVerificationConfig extends DataFlow::Configurat
6467

6568
from HostnameVerificationCall verification
6669
where verification.isIgnored()
67-
select verification, "Ignored result of hostname verification."
70+
select verification, "Ignored result of hostname verification."

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,30 @@ public static SSLSocket connectWithHostnameVerification03(
9090
throw new SSLException("Oops! Hostname verification failed!");
9191
}
9292

93+
// GOOD: connect and check result of HostnameVerifier.verify()
94+
public static String connectWithHostnameVerification04(
95+
String[] hosts, HostnameVerifier verifier, SSLSession session) throws IOException {
96+
97+
for (String host : hosts) {
98+
if (verifier.verify(host, session)) {
99+
return host;
100+
}
101+
}
102+
103+
throw new SSLException("Oops! Hostname verification failed!");
104+
}
105+
93106
public static class HostnameVerifierWrapper implements HostnameVerifier {
94107

95108
private final HostnameVerifier verifier;
96109

97110
public HostnameVerifierWrapper(HostnameVerifier verifier) {
98-
this.verifier = verifier;
111+
this.verifier = verifier;
99112
}
100113

101114
@Override
102115
public boolean verify(String hostname, SSLSession session) {
103-
return verifier.verify(hostname, session); // GOOD: wrapped calls should not be reported
116+
return verifier.verify(hostname, session); // GOOD: wrapped calls should not be reported
104117
}
105118

106119
}

0 commit comments

Comments
 (0)