Skip to content
This repository has been archived by the owner on Jul 16, 2019. It is now read-only.

Duplicate headers in response #8

Open
aeirola opened this issue May 2, 2016 · 2 comments
Open

Duplicate headers in response #8

aeirola opened this issue May 2, 2016 · 2 comments

Comments

@aeirola
Copy link

aeirola commented May 2, 2016

I've noticed that it is possible for the filter to return responses with multipleAccess-Control-Allow-Origin headers, if the original response already happens to contain some CORS headers. Browsers don't like these kind of responses, with Chrome complaining as following:

The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed. Origin 'http://localhost:8000' is therefore not allowed access. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

While I understand that there should only be on source of CORS headers for a single response, it is quite easy to bump in to the issue if enriching resources from other CORS-enabled services. Then the CORS headers from both services will be appended to the response.

I guess the simple solution would be to check if the response already contains CORS headers, and then either leave them be, or overwrite them with new values. Adding multiple CORS headers doesn't seem to be good behaviour.

@aeirola
Copy link
Author

aeirola commented May 2, 2016

As for the CORS specification, it is stated under 7.2 Resource Sharing Check that the response should be considered invalid if it contains more than one Access-Control-Allow-Origin header.

@monarchwadia
Copy link

monarchwadia commented Jun 22, 2017

I also ran into this issue. I fixed it by changing the <url-pattern> to match only those routes which did not add CORS headers to their responses beforehand. This was easy in my case, but might not be very easy in other cases.

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

No branches or pull requests

2 participants