Skip to content

fix(server): drive CORS allowed origins from CORS_ORIGINS config - #609

Open
SceptredHead wants to merge 1 commit into
DevNiola:mainfrom
SceptredHead:fix/397-configurable-cors-origins
Open

SceptredHead wants to merge 1 commit into
DevNiola:mainfrom
SceptredHead:fix/397-configurable-cors-origins

Conversation

@SceptredHead

Copy link
Copy Markdown

Description

This PR makes the CORS allowed-origins list fully configurable via the CORS_ORIGINS environment variable, so staging and production deployments can restrict which browser origins the server accepts.

What was implemented

  • apps/server/src/config.ts — added a corsOrigins field to ServerConfig and a parseCorsOrigins() helper that:

    • Splits CORS_ORIGINS on commas and validates each entry as a valid http:/https: URL.
    • In production (NODE_ENV=production), the variable is required and the wildcard "*" is rejected at startup, preventing accidental permissive config from reaching prod.
    • In development, defaults to ["*"] when the variable is absent.
  • apps/server/src/index.ts — registers @fastify/cors with an origin callback that checks each request origin against the allow-list. Requests with no Origin header (server-to-server, CLI) are passed through unconditionally.

  • apps/server/package.json — added @fastify/cors and dotenv to dependencies.

  • .env.example — documented CORS_ORIGINS with an example value.

  • deploy/k8s/base/configmap.yaml — added an empty CORS_ORIGINS placeholder (empty string intentionally fails startup in production, forcing operators to set the secret).

  • deploy/k8s/overlays/production/patches/cors-origins.yaml — new patch that injects CORS_ORIGINS from the prism-secrets Secret into the server Deployment, keeping the value out of the ConfigMap.

Closes #397

Read CORS_ORIGINS from the environment as a comma-separated list of URLs.
Validate each entry as a valid http/https URL. In production, the variable
is required and wildcard "*" is rejected so only explicitly listed origins
are reflected back to browsers.

Register @fastify/cors with an origin callback that checks each request
origin against the allow-list. Requests without an Origin header (curl,
server-to-server) are allowed through unconditionally.

Add CORS_ORIGINS to .env.example with documentation and to the k8s
ConfigMap (empty placeholder). A production overlay patch reads the value
from the prism-secrets Secret so staging/production can configure it
independently without touching the base manifests.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Backend] Make CORS allowed origins configurable

1 participant