feat: add throttler

This commit is contained in:
2026-11-06 18:32:48 +03:30
parent 71ce020803
commit 2051090d3d
10 changed files with 16 additions and 18 deletions
+3 -8
View File
@@ -83,14 +83,9 @@ const ENV = process.env.NODE_ENV;
// Schedule // Schedule
ScheduleModule.forRoot(), ScheduleModule.forRoot(),
// Throttler // Generous per-IP, per-endpoint limits for the MVP. Sensitive routes
// ThrottlerModule.forRoot([ // override this same bucket so their limits do not affect other routes.
// { name: 'default', limit: 100, ttl: 60_000 }, ThrottlerModule.forRoot([{ name: 'default', limit: 300, 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([]),
// Logging // Logging
LoggingModule, LoggingModule,
@@ -5,7 +5,7 @@ import { Public } from '@/modules/auth/decorators/public.decorator';
import { Throttle } from '@nestjs/throttler'; import { Throttle } from '@nestjs/throttler';
@Controller('admin/auth') @Controller('admin/auth')
@Throttle({ login: {} }) @Throttle({ default: { limit: 30, ttl: 60_000 } })
export class AdminAuthController { export class AdminAuthController {
constructor( constructor(
/** /**
@@ -21,7 +21,7 @@ import { Throttle } from '@nestjs/throttler';
@Controller('admin/choices') @Controller('admin/choices')
@Roles(Role.SUPERUSER, Role.ADMIN) @Roles(Role.SUPERUSER, Role.ADMIN)
@Throttle({ admin: {} }) @Throttle({ default: { limit: 120, ttl: 60_000 } })
export class AdminChoicesController { export class AdminChoicesController {
constructor( constructor(
/** /**
@@ -19,7 +19,7 @@ import { Throttle } from '@nestjs/throttler';
@Controller('admin/question-transitions') @Controller('admin/question-transitions')
@Roles(Role.SUPERUSER, Role.ADMIN) @Roles(Role.SUPERUSER, Role.ADMIN)
@Throttle({ admin: {} }) @Throttle({ default: { limit: 120, ttl: 60_000 } })
export class AdminQuestionTransitionsController { export class AdminQuestionTransitionsController {
constructor( constructor(
/** /**
@@ -25,7 +25,7 @@ import { Throttle } from '@nestjs/throttler';
@Controller('admin/questions') @Controller('admin/questions')
@Roles(Role.SUPERUSER, Role.ADMIN) @Roles(Role.SUPERUSER, Role.ADMIN)
@Throttle({ admin: {} }) @Throttle({ default: { limit: 120, ttl: 60_000 } })
export class AdminQuestionsController { export class AdminQuestionsController {
constructor( constructor(
/** /**
@@ -19,7 +19,7 @@ import { Throttle } from '@nestjs/throttler';
@Controller('admin/scoring') @Controller('admin/scoring')
@Roles(Role.SUPERUSER, Role.ADMIN) @Roles(Role.SUPERUSER, Role.ADMIN)
@Throttle({ admin: {} }) @Throttle({ default: { limit: 120, ttl: 60_000 } })
export class AdminScoringController { export class AdminScoringController {
constructor( constructor(
/** /**
@@ -21,7 +21,7 @@ import { Throttle } from '@nestjs/throttler';
@Controller('admin/tests') @Controller('admin/tests')
@Roles(Role.SUPERUSER, Role.ADMIN) @Roles(Role.SUPERUSER, Role.ADMIN)
@Throttle({ admin: {} }) @Throttle({ default: { limit: 120, ttl: 60_000 } })
export class AdminTestsController { export class AdminTestsController {
constructor( constructor(
/** /**
+3 -3
View File
@@ -26,7 +26,7 @@ export class AuthController {
@Public() @Public()
@Post('login') @Post('login')
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
@Throttle({ login: {} }) @Throttle({ default: { limit: 30, ttl: 60_000 } })
@ApiAppResponse([ @ApiAppResponse([
{ {
status: HttpStatus.OK, status: HttpStatus.OK,
@@ -86,7 +86,7 @@ export class AuthController {
@Public() @Public()
@Post('verify-otp') @Post('verify-otp')
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
@Throttle({ otp: {} }) @Throttle({ default: { limit: 30, ttl: 60_000 } })
@ApiAppResponse([ @ApiAppResponse([
{ {
status: HttpStatus.OK, status: HttpStatus.OK,
@@ -112,7 +112,7 @@ export class AuthController {
@Public() @Public()
@Post('refresh') @Post('refresh')
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
@Throttle({ login: {} }) @Throttle({ default: { limit: 60, ttl: 60_000 } })
@ApiAppResponse([ @ApiAppResponse([
{ {
status: HttpStatus.OK, status: HttpStatus.OK,
@@ -12,8 +12,10 @@ import { ChatDTO } from './dtos/chat.dto';
import { ActiveUser } from '@/common/decorators/active-user.decorator'; import { ActiveUser } from '@/common/decorators/active-user.decorator';
import { User } from '../users/entities/user.entity'; import { User } from '../users/entities/user.entity';
import { ApiAppResponse } from '@/common/decorators/api-app-response.decorator'; import { ApiAppResponse } from '@/common/decorators/api-app-response.decorator';
import { Throttle } from '@nestjs/throttler';
@Controller('chatbot') @Controller('chatbot')
@Throttle({ default: { limit: 30, ttl: 60_000 } })
export class ChatbotController { export class ChatbotController {
constructor( constructor(
/** /**
@@ -24,9 +24,9 @@ import { StartGuestDTO } from './dtos/responses/start-guest.dto';
import { GetAnswerSubmissionDTO } from './dtos/responses/get-answer-submission.dto'; import { GetAnswerSubmissionDTO } from './dtos/responses/get-answer-submission.dto';
import { GetSubmissionHistoryDTO } from './dtos/responses/get-submission-history.dto'; import { GetSubmissionHistoryDTO } from './dtos/responses/get-submission-history.dto';
import { GetSubmissionDetailDTO } from './dtos/responses/get-submission-detail.dto'; import { GetSubmissionDetailDTO } from './dtos/responses/get-submission-detail.dto';
import type { Response } from 'express';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { I18nService } from 'nestjs-i18n'; import { I18nService } from 'nestjs-i18n';
import { Throttle } from '@nestjs/throttler';
@Controller('submissions') @Controller('submissions')
export class SubmissionsController { export class SubmissionsController {
@@ -173,6 +173,7 @@ export class SubmissionsController {
} }
@Sse(':id/analyze') @Sse(':id/analyze')
@Throttle({ default: { limit: 30, ttl: 60_000 } })
@ApiProduces('text/event-stream') @ApiProduces('text/event-stream')
@ApiResponse({ @ApiResponse({
status: HttpStatus.OK, status: HttpStatus.OK,