Skip to content

Scheduling infrastructure for absolutely everyone.

chore: add global rate limiting to prevent abuse apiv2 (#15971)

Morganbaaa1fa71eff
diff --git a/apps/api/v2/src/app.module.ts b/apps/api/v2/src/app.module.ts
index 5fad042f861..dd4093e501e 100644
--- a/apps/api/v2/src/app.module.ts
+++ b/apps/api/v2/src/app.module.ts
@@ -14,8 +14,8 @@ import { RedisService } from "@/modules/redis/redis.service";
import { BullModule } from "@nestjs/bull";
import { MiddlewareConsumer, Module, NestModule, RequestMethod } from "@nestjs/common";
import { ConfigModule } from "@nestjs/config";
-import { APP_INTERCEPTOR, RouterModule } from "@nestjs/core";
-import { seconds, ThrottlerModule } from "@nestjs/throttler";
+import { APP_GUARD, APP_INTERCEPTOR } from "@nestjs/core";
+import { seconds, ThrottlerGuard, ThrottlerModule } from "@nestjs/throttler";
import { ThrottlerStorageRedisService } from "nestjs-throttler-storage-redis";
import { AppController } from "./app.controller";
@@ -45,14 +45,9 @@ import { AppController } from "./app.controller";
useFactory: (redisService: RedisService) => ({
throttlers: [
{
- name: "short",
- ttl: seconds(10),
- limit: 3,
- },
- {
- name: "medium",
- ttl: seconds(30),
- limit: 10,
+ name: "long",
+ ttl: seconds(60), // Time to live for the long period in seconds
+ limit: 120, // Maximum number of requests within the long ttl
},
],
storage: new ThrottlerStorageRedisService(redisService.redis),
@@ -69,6 +64,10 @@ import { AppController } from "./app.controller";
provide: APP_INTERCEPTOR,
useClass: ResponseInterceptor,
},
+ {
+ provide: APP_GUARD,
+ useClass: ThrottlerGuard,
+ },
],
})
export class AppModule implements NestModule {