CORS: Support multiple allowed origins (dynamic Access-Control-Allow-Origin) #3222
akshat-kumar-singhal
started this conversation in
Ideas
Replies: 1 comment
-
|
Yes it should be supported |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
The current CORS middleware (
pkg/gofr/http/middleware/cors.go) setsAccess-Control-Allow-Originas a static value frommiddlewareConfigs. The HTTP spec only allows a single origin or*in this header.When an application serves multiple frontends (e.g.,
https://app.example.comandhttps://admin.example.com), there is no way to configure GoFr to respond with the correct origin dynamically. The only options are:*(insecure, does not work withcredentials: include)Current behavior
Proposed solution
Support a comma-separated list of allowed origins in
ACCESS_CONTROL_ALLOW_ORIGIN. The middleware would:Originheader against the allowed set*)Vary: Originheader for correct cachingConfiguration
This is backward-compatible — a single origin or
*works exactly as before. Only when commas are present does the dynamic matching activate.Use case
Multi-tenant SaaS with separate customer and admin frontends deployed to different domains, both calling the same API. Currently requires workarounds like custom middleware or using
*.Beta Was this translation helpful? Give feedback.
All reactions