fix: implement dynamic CORS headers based on request origins (Fixes #1049)#1143
Closed
zeroknowledge0x wants to merge 1 commit into
Closed
fix: implement dynamic CORS headers based on request origins (Fixes #1049)#1143zeroknowledge0x wants to merge 1 commit into
zeroknowledge0x wants to merge 1 commit into
Conversation
- Replace hardcoded Access-Control-Allow-Origin: * with origin validation - Add ALLOWED_ORIGINS environment variable for configurable allowlist - Validate request Origin header against allowed origins - Only set CORS headers for requests from allowed origins - Add Vary: Origin header for proper cache key differentiation - Update errorResponse to pass CORS headers through Fixes sublime247#1049
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.
Summary
Replaces hardcoded
Access-Control-Allow-Origin: *with dynamic origin validation in the well-known cache worker, ensuring CORS headers are only sent for explicitly allowed origins.Changes
workers/well-known-cache/src/index.tsALLOWED_ORIGINSto theEnvinterfaceparseAllowedOrigins()function to parse comma-separated env vargetCorsHeaders()function that validates request origin against allowlistAccess-Control-Allow-Originfor requests from allowed originsVary: Originheader for proper cache key differentiationerrorResponse()to accept and pass through CORS headersCORS_HEADERSconstant usage with dynamiccorsHeaderswrangler.tomlALLOWED_ORIGINSenvironment variable with placeholder domainSecurity Improvements
*).well-knownresourcesVary: Originensures proper cache segregation per originConfiguration
Set
ALLOWED_ORIGINSin wrangler.toml or Cloudflare dashboard:Related Issues
Fixes #1049