Skip to content
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

Can't get CORS to work when "withCredentials" is true for any origin #9

Closed
kshetline opened this issue Nov 1, 2019 · 4 comments
Closed
Labels

Comments

@kshetline
Copy link

I'm trying to get CORS to work when withCredentials is true in my XMLHttpRequest, but for any origin. If I use "allow_origins": [] or "allow_origins": ["*"] in my "github_com/devopsfaith/krakend-cors" config, CORS will only work if withCredentials is false.

I can get CORS to work when withCredentials is true only if I specifically whitelist all allowed origins.

The problem is that with "allow_origins": [] or "allow_origins": ["*"], Access-Control-Allow-Origin comes back as "*". I need to have to origin of the request echoed back in the Access-Control-Allow-Origin header instead.

Is there a way to specify that behavior?

        "github_com/devopsfaith/krakend-cors": {
            "allow_origins": ["http://localhost:8080"], // Or [] or ["*"] - which only changes the limitation or error I get
            "allow_headers": ["Origin", "Authorization", "Content-Type", "Accep\
t", "X-Auth-Token"],
            "expose_headers": ["Content-Type", "Content-Length"],
            "allow_credentials": true
        }

@taik0
Copy link
Member

taik0 commented Nov 1, 2019

Hi @kshetline and welcome to the KrakenD community!

This module wraps https://github.com/rs/cors, the behaviour you are describing is disabled for security reasons (by the library, not us).

Current CORS standards(both W3C CORS and WHATWG fetch standard) have a clear definition for the wildcard *, which means any domain is allowed. But they also have another important security requirement: Origin: * and Credentials: true cannot be used at the same time, to avoid overly loose permissions. Currently all browsers follow this requirement to disallow this configuration combination.

Please check this issue for more information: rs/cors#55

@kshetline
Copy link
Author

I can get this to work just fine with a simple sample node/express server (which is not the server we're using through kraken), without running into any security issues from either Chrome or Firefox.

I'm confused about whether or not the issue you linked to above matches my situation or not. I don't have the browser sending Origin: *. The browser is sending it's actual origin (let's say that's https:/foo.com). The problem is that the response from the service deployed via kraken is Access-Control-Allow-Origin: *, instead of Access-Control-Allow-Origin: https://foo.com.

This problem goes away if withCredentials is false. Are you saying that regardless of circumstances, rs/cors won't echo back the same origin it is sent, even when that origin is explicit, not "*"?

@kshetline
Copy link
Author

I've found a solution to get the behavior I want. I don't know if this would be considered a "cheat" or not, but "allow_origins": ["http*"] solves my problem.

It was very useful to know that the source code that mattered was " https://github.com/rs/cors", because that made it easy to figure this out. Thanks!

@taik0 taik0 closed this as completed Mar 6, 2021
@github-actions
Copy link

github-actions bot commented Jun 2, 2022

This issue was marked as resolved a long time ago and now has been automatically locked as there has not been any recent activity after it. You can still open a new issue and reference this link.

@github-actions github-actions bot added the locked label Jun 2, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants