File tree Expand file tree Collapse file tree
src/experimental/Security/CWE/CWE-297
test/experimental/query-tests/security/CWE-297 Expand file tree Collapse file tree Original file line number Diff line number Diff 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
6568from HostnameVerificationCall verification
6669where verification .isIgnored ( )
67- select verification , "Ignored result of hostname verification."
70+ select verification , "Ignored result of hostname verification."
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments