diff --git a/src/app.module.ts b/src/app.module.ts index a40fbac..98b127a 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -83,14 +83,9 @@ const ENV = process.env.NODE_ENV; // Schedule ScheduleModule.forRoot(), - // Throttler - // ThrottlerModule.forRoot([ - // { name: 'default', limit: 100, ttl: 60_000 }, - // { name: 'login', limit: 5, ttl: 60_000 }, - // { name: 'otp', limit: 3, ttl: 300_000 }, - // { name: 'admin', limit: 30, ttl: 60_000 }, - // ]), - ThrottlerModule.forRoot([]), + // Generous per-IP, per-endpoint limits for the MVP. Sensitive routes + // override this same bucket so their limits do not affect other routes. + ThrottlerModule.forRoot([{ name: 'default', limit: 300, ttl: 60_000 }]), // Logging LoggingModule, diff --git a/src/modules/admin/auth/admin-auth.controller.ts b/src/modules/admin/auth/admin-auth.controller.ts index 870db40..c87b862 100644 --- a/src/modules/admin/auth/admin-auth.controller.ts +++ b/src/modules/admin/auth/admin-auth.controller.ts @@ -5,7 +5,7 @@ import { Public } from '@/modules/auth/decorators/public.decorator'; import { Throttle } from '@nestjs/throttler'; @Controller('admin/auth') -@Throttle({ login: {} }) +@Throttle({ default: { limit: 30, ttl: 60_000 } }) export class AdminAuthController { constructor( /** diff --git a/src/modules/admin/choices/admin-choices.controller.ts b/src/modules/admin/choices/admin-choices.controller.ts index 18cf2a7..5653f7f 100644 --- a/src/modules/admin/choices/admin-choices.controller.ts +++ b/src/modules/admin/choices/admin-choices.controller.ts @@ -21,7 +21,7 @@ import { Throttle } from '@nestjs/throttler'; @Controller('admin/choices') @Roles(Role.SUPERUSER, Role.ADMIN) -@Throttle({ admin: {} }) +@Throttle({ default: { limit: 120, ttl: 60_000 } }) export class AdminChoicesController { constructor( /** diff --git a/src/modules/admin/question-transitions/admin-question-transitions.controller.ts b/src/modules/admin/question-transitions/admin-question-transitions.controller.ts index 19c1fc0..2dbf88b 100644 --- a/src/modules/admin/question-transitions/admin-question-transitions.controller.ts +++ b/src/modules/admin/question-transitions/admin-question-transitions.controller.ts @@ -19,7 +19,7 @@ import { Throttle } from '@nestjs/throttler'; @Controller('admin/question-transitions') @Roles(Role.SUPERUSER, Role.ADMIN) -@Throttle({ admin: {} }) +@Throttle({ default: { limit: 120, ttl: 60_000 } }) export class AdminQuestionTransitionsController { constructor( /** diff --git a/src/modules/admin/questions/admin-questions.controller.ts b/src/modules/admin/questions/admin-questions.controller.ts index 576e0ff..3d03aa0 100644 --- a/src/modules/admin/questions/admin-questions.controller.ts +++ b/src/modules/admin/questions/admin-questions.controller.ts @@ -25,7 +25,7 @@ import { Throttle } from '@nestjs/throttler'; @Controller('admin/questions') @Roles(Role.SUPERUSER, Role.ADMIN) -@Throttle({ admin: {} }) +@Throttle({ default: { limit: 120, ttl: 60_000 } }) export class AdminQuestionsController { constructor( /** diff --git a/src/modules/admin/scoring/admin-scoring.controller.ts b/src/modules/admin/scoring/admin-scoring.controller.ts index 1b7922d..38d59ff 100644 --- a/src/modules/admin/scoring/admin-scoring.controller.ts +++ b/src/modules/admin/scoring/admin-scoring.controller.ts @@ -19,7 +19,7 @@ import { Throttle } from '@nestjs/throttler'; @Controller('admin/scoring') @Roles(Role.SUPERUSER, Role.ADMIN) -@Throttle({ admin: {} }) +@Throttle({ default: { limit: 120, ttl: 60_000 } }) export class AdminScoringController { constructor( /** diff --git a/src/modules/admin/tests/admin-tests.controller.ts b/src/modules/admin/tests/admin-tests.controller.ts index 8f0e001..45227eb 100644 --- a/src/modules/admin/tests/admin-tests.controller.ts +++ b/src/modules/admin/tests/admin-tests.controller.ts @@ -21,7 +21,7 @@ import { Throttle } from '@nestjs/throttler'; @Controller('admin/tests') @Roles(Role.SUPERUSER, Role.ADMIN) -@Throttle({ admin: {} }) +@Throttle({ default: { limit: 120, ttl: 60_000 } }) export class AdminTestsController { constructor( /** diff --git a/src/modules/auth/auth.controller.ts b/src/modules/auth/auth.controller.ts index 754b6c6..3fcf7f9 100644 --- a/src/modules/auth/auth.controller.ts +++ b/src/modules/auth/auth.controller.ts @@ -26,7 +26,7 @@ export class AuthController { @Public() @Post('login') @HttpCode(HttpStatus.OK) - @Throttle({ login: {} }) + @Throttle({ default: { limit: 30, ttl: 60_000 } }) @ApiAppResponse([ { status: HttpStatus.OK, @@ -86,7 +86,7 @@ export class AuthController { @Public() @Post('verify-otp') @HttpCode(HttpStatus.OK) - @Throttle({ otp: {} }) + @Throttle({ default: { limit: 30, ttl: 60_000 } }) @ApiAppResponse([ { status: HttpStatus.OK, @@ -112,7 +112,7 @@ export class AuthController { @Public() @Post('refresh') @HttpCode(HttpStatus.OK) - @Throttle({ login: {} }) + @Throttle({ default: { limit: 60, ttl: 60_000 } }) @ApiAppResponse([ { status: HttpStatus.OK, diff --git a/src/modules/chatbot/chatbot.controller.ts b/src/modules/chatbot/chatbot.controller.ts index 8780c23..3cc0929 100644 --- a/src/modules/chatbot/chatbot.controller.ts +++ b/src/modules/chatbot/chatbot.controller.ts @@ -12,8 +12,10 @@ import { ChatDTO } from './dtos/chat.dto'; import { ActiveUser } from '@/common/decorators/active-user.decorator'; import { User } from '../users/entities/user.entity'; import { ApiAppResponse } from '@/common/decorators/api-app-response.decorator'; +import { Throttle } from '@nestjs/throttler'; @Controller('chatbot') +@Throttle({ default: { limit: 30, ttl: 60_000 } }) export class ChatbotController { constructor( /** diff --git a/src/modules/submissions/submissions.controller.ts b/src/modules/submissions/submissions.controller.ts index 172390c..9b26592 100644 --- a/src/modules/submissions/submissions.controller.ts +++ b/src/modules/submissions/submissions.controller.ts @@ -24,9 +24,9 @@ import { StartGuestDTO } from './dtos/responses/start-guest.dto'; import { GetAnswerSubmissionDTO } from './dtos/responses/get-answer-submission.dto'; import { GetSubmissionHistoryDTO } from './dtos/responses/get-submission-history.dto'; import { GetSubmissionDetailDTO } from './dtos/responses/get-submission-detail.dto'; -import type { Response } from 'express'; import { Observable } from 'rxjs'; import { I18nService } from 'nestjs-i18n'; +import { Throttle } from '@nestjs/throttler'; @Controller('submissions') export class SubmissionsController { @@ -173,6 +173,7 @@ export class SubmissionsController { } @Sse(':id/analyze') + @Throttle({ default: { limit: 30, ttl: 60_000 } }) @ApiProduces('text/event-stream') @ApiResponse({ status: HttpStatus.OK,