Skip to content

Harden CORS configuration and add integration tests #492

@temma02

Description

@temma02

Description

getAllowedOrigins in cors.ts reads from an env var but falls back to a wildcard in development. This wildcard can leak into staging if the env var is not set. The allowed-origins list should be explicit and validated at startup.

Requirements and context

  • Must be secure, tested, and documented where applicable
  • Should stay reviewable and fit the current monorepo structure
  • Relevant files: apps/backend/src/lib/api/cors.ts, apps/backend/src/lib/api/cors.test.ts, apps/frontend/src/lib/api/cors.ts

Suggested execution

  • Create branch: issue-018-harden-cors-configuration
  • Keep changes scoped to the issue and reference the task IDs in the PR

Implement changes

  • Throw at startup if ALLOWED_ORIGINS is unset in non-development environments
  • Validate each origin is a well-formed URL (no trailing slashes, no wildcards in production)
  • Add Vary: Origin header to all CORS responses

Test and commit

  • Extend cors.test.ts with: missing env var in production, malformed origin, preflight for disallowed origin
  • Run vitest run apps/backend/src/lib/api/cors.test.ts
  • Edge case: localhost origins must only be allowed in development

Example commit message

fix(cors): enforce explicit allowed-origins in non-development environments

Guidelines

  • Prefer small, reviewable PRs
  • Keep naming and data contracts consistent with the spec docs

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions