From 012960665e7335ab8aa4e724af99c4698b79dcf6 Mon Sep 17 00:00:00 2001 From: Natheeshkumar Date: Thu, 29 Oct 2026 23:27:24 +0530 Subject: [PATCH 1/4] test(e2e): only refuse the public default password on hosted targets Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- test/e2e/steps/helpers/common.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/e2e/steps/helpers/common.ts b/test/e2e/steps/helpers/common.ts index 1e9b4a38..2fcb8cef 100644 --- a/test/e2e/steps/helpers/common.ts +++ b/test/e2e/steps/helpers/common.ts @@ -29,11 +29,13 @@ function isLocalTarget(url: string): boolean { * Exported for unit testing. */ export function assertDefaultCredentialsOnlyLocal( - email: string, + _email: string, password: string, targetUrls: Array ): void { - if (email.toLowerCase() !== PUBLIC_DEFAULT_E2E_EMAIL && password !== PUBLIC_DEFAULT_E2E_EMAIL) { + // Only the public default password is the risk; the shared account's email may be reused + // on hosted targets as long as it has a private password there. + if (password !== PUBLIC_DEFAULT_E2E_EMAIL) { return; } const remote = targetUrls.find((url) => url && !isLocalTarget(url)); From 56b638c61d5c41a122853b7d2664c84532b4c212 Mon Sep 17 00:00:00 2001 From: Natheeshkumar Date: Fri, 30 Oct 2026 00:06:14 +0530 Subject: [PATCH 2/4] fix(auth): relax sign-in rate limit on dev so post-deploy E2E can sign in NODE_ENV=production on deployed environments enabled better-auth's default 3-per-10s sign-in limit, which throttles the parallel dev E2E run. Only APP_ENV=dev is relaxed; staging and production keep the default. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- apps/backend/src/lib/__tests__/authAccess.test.ts | 9 ++++++++- apps/backend/src/lib/authAccess.ts | 10 ++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/apps/backend/src/lib/__tests__/authAccess.test.ts b/apps/backend/src/lib/__tests__/authAccess.test.ts index 85058a6b..493abac0 100644 --- a/apps/backend/src/lib/__tests__/authAccess.test.ts +++ b/apps/backend/src/lib/__tests__/authAccess.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect } from 'vitest'; -import { authAdminRoles, authRateLimitRules } from '../authAccess.js'; +import { authAdminRoles, authRateLimitRules, buildAuthRateLimitRules } from '../authAccess.js'; describe('auth access control (S01-02)', () => { it('does not give the admin role destructive user permissions', () => { @@ -25,4 +25,11 @@ describe('auth rate-limit rules (S01-04)', () => { expect(rule).toMatchObject({ window: expect.any(Number), max: expect.any(Number) }); } }); + + it('relaxes the sign-in limit only for the dev environment', () => { + expect(buildAuthRateLimitRules('dev')).toHaveProperty('/sign-in/email'); + expect(buildAuthRateLimitRules('staging')).not.toHaveProperty('/sign-in/email'); + expect(buildAuthRateLimitRules('production')).not.toHaveProperty('/sign-in/email'); + expect(buildAuthRateLimitRules(undefined)).not.toHaveProperty('/sign-in/email'); + }); }); diff --git a/apps/backend/src/lib/authAccess.ts b/apps/backend/src/lib/authAccess.ts index 0f764787..28955800 100644 --- a/apps/backend/src/lib/authAccess.ts +++ b/apps/backend/src/lib/authAccess.ts @@ -20,10 +20,16 @@ export const authAdminRoles = { // email-sending endpoints (3 per 60s) by default. These add limits for the // token/OTP verification endpoints it leaves on the generic bucket, so OTPs // cannot be guessed by cycling new codes. Per client IP; see proxyConfig. -export const authRateLimitRules = { +export const buildAuthRateLimitRules = (appEnv: string | undefined = process.env.APP_ENV) => ({ '/email-otp/verify-email': { window: 60, max: 10 }, '/email-otp/check-verification-otp': { window: 60, max: 10 }, '/email-otp/reset-password': { window: 60, max: 10 }, '/reset-password': { window: 60, max: 10 }, '/magic-link/verify': { window: 60, max: 10 }, -}; + // The dev post-deploy E2E run signs in from one runner IP across parallel + // workers, which the default 3-per-10s sign-in limit throttles. Staging and + // production keep the default. + ...(appEnv === 'dev' ? { '/sign-in/email': { window: 10, max: 200 } } : {}), +}); + +export const authRateLimitRules = buildAuthRateLimitRules(); From 6d2f10b0ada9ab270e96528430843b657743ecea Mon Sep 17 00:00:00 2001 From: Natheeshkumar Date: Fri, 30 Oct 2026 00:49:36 +0530 Subject: [PATCH 3/4] fix(backend): restore default DB pool size of 2 The security remediation raised the app-side pool default from 2 to 10, which exhausts the shared Postgres connection slots across replicas under load (dev E2E saw 'Too many database connections'). DB_POOL_MAX still overrides. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- apps/backend/src/lib/prisma.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/backend/src/lib/prisma.ts b/apps/backend/src/lib/prisma.ts index 887b4556..1ed0948c 100644 --- a/apps/backend/src/lib/prisma.ts +++ b/apps/backend/src/lib/prisma.ts @@ -20,7 +20,7 @@ function positiveIntFromEnv(name: string, fallback: number): number { * Build the pg driver adapter. * * In production (PgBouncer transaction mode) the app-side pool stays small - * (DB_POOL_MAX, default 10) — PgBouncer handles real server-side pooling. The adapter does not + * (DB_POOL_MAX, default 2) — PgBouncer handles real server-side pooling. The adapter does not * send named/prepared statements unless a statementNameGenerator is supplied * (we don't supply one), which is required for PgBouncer transaction mode * compatibility — this replaces the old `pgbouncer=true` query-string flag @@ -34,7 +34,7 @@ function buildAdapter(): PrismaPg { assertSecureDatabaseUrl(connectionString, appConfig.isProduction); - const max = isLocalDatabase(connectionString) ? undefined : positiveIntFromEnv('DB_POOL_MAX', 10); + const max = isLocalDatabase(connectionString) ? undefined : positiveIntFromEnv('DB_POOL_MAX', 2); // query_timeout is enforced client-side: a server-side statement_timeout startup // parameter is rejected by PgBouncer unless it is explicitly ignored. From 5aa0f10a1bf00bce64a36705d60ca8ca53438e5e Mon Sep 17 00:00:00 2001 From: Natheeshkumar Date: Fri, 30 Oct 2026 00:50:31 +0530 Subject: [PATCH 4/4] docs: update DB_POOL_MAX default in .env.example Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- apps/backend/.env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/backend/.env.example b/apps/backend/.env.example index 98869551..ac61495c 100644 --- a/apps/backend/.env.example +++ b/apps/backend/.env.example @@ -30,7 +30,7 @@ PORT=4000 # sslmode=disable/allow/prefer for a non-local host. # # Optional pool / timeout tuning (non-local hosts): -# DB_POOL_MAX=10 app-side pool size +# DB_POOL_MAX=2 app-side pool size (default 2) # DB_CONNECTION_TIMEOUT_MS=10000 wait for a pooled connection # DB_QUERY_TIMEOUT_MS=60000 client-side per-query timeout #