Skip to content

[BE-23] Add rate limiting, helmet, and strict env validation #1082

Description

@yusuftomilola

Overview

The API has no rate limiting, no security headers, and starts happily with missing secrets. @nestjs/throttler is installed but never registered. Before this repo invites public contributions against a deployed instance, the basics must be in place.

What to Build

  1. Rate limiting: ThrottlerModule.forRootAsync() from env (THROTTLE_TTL, THROTTLE_LIMIT), ThrottlerGuard global; stricter per-route limits on POST /api/auth/login and /api/auth/register (e.g. 5/min)
  2. Headers: add helmet middleware in main.ts
  3. Env validation: Joi or Zod schema on ConfigModule.forRoot() — required vars (JWT_SECRET, JWT_REFRESH_SECRET, DB vars) fail fast at boot with a descriptive error; no hardcoded secret fallbacks anywhere
  4. CORS: keep the existing FRONTEND_URL origin config, but reject wildcard in production mode

References

  • Current bootstrap: backend/src/main.ts, backend/src/app.module.ts
  • Blocked by [BE-01] (auth routes must exist to be rate-limited)

Acceptance Criteria

  • Exceeding limits returns 429 with a Retry-After header
  • Login/register have tighter limits than general routes
  • App refuses to start with a clear message when a required env var is missing
  • Helmet headers present on every response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions