1010 * external/cwe/cwe-208
1111 */
1212
13-
1413import java
1514import semmle.code.java.dataflow.FlowSources
1615import semmle.code.java.dataflow.TaintTracking
@@ -28,29 +27,26 @@ private class NonConstantTimeComparisonCall extends StaticMethodAccess {
2827/** Methods that use a non-constant-time algorithm for comparing inputs. */
2928private class NonConstantTimeEqualsCall extends MethodAccess {
3029 NonConstantTimeEqualsCall ( ) {
31- this .getMethod ( ) .hasQualifiedName ( "java.lang" , "String" , [ "equals" , "contentEquals" , "equalsIgnoreCase" ] )
30+ this .getMethod ( )
31+ .hasQualifiedName ( "java.lang" , "String" , [ "equals" , "contentEquals" , "equalsIgnoreCase" ] )
3232 }
3333}
3434
3535private 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 ) ] )
3937}
4038
4139private 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 ) ] )
4541}
4642
4743class ClientSuppliedIpTokenCheck extends DataFlow:: Node {
4844 ClientSuppliedIpTokenCheck ( ) {
4945 exists ( MethodAccess ma |
5046 ma .getMethod ( ) .hasName ( "getHeader" ) and
5147 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"
5450 ] and
5551 ma = this .asExpr ( )
5652 )
@@ -60,14 +56,17 @@ class ClientSuppliedIpTokenCheck extends DataFlow::Node {
6056class NonConstantTimeComparisonConfig extends TaintTracking:: Configuration {
6157 NonConstantTimeComparisonConfig ( ) { this = "NonConstantTimeComparisonConfig" }
6258
63- override predicate isSource ( DataFlow:: Node source ) { source instanceof ClientSuppliedIpTokenCheck }
59+ override predicate isSource ( DataFlow:: Node source ) {
60+ source instanceof ClientSuppliedIpTokenCheck
61+ }
6462
65- override predicate isSink ( DataFlow:: Node sink ) {
66- isNonConstantEqualsCallArgument ( sink .asExpr ( ) ) or
63+ override predicate isSink ( DataFlow:: Node sink ) {
64+ isNonConstantEqualsCallArgument ( sink .asExpr ( ) ) or
6765 isNonConstantComparisonCallArgument ( sink .asExpr ( ) )
6866 }
6967}
7068
7169from DataFlow:: PathNode source , DataFlow:: PathNode sink , NonConstantTimeComparisonConfig conf
7270where 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