23
23
*/
24
24
25
25
import javascript
26
+ private import semmle.javascript.frameworks.ConnectExpressShared:: ConnectExpressShared
26
27
27
28
// main concepts
28
29
/**
@@ -160,8 +161,8 @@ class RouteHandlerLimitedByExpressLimiter extends RateLimitedRouteHandlerExpr {
160
161
* A rate-handler function implemented using one of the rate-limiting classes provided
161
162
* by the `rate-limiter-flexible` package.
162
163
*
163
- * We look for functions that invoke the `consume` method of one of the `RateLimiter*`
164
- * classes from the `rate-limiter-flexible` package on a property of their first argument ,
164
+ * We look for route handlers that invoke the `consume` method of one of the `RateLimiter*`
165
+ * classes from the `rate-limiter-flexible` package on a property of their request parameter ,
165
166
* like the `rateLimiterMiddleware` function in this example:
166
167
*
167
168
* ```
@@ -176,14 +177,13 @@ class RateLimiterFlexibleRateLimiter extends DataFlow::FunctionNode {
176
177
RateLimiterFlexibleRateLimiter ( ) {
177
178
exists (
178
179
string rateLimiterClassName , DataFlow:: SourceNode rateLimiterClass ,
179
- DataFlow:: SourceNode rateLimiterInstance
180
+ DataFlow:: SourceNode rateLimiterInstance , DataFlow :: ParameterNode request
180
181
|
181
182
rateLimiterClassName .matches ( "RateLimiter%" ) and
182
183
rateLimiterClass = DataFlow:: moduleMember ( "rate-limiter-flexible" , rateLimiterClassName ) and
183
184
rateLimiterInstance = rateLimiterClass .getAnInstantiation ( ) and
184
- getParameter ( 0 ) .getAPropertyRead ( ) = rateLimiterInstance
185
- .getAMemberCall ( "consume" )
186
- .getAnArgument ( )
185
+ request .getParameter ( ) = getRouteHandlerParameter ( getFunction ( ) , "request" ) and
186
+ request .getAPropertyRead ( ) = rateLimiterInstance .getAMemberCall ( "consume" ) .getAnArgument ( )
187
187
)
188
188
}
189
189
}
0 commit comments