4
4
* A caller has to check the result and drop the connection if the verification failed.
5
5
* @kind problem
6
6
* @problem.severity error
7
- * @precision medium
7
+ * @precision high
8
8
* @id java/ignored-hostname-verification
9
9
* @tags security
10
10
* external/cwe/cwe-297
11
11
*/
12
12
13
13
import java
14
- import semmle.code.java.controlflow.Guards
15
- import semmle.code.java.dataflow.DataFlow
16
14
17
15
/** The `HostnameVerifier.verify()` method. */
18
16
private class HostnameVerifierVerifyMethod extends Method {
@@ -22,45 +20,17 @@ private class HostnameVerifierVerifyMethod extends Method {
22
20
}
23
21
}
24
22
25
- /** Defines `HostnameVerifier.verity()` calls that are not wrapped by another `HostnameVerifier`. */
23
+ /** Defines `HostnameVerifier.verity()` calls that is not wrapped in another `HostnameVerifier`. */
26
24
private class HostnameVerificationCall extends MethodAccess {
27
25
HostnameVerificationCall ( ) {
28
26
this .getMethod ( ) instanceof HostnameVerifierVerifyMethod and
29
27
not this .getCaller ( ) instanceof HostnameVerifierVerifyMethod
30
28
}
31
29
32
- /** Holds if the result if the call is not useds . */
30
+ /** Holds if the result of the call is not used . */
33
31
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 ( ) ]
64
34
)
65
35
}
66
36
}
0 commit comments