44 * A caller has to check the result and drop the connection if the verification failed.
55 * @kind problem
66 * @problem.severity error
7- * @precision medium
7+ * @precision high
88 * @id java/ignored-hostname-verification
99 * @tags security
1010 * external/cwe/cwe-297
1111 */
1212
1313import java
14- import semmle.code.java.controlflow.Guards
15- import semmle.code.java.dataflow.DataFlow
1614
1715/** The `HostnameVerifier.verify()` method. */
1816private class HostnameVerifierVerifyMethod extends Method {
@@ -22,45 +20,17 @@ private class HostnameVerifierVerifyMethod extends Method {
2220 }
2321}
2422
25- /** Defines `HostnameVerifier.verity()` calls that are not wrapped by another `HostnameVerifier`. */
23+ /** Defines `HostnameVerifier.verity()` calls that is not wrapped in another `HostnameVerifier`. */
2624private class HostnameVerificationCall extends MethodAccess {
2725 HostnameVerificationCall ( ) {
2826 this .getMethod ( ) instanceof HostnameVerifierVerifyMethod and
2927 not this .getCaller ( ) instanceof HostnameVerifierVerifyMethod
3028 }
3129
32- /** Holds if the result if the call is not useds . */
30+ /** Holds if the result of the call is not used . */
3331 predicate isIgnored ( ) {
34- not exists (
35- DataFlow:: Node source , DataFlow:: Node sink , CheckFailedHostnameVerificationConfig config
36- |
37- this = source .asExpr ( ) and config .hasFlow ( source , sink )
38- )
39- }
40- }
41-
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 {
47- CheckFailedHostnameVerificationConfig ( ) { this = "CheckFailedHostnameVerificationConfig" }
48-
49- override predicate isSource ( DataFlow:: Node source ) {
50- source .asExpr ( ) instanceof HostnameVerificationCall
51- }
52-
53- override predicate isSink ( DataFlow:: Node sink ) {
54- exists ( Guard guard , ThrowStmt throwStmt , ReturnStmt returnStmt |
55- (
56- guard .controls ( throwStmt .getBasicBlock ( ) , false ) or
57- guard .controls ( returnStmt .getBasicBlock ( ) , true )
58- ) and
59- (
60- guard = sink .asExpr ( ) or
61- guard .( EqualityTest ) .getAnOperand ( ) = sink .asExpr ( ) or
62- guard .( HostnameVerificationCall ) = sink .asExpr ( )
63- )
32+ not exists ( Expr expr , IfStmt ifStmt , MethodAccess ma |
33+ this = [ expr .getAChildExpr ( ) , ifStmt .getCondition ( ) , ma .getAnArgument ( ) ]
6434 )
6535 }
6636}
0 commit comments