Skip to content

[BE-129] Harden CORS configuration #988

Description

@mftee

Overview

main.ts configures CORS as:

origin: configService.get<string>('FRONTEND_URL') || 'http://localhost:3001',
credentials: true,

With credentials: true, the allowed origin must be exact and trustworthy. The fallback to a localhost origin means a misconfigured deployment where FRONTEND_URL is unset silently permits credentialed requests from a development origin instead of failing loudly.

Tasks

  • Require FRONTEND_URL explicitly in production — fail startup rather than falling back to localhost ([BE-113] provides the validation mechanism).
  • Support multiple allowed origins via a comma-separated list, validated against an allowlist rather than reflected.
  • Never reflect an arbitrary Origin header back while credentials: true is set.
  • Restrict allowed methods and headers to what the frontend actually uses.
  • Add tests asserting a disallowed origin is rejected.

Acceptance Criteria

  • Production refuses to start without an explicit frontend origin.
  • A disallowed origin receives no CORS approval (covered by a test).
  • The localhost fallback applies only in development.

Dependencies

Pairs with [BE-113].

Notes for Contributors

Comment below to be assigned.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions