Skip to content

Harden CORS configuration for production — restrict origins, methods, and headers explicitly #255

Description

@robertocarlous

Summary

The current CORS configuration in src/middleware/corsandbody.ts likely permits broad origins or uses a permissive default. In production, CORS must be restricted to known client origins to prevent cross-site request forgery from arbitrary domains.

Proposed Solution

  • Replace any wildcard or permissive CORS config with an explicit allowlist driven by env vars:
CORS_ALLOWED_ORIGINS=https://app.neurowealth.io,https://admin.neurowealth.io
  • Allow only: GET, POST, PUT, DELETE, OPTIONS
  • Allow only required headers: Content-Type, Authorization, Idempotency-Key, X-Correlation-ID
  • Set credentials: true only for authenticated routes
  • Return 403 (not just a missing header) for disallowed origins
  • Validate CORS_ALLOWED_ORIGINS at startup — refuse to start if empty in production

Acceptance Criteria

  • Requests from unlisted origins receive 403
  • Preflight OPTIONS requests respond correctly for allowed origins
  • CORS_ALLOWED_ORIGINS validated at startup; missing in NODE_ENV=production is a fatal error
  • Integration tests cover allowed origin, disallowed origin, and preflight
  • CORS_ALLOWED_ORIGINS documented in .env.example

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programenhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions