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

default config of origin: * and credentials: true seems invalid? #96

Open
robacarp opened this issue Mar 10, 2023 · 0 comments
Open

default config of origin: * and credentials: true seems invalid? #96

robacarp opened this issue Mar 10, 2023 · 0 comments

Comments

@robacarp
Copy link

Hey there, I'm not sure of the status of your plug here, hopefully you're still around. Thanks for your time on this library.

I ran into a small issue with the default config. If you don't consider this a bug, perhaps this paper trail will be helpful for some other future traveler.

When creating a request in browser-land javascript, like this:

fetch(url, {
   credentials: true,
   mode: "cors"
})

By default CORSPlug gives an invalid response:

access-control-allow-origin: *
access-control-allow-credentials: true
[...]

Firefox fails with an ambiguous "null" and Chrome shows the message:

Access to fetch at '[url]' from origin '[other url]' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.

The MDN Article on Access-Control-Allow-Origin explains further:

For requests without credentials, the literal value "*" can be specified as a wildcard; the value tells browsers to allow requesting code from any origin to access the resource. Attempting to use the wildcard with credentials results in an error.

A behavior I have seen elsewhere is that when the origin is specified as '*', credentials is disabled. In that case, it's silently disabled, which bit me in a different way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant