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

cors: set access-control-expose-headers on actual CORS request #3852

Merged

Conversation

stanley-cheung
Copy link
Contributor

Description: Set the access-control-expose-headers response header on the actual CORS request (not preflight). Currently, if I set a custom header from the upstream server, I can't retrieve the value of that header from the browser getResponseHeaders() API because the access-control-expose-headers response header is only set on the preflight OPTIONS request, not the actual POST request.
Risk Level: low
Testing: bazel test /test/...
Docs Changes: None
Release Notes: None

Signed-off-by: Stanley Cheung stanleycheung@google.com

…S request

Signed-off-by: Stanley Cheung <stanleycheung@google.com>
@stanley-cheung
Copy link
Contributor Author

Maintainers: this is the first time I try to submit a PR. I noticed the 2 CI tests failures. How should I proceed? Any tips on how to reproduce that locally? Could that be flakes? My change seems unrelated. Please advise. Thanks!

@dio
Copy link
Member

dio commented Jul 13, 2018

@stanley-cheung you can try to do master merge, hopefully, that will heal the echo_integration_test flakiness.

Signed-off-by: Stanley Cheung <stanleycheung@google.com>
@stanley-cheung
Copy link
Contributor Author

@dio Thanks. That works. I merge master in and all tests passed now.

@htuch htuch requested review from dio and mattklein123 July 13, 2018 14:19
Copy link
Member

@dio dio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @stanley-cheung for doing this. Only one nit and a comment below:

This patch is interesting since currently, we have this header Access-Control-Expose-Headers being sent only for a response of a preflight request. However, based on this flowchart in this article, we should only send it as part of an actual response for a normal request, i.e. as proposed by this PR. I also did a quick look at this express' cors module: https://github.com/expressjs/cors/blob/master/test/test.js#L570-L622 and the relevant RFC, those confirm the flowchart.

@mattklein123 @codesuki thoughts?

route->mutable_route()->set_cluster("cluster_0");
auto* cors = route->mutable_route()->mutable_cors();
cors->add_allow_origin("test-origin-1");
cors->set_expose_headers("custom-header-1");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, can we have a comma-separated list of headers here (e.g. X-My-Custom-Header, X-Another-Custom-Header)? Just to make a point that we can express setting multiple headers by doing so.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dio, thanks for the review. I have updated the test with multiple expose-headers.

Should I also take out the setting of access-control-expose-headers in the OPTIONS request in this same PR?

@codesuki
Copy link
Member

After re-reading the rfc I agree this is correct.

https://www.w3.org/TR/cors/#resource-requests

Also expose headers should be removed from the preflight request since it's not noted in 6.2.

Additionally I found some points where a preflight request should probably terminate early which it's not doing yet. I'll follow up on that later this week.

Signed-off-by: Stanley Cheung <stanleycheung@google.com>
Signed-off-by: Stanley Cheung <stanleycheung@google.com>
Signed-off-by: Stanley Cheung <stanleycheung@google.com>
@stanley-cheung
Copy link
Contributor Author

@codesuki Thanks for the review! I have updated the PR to not set access-control-expose-headers in the response to the OPTIONS request.

Copy link
Member

@dio dio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

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

Successfully merging this pull request may close these issues.

4 participants