File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed
src/experimental/Security/CWE/CWE-297
test/experimental/query-tests/security/CWE-297 Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -51,8 +51,11 @@ private class CheckFailedHostnameVerificationConfig extends DataFlow::Configurat
51
51
}
52
52
53
53
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
56
59
(
57
60
guard = sink .asExpr ( ) or
58
61
guard .( EqualityTest ) .getAnOperand ( ) = sink .asExpr ( ) or
@@ -64,4 +67,4 @@ private class CheckFailedHostnameVerificationConfig extends DataFlow::Configurat
64
67
65
68
from HostnameVerificationCall verification
66
69
where 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(
90
90
throw new SSLException ("Oops! Hostname verification failed!" );
91
91
}
92
92
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
+
93
106
public static class HostnameVerifierWrapper implements HostnameVerifier {
94
107
95
108
private final HostnameVerifier verifier ;
96
109
97
110
public HostnameVerifierWrapper (HostnameVerifier verifier ) {
98
- this .verifier = verifier ;
111
+ this .verifier = verifier ;
99
112
}
100
113
101
114
@ Override
102
115
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
104
117
}
105
118
106
119
}
You can’t perform that action at this time.
0 commit comments