77 * @precision medium
88 * @id java/ignored-hostname-verification
99 * @tags security
10- * external/cwe/cwe-295
10+ * external/cwe/cwe-297
1111 */
1212
1313import java
1414import semmle.code.java.controlflow.Guards
15- import semmle.code.java.dataflow.TaintTracking
15+ import semmle.code.java.dataflow.DataFlow
1616
17+ /** The `HostnameVerifier.verify()` method. */
18+ private class HostnameVerifierVerifyMethod extends Method {
19+ HostnameVerifierVerifyMethod ( ) {
20+ this .getDeclaringType ( ) .getASupertype * ( ) .hasQualifiedName ( "javax.net.ssl" , "HostnameVerifier" ) and
21+ this .hasStringSignature ( "verify(String, SSLSession)" )
22+ }
23+ }
24+
25+ /** Defines `HostnameVerifier.verity()` calls that are not wrapped by another `HostnameVerifier`. */
1726private class HostnameVerificationCall extends MethodAccess {
1827 HostnameVerificationCall ( ) {
19- getMethod ( )
20- .getDeclaringType ( )
21- .getASupertype * ( )
22- .hasQualifiedName ( "javax.net.ssl" , "HostnameVerifier" ) and
23- getMethod ( ) .hasStringSignature ( "verify(String, SSLSession)" )
28+ this .getMethod ( ) instanceof HostnameVerifierVerifyMethod and
29+ not this .getCaller ( ) instanceof HostnameVerifierVerifyMethod
2430 }
2531
26- predicate ignored ( ) {
32+ /** Holds if the result if the call is not useds. */
33+ predicate isIgnored ( ) {
2734 not exists (
2835 DataFlow:: Node source , DataFlow:: Node sink , CheckFailedHostnameVerificationConfig config
2936 |
30- this = source .asExpr ( )
31- |
32- config .hasFlow ( source , sink )
37+ this = source .asExpr ( ) and config .hasFlow ( source , sink )
3338 )
3439 }
3540}
3641
37- private class CheckFailedHostnameVerificationConfig extends TaintTracking:: Configuration {
42+ /**
43+ * A configuration that tracks data flows from the result of a `HostnameVerifier.vefiry()` call
44+ * to a condition that controls a throw statement.
45+ */
46+ private class CheckFailedHostnameVerificationConfig extends DataFlow:: Configuration {
3847 CheckFailedHostnameVerificationConfig ( ) { this = "CheckFailedHostnameVerificationConfig" }
3948
4049 override predicate isSource ( DataFlow:: Node source ) {
@@ -54,5 +63,5 @@ private class CheckFailedHostnameVerificationConfig extends TaintTracking::Confi
5463}
5564
5665from HostnameVerificationCall verification
57- where verification .ignored ( )
58- select verification , "Ignored result of hostname verification."
66+ where verification .isIgnored ( )
67+ select verification , "Ignored result of hostname verification."
0 commit comments