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

Access-Control-Allow-Origin issue #283

Open
alan-bradbury-hollaroo opened this issue Oct 7, 2022 · 2 comments
Open

Access-Control-Allow-Origin issue #283

alan-bradbury-hollaroo opened this issue Oct 7, 2022 · 2 comments

Comments

@alan-bradbury-hollaroo
Copy link

I have the following express app setup:

const app = express();
app.use(cors({ credentials: true, origin: 'https://localhost:8080' }));

And make a request from https://localhost:8080 with Access-Control-Allow-Credentials set to true and get the following error.

Access to fetch at 'https://localhost:3000/xxxx' from origin 'https://localhost:8080' 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'.

Upon looking at the pre-flight request the Access-Control-Allow-Origin has indeed been returned as * rather than https://localhost:8080

I can see my cors settings are being picked up as I've tried changing the methods option and can see that being reflected.

@dougwilson dougwilson transferred this issue from expressjs/express Oct 7, 2022
@dougwilson
Copy link
Contributor

Hello, and sorry you are having trouble. I'm not sure how that could be happening, as you can view our source code and see that the only place this module returns that header as '*' is when the origin options is blank or set to '*' (https://github.com/expressjs/cors/blob/master/lib/index.js#L44). In order to assist further, we'll need your complete app such that we can run it and reproduce the issue, as there must be something else causing that header to be returned as '*' that is not clear from what has been provided in the report. Alternatively you are always welcome to open a PR that makes the changes necessary to resolve your issue.

@Kylir
Copy link

Kylir commented Jan 10, 2023

Hello!
I had the exact same issue: An ExpressJS API, cors configured and the OPTIONS request was successful, but the POST just after was failing.
It took me a while to realise that I had another call to cors deeper in my code for that POST that was overwriting the headers.
It's worth searching for cors in your project if you have this issue.

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

No branches or pull requests

3 participants