Repository navigation
fix(server): drive CORS allowed origins from CORS_ORIGINS config - #609
Open
SceptredHead wants to merge 1 commit into
Open
SceptredHead wants to merge 1 commit into
SceptredHead wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR makes the CORS allowed-origins list fully configurable via the
CORS_ORIGINSenvironment variable, so staging and production deployments can restrict which browser origins the server accepts.What was implemented
apps/server/src/config.ts— added acorsOriginsfield toServerConfigand aparseCorsOrigins()helper that:CORS_ORIGINSon commas and validates each entry as a validhttp:/https:URL.NODE_ENV=production), the variable is required and the wildcard"*"is rejected at startup, preventing accidental permissive config from reaching prod.["*"]when the variable is absent.apps/server/src/index.ts— registers@fastify/corswith an origin callback that checks each request origin against the allow-list. Requests with noOriginheader (server-to-server, CLI) are passed through unconditionally.apps/server/package.json— added@fastify/corsanddotenvtodependencies..env.example— documentedCORS_ORIGINSwith an example value.deploy/k8s/base/configmap.yaml— added an emptyCORS_ORIGINSplaceholder (empty string intentionally fails startup in production, forcing operators to set the secret).deploy/k8s/overlays/production/patches/cors-origins.yaml— new patch that injectsCORS_ORIGINSfrom theprism-secretsSecret into the server Deployment, keeping the value out of the ConfigMap.Closes #397