-
-
Notifications
You must be signed in to change notification settings - Fork 413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[💡 FEATURE REQUEST]: HTTP Middleware - Dynamic CORS origin support #1709
Comments
Hey @orlandothoeny 👋🏻 |
Hi @rustatian, Thanks for the quick reply :) I just saw that the middleware uses https://github.com/rs/cors, I'll have to try that out. In the test-cases I only found one with a simple subdomain, no nested ones: https://github.com/rs/cors/blob/20a76bd635d3c8a7ea58f49fad54b8eecb95aa46/cors_test.go#L116 Maybe it just works. Then nothing would have to change to be able to accomplish this. Except maybe to add this to the docs to prevent future issues. |
I don't know Go, but just by looking at the code I think that should work. I don't see any special subdomain logic. I think it's just a simple wildcard with a prefix + suffix check. So something like
|
Just realized that that wouldn't allow |
Oh yeah, you're right. Looks like regex pattern matching would be best here. Since I'm able to provide my implementation for the allow logic, it would be possible to use regexp here. |
Plugin
HTTP Middleware (any)
I have an idea!
Affected middleware: HTTP
The only thing that prevents us from completely getting rid of our NGINX is CORS support for wildcard subdomains.
The HTTP middleware currently only supports returning static values for the CORS headers.
Use case
We have a PHP API, this API is used by multiple sites that run on the same main domain.
Example
The API is running under
api.example.com
. We haveexample.com
,cockpit.example.com
,admin.example.com
and various other sites that all callapi.example.com
via JavaScript in the browser. Thus, all these hostnames must be allowed as CORS origin.This also applies to our staging & development environment, which run on the same main domain but under a separate subdomain. E.g.
api.dev.example.com
,dev.example.com
,cockpit.dev.example.com
&admin.dev.example.com
.Due to the large volume of hosts and differences between the environments, we decided to use a Regex pattern that allows the main domain, as well as all subdomains below it. This saves us the complexity of having to maintain a separate list of allowed hosts for every environment.
To accomplish this, we use the following NGINX config:
Feature request
HTTP Middleware support that allows us to return the requesting host as
allowed_origin
value if it is one of these:example.com
example.com
example.com
.Possible implementation ideas
allowed_origin_wildcard: '*.example.com'
allowed_origin_root: 'example.com'
Config ideas
Either create a new separate key for the matching-config. Or a new matching-type config.
For example:
allowed_origin || allowed_origin_wildcard
allowed_origin && allowed_origin_type=['simple' || 'regex']
The text was updated successfully, but these errors were encountered: