Merge pull request #22222 from cysp/fastify-scoped-rate-limit

JS: Recognize @fastify/rate-limit as a rate limiter
This commit is contained in:
Asger F
2026-07-27 13:02:25 +02:00
committed by GitHub
4 changed files with 16 additions and 3 deletions

View File

@@ -189,7 +189,9 @@ class RouteHandlerLimitedByRateLimiterFlexible extends RateLimitingMiddleware in
{ }
private class FastifyRateLimiter extends RateLimitingMiddleware {
FastifyRateLimiter() { this = DataFlow::moduleImport("fastify-rate-limit") }
FastifyRateLimiter() {
this = DataFlow::moduleImport(["fastify-rate-limit", "@fastify/rate-limit"])
}
}
/**

View File

@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* The `js/missing-rate-limiting` query now recognizes the `@fastify/rate-limit` package as a rate limiter.

View File

@@ -9,4 +9,5 @@
| 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 |
| 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 |
| tst.js:88:24:88:40 | expensiveHandler1 | This route handler performs $@, but is not rate-limited. | tst.js:14:40:14:46 | login() | authorization |
| tst.js:112:28:112:44 | expensiveHandler1 | This route handler performs $@, but is not rate-limited. | tst.js:14:40:14:46 | login() | authorization |
| tst.js:111:28:111:44 | expensiveHandler1 | This route handler performs $@, but is not rate-limited. | tst.js:14:40:14:46 | login() | authorization |
| tst.js:116:39:116:55 | expensiveHandler1 | This route handler performs $@, but is not rate-limited. | tst.js:14:40:14:46 | login() | authorization |

View File

@@ -91,7 +91,6 @@ fastifyApp.get('/bar', expensiveHandler1);
// Fastify per-route rate limiting via config.rateLimit
const fastifyApp2 = require('fastify')();
fastifyApp2.register(require('@fastify/rate-limit'));
fastifyApp2.post('/login', {
config: {
@@ -110,3 +109,10 @@ fastifyApp2.post('/signup', {
}, expensiveHandler1); // OK - has per-route rateLimit directly in options
fastifyApp2.post('/other', expensiveHandler1); // $ Alert - no rate limiting
// rate limiting using the scoped package name
const fastifyApp3 = require('fastify')();
fastifyApp3.get('/before-rate-limit', expensiveHandler1); // $ Alert
fastifyApp3.register(require('@fastify/rate-limit'));
fastifyApp3.get('/after-rate-limit', expensiveHandler1);