mirror of
https://github.com/github/codeql.git
synced 2026-04-27 17:55:19 +02:00
Fixed another false-positive in CWE-297/IgnoredHostnameVerification.ql
This commit is contained in:
@@ -51,8 +51,11 @@ private class CheckFailedHostnameVerificationConfig extends DataFlow::Configurat
|
||||
}
|
||||
|
||||
override predicate isSink(DataFlow::Node sink) {
|
||||
exists(Guard guard, ThrowStmt throwStmt |
|
||||
guard.controls(throwStmt.getBasicBlock(), _) and
|
||||
exists(Guard guard, ThrowStmt throwStmt, ReturnStmt returnStmt |
|
||||
(
|
||||
guard.controls(throwStmt.getBasicBlock(), false) or
|
||||
guard.controls(returnStmt.getBasicBlock(), true)
|
||||
) and
|
||||
(
|
||||
guard = sink.asExpr() or
|
||||
guard.(EqualityTest).getAnOperand() = sink.asExpr() or
|
||||
@@ -64,4 +67,4 @@ private class CheckFailedHostnameVerificationConfig extends DataFlow::Configurat
|
||||
|
||||
from HostnameVerificationCall verification
|
||||
where verification.isIgnored()
|
||||
select verification, "Ignored result of hostname verification."
|
||||
select verification, "Ignored result of hostname verification."
|
||||
|
||||
@@ -90,17 +90,30 @@ public class IgnoredHostnameVerification {
|
||||
throw new SSLException("Oops! Hostname verification failed!");
|
||||
}
|
||||
|
||||
// GOOD: connect and check result of HostnameVerifier.verify()
|
||||
public static String connectWithHostnameVerification04(
|
||||
String[] hosts, HostnameVerifier verifier, SSLSession session) throws IOException {
|
||||
|
||||
for (String host : hosts) {
|
||||
if (verifier.verify(host, session)) {
|
||||
return host;
|
||||
}
|
||||
}
|
||||
|
||||
throw new SSLException("Oops! Hostname verification failed!");
|
||||
}
|
||||
|
||||
public static class HostnameVerifierWrapper implements HostnameVerifier {
|
||||
|
||||
private final HostnameVerifier verifier;
|
||||
|
||||
public HostnameVerifierWrapper(HostnameVerifier verifier) {
|
||||
this.verifier = verifier;
|
||||
this.verifier = verifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean verify(String hostname, SSLSession session) {
|
||||
return verifier.verify(hostname, session); // GOOD: wrapped calls should not be reported
|
||||
return verifier.verify(hostname, session); // GOOD: wrapped calls should not be reported
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user