From 603e74af0962553f4a5b43b16094648105219005 Mon Sep 17 00:00:00 2001 From: ZaydSkaff Date: Thu, 19 Jun 2025 12:54:59 +0300 Subject: [PATCH 1/3] Test/prevent server block on rate limit (#417) * task: add trust proxy header * add logging * task: test rate limits on sever * task: increase rate limit timeout * fix: merge conflicts --- src/main.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 543767f..33ce70a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -10,7 +10,6 @@ import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston'; import { setupSwaggerAuthentication } from '../libs/common/src/util/user-auth.swagger.utils'; import { AppModule } from './app.module'; import { HttpExceptionFilter } from './common/filters/http-exception/http-exception.filter'; -import { NestExpressApplication } from '@nestjs/platform-express'; async function bootstrap() { const app = await NestFactory.create(AppModule); From c5dd5e28fd88f3026f3c59b01d8c186f118043d9 Mon Sep 17 00:00:00 2001 From: ZaydSkaff Date: Thu, 19 Jun 2025 13:54:22 +0300 Subject: [PATCH 2/3] Test/prevent server block on rate limit (#418) --- src/main.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main.ts b/src/main.ts index 33ce70a..e00dca6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,7 +2,6 @@ import { RequestContextMiddleware } from '@app/common/middleware/request-context import { SeederService } from '@app/common/seed/services/seeder.service'; import { Logger, ValidationPipe } from '@nestjs/common'; import { NestFactory } from '@nestjs/core'; -import { NestExpressApplication } from '@nestjs/platform-express'; import { json, urlencoded } from 'body-parser'; import rateLimit from 'express-rate-limit'; import helmet from 'helmet'; @@ -12,7 +11,7 @@ import { AppModule } from './app.module'; import { HttpExceptionFilter } from './common/filters/http-exception/http-exception.filter'; async function bootstrap() { - const app = await NestFactory.create(AppModule); + const app = await NestFactory.create(AppModule); app.enableCors(); @@ -22,14 +21,11 @@ async function bootstrap() { app.useGlobalFilters(new HttpExceptionFilter()); app.use(new RequestContextMiddleware().use); - app.set('trust proxy', true); app.use( rateLimit({ - windowMs: 2 * 60 * 1000, - max: 50, - standardHeaders: true, - legacyHeaders: false, + windowMs: 5 * 60 * 1000, + max: 500, }), ); From aa9e90bf084afabb2788408e2d3716a052df606f Mon Sep 17 00:00:00 2001 From: ZaydSkaff Date: Thu, 19 Jun 2025 14:34:23 +0300 Subject: [PATCH 3/3] Test/prevent server block on rate limit (#419) * increase DB max connection to 50 --- libs/common/src/database/database.module.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/common/src/database/database.module.ts b/libs/common/src/database/database.module.ts index 373041c..f3ec232 100644 --- a/libs/common/src/database/database.module.ts +++ b/libs/common/src/database/database.module.ts @@ -125,7 +125,7 @@ import { VisitorPasswordEntity } from '../modules/visitor-password/entities'; logger: typeOrmLogger, extra: { charset: 'utf8mb4', - max: 20, // set pool max size + max: 50, // set pool max size idleTimeoutMillis: 5000, // close idle clients after 5 second connectionTimeoutMillis: 12_000, // return an error after 11 second if connection could not be established maxUses: 7500, // close (and replace) a connection after it has been used 7500 times (see below for discussion)