10
10
* external/cwe/cwe-208
11
11
*/
12
12
13
-
14
13
import java
15
14
import semmle.code.java.dataflow.FlowSources
16
15
import semmle.code.java.dataflow.TaintTracking
@@ -28,29 +27,26 @@ private class NonConstantTimeComparisonCall extends StaticMethodAccess {
28
27
/** Methods that use a non-constant-time algorithm for comparing inputs. */
29
28
private class NonConstantTimeEqualsCall extends MethodAccess {
30
29
NonConstantTimeEqualsCall ( ) {
31
- this .getMethod ( ) .hasQualifiedName ( "java.lang" , "String" , [ "equals" , "contentEquals" , "equalsIgnoreCase" ] )
30
+ this .getMethod ( )
31
+ .hasQualifiedName ( "java.lang" , "String" , [ "equals" , "contentEquals" , "equalsIgnoreCase" ] )
32
32
}
33
33
}
34
34
35
35
private predicate isNonConstantEqualsCallArgument ( Expr e ) {
36
- exists ( NonConstantTimeEqualsCall call |
37
- e = [ call .getQualifier ( ) , call .getArgument ( 0 ) ]
38
- )
36
+ exists ( NonConstantTimeEqualsCall call | e = [ call .getQualifier ( ) , call .getArgument ( 0 ) ] )
39
37
}
40
38
41
39
private predicate isNonConstantComparisonCallArgument ( Expr p ) {
42
- exists ( NonConstantTimeComparisonCall call |
43
- p = [ call .getArgument ( 0 ) , call .getArgument ( 1 ) ]
44
- )
40
+ exists ( NonConstantTimeComparisonCall call | p = [ call .getArgument ( 0 ) , call .getArgument ( 1 ) ] )
45
41
}
46
42
47
43
class ClientSuppliedIpTokenCheck extends DataFlow:: Node {
48
44
ClientSuppliedIpTokenCheck ( ) {
49
45
exists ( MethodAccess ma |
50
46
ma .getMethod ( ) .hasName ( "getHeader" ) and
51
47
ma .getArgument ( 0 ) .( CompileTimeConstantExpr ) .getStringValue ( ) .toLowerCase ( ) in [
52
- "x-auth-token" , "x-csrf-token" , "http_x_csrf_token" , "x-csrf-param" , "x-csrf-header" ,
53
- "http_x_csrf_token" , "x-api-key" , "authorization" , "proxy-authorization"
48
+ "x-auth-token" , "x-csrf-token" , "http_x_csrf_token" , "x-csrf-param" , "x-csrf-header" ,
49
+ "http_x_csrf_token" , "x-api-key" , "authorization" , "proxy-authorization"
54
50
] and
55
51
ma = this .asExpr ( )
56
52
)
@@ -60,14 +56,17 @@ class ClientSuppliedIpTokenCheck extends DataFlow::Node {
60
56
class NonConstantTimeComparisonConfig extends TaintTracking:: Configuration {
61
57
NonConstantTimeComparisonConfig ( ) { this = "NonConstantTimeComparisonConfig" }
62
58
63
- override predicate isSource ( DataFlow:: Node source ) { source instanceof ClientSuppliedIpTokenCheck }
59
+ override predicate isSource ( DataFlow:: Node source ) {
60
+ source instanceof ClientSuppliedIpTokenCheck
61
+ }
64
62
65
- override predicate isSink ( DataFlow:: Node sink ) {
66
- isNonConstantEqualsCallArgument ( sink .asExpr ( ) ) or
63
+ override predicate isSink ( DataFlow:: Node sink ) {
64
+ isNonConstantEqualsCallArgument ( sink .asExpr ( ) ) or
67
65
isNonConstantComparisonCallArgument ( sink .asExpr ( ) )
68
66
}
69
67
}
70
68
71
69
from DataFlow:: PathNode source , DataFlow:: PathNode sink , NonConstantTimeComparisonConfig conf
72
70
where conf .hasFlowPath ( source , sink )
73
- select sink .getNode ( ) , source , sink , "Possible timing attack against $@ validation." , source .getNode ( )
71
+ select sink .getNode ( ) , source , sink , "Possible timing attack against $@ validation." ,
72
+ source .getNode ( )
0 commit comments