Skip to content

Commit 7a48409

Browse files
committed
JS: Recognize Fastify per-route rate limiting
1 parent fef582c commit 7a48409

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

javascript/ql/lib/semmle/javascript/security/dataflow/MissingRateLimiting.qll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,21 @@ class RouteHandlerLimitedByRateLimiterFlexible extends RateLimitingMiddleware in
191191
private class FastifyRateLimiter extends RateLimitingMiddleware {
192192
FastifyRateLimiter() { this = DataFlow::moduleImport("fastify-rate-limit") }
193193
}
194+
195+
/**
196+
* An options object with a `rateLimit` config passed to a Fastify shorthand route method,
197+
* such as `fastify.post('/path', { config: { rateLimit: { ... } } }, handler)`.
198+
*/
199+
private class FastifyPerRouteRateLimit extends RateLimitingMiddleware {
200+
FastifyPerRouteRateLimit() {
201+
exists(Fastify::RouteSetup setup |
202+
not setup.getMethodName() = ["route", "addHook"] and
203+
setup.getNumArgument() >= 3 and
204+
this.flowsTo(setup.getArgument(1))
205+
|
206+
exists(this.getAPropertySource("config").getAPropertySource("rateLimit"))
207+
or
208+
exists(this.getAPropertySource("rateLimit"))
209+
)
210+
}
211+
}
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#select
21
| MissingRateLimiting.js:4:19:8:1 | functio ... ath);\\n} | This route handler performs $@, but is not rate-limited. | MissingRateLimiting.js:7:5:7:22 | res.sendFile(path) | a file system access |
32
| MissingRateLimiting.js:25:19:25:20 | f1 | This route handler performs $@, but is not rate-limited. | MissingRateLimiting.js:13:5:13:22 | res.sendFile(path) | a file system access |
43
| MissingRateLimiting.js:25:27:25:28 | f3 | This route handler performs $@, but is not rate-limited. | MissingRateLimiting.js:22:5:22:22 | res.sendFile(path) | a file system access |
@@ -10,9 +9,4 @@
109
| tst.js:64:25:64:63 | functio ... req); } | This route handler performs $@, but is not rate-limited. | tst.js:64:46:64:60 | verifyUser(req) | authorization |
1110
| tst.js:76:25:76:53 | catchAs ... ndler1) | This route handler performs $@, but is not rate-limited. | tst.js:14:40:14:46 | login() | authorization |
1211
| tst.js:88:24:88:40 | expensiveHandler1 | This route handler performs $@, but is not rate-limited. | tst.js:14:40:14:46 | login() | authorization |
13-
| tst.js:103:4:103:20 | expensiveHandler1 | This route handler performs $@, but is not rate-limited. | tst.js:14:40:14:46 | login() | authorization |
14-
| tst.js:110:4:110:20 | expensiveHandler1 | This route handler performs $@, but is not rate-limited. | tst.js:14:40:14:46 | login() | authorization |
1512
| tst.js:112:28:112:44 | expensiveHandler1 | This route handler performs $@, but is not rate-limited. | tst.js:14:40:14:46 | login() | authorization |
16-
testFailures
17-
| tst.js:103:4:103:20 | This route handler performs $@, but is not rate-limited. | Unexpected result: Alert |
18-
| tst.js:110:4:110:20 | This route handler performs $@, but is not rate-limited. | Unexpected result: Alert |

0 commit comments

Comments
 (0)