-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
fix(cors): add 'vary: origin' header if not set by backend #10490
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for kubernetes-ingress-nginx canceled.
|
This issue is currently awaiting triage. If Ingress contributors determines this is a relevant issue, they will accept it by applying the The Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Hi @aslafy-z. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
That might actually be it. https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#access-control-allow-origin I might have missed it when going through the docs. |
Should be roughly around this area for cors annotations. https://github.com/kubernetes/ingress-nginx/blob/main/test/e2e/annotations/cors.go#L430 |
fedd8a9
to
25477e5
Compare
@larivierec I implemented a test, feel free to give a look :) |
46d6193
to
67f5df2
Compare
I fixed the tests @larivierec |
Looks good. One thing though, I've seen you've written a new e2e test for your functionality however, all other e2e tests using wildcards should also respond with vary. I'm pretty sure there should be a couple more to modify. Can you have another look? |
@larivierec I'm wondering if it will not made more complex to read the other tests with "unrelated" checks. What do you think? Do you think I should add |
I don't think that's a good idea. For example, the ones that don't have a wildcard domain, won't have the vary header. If you add it tests will fail. |
@larivierec ones that have a wildcard domains are not the only impacted with this change. If possible I'd prefer to not return that Vary header when the allowed origins contains a single static entry but I found no easy way of doing so. Any idea? |
ok, you may be right. Like you mentioned, when there's more than 1 allow origin and also when there's a wildcard. Here's a snippet from the mozilla docs:
I think you'd have to add some extra logic in the build cors origin regex to set the In the section above, and this will will modify the result of the template tests and e2e tests. Your fix might be as simple as adding a new line and adding the header. I hope this helps a bit. :) |
bd18dd4
to
3f8cdbe
Compare
Signed-off-by: GitHub <noreply@github.com>
@larivierec I added a conditional to only insert this header when needed and added tests to validate it. Please give a new look. |
lgtm |
@rikatz can you please have a look? |
@rikatz Is there something missing from that PR or can it go forward? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left my review a year ago, hopefully the maintainers might find time to look at the issue
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: aslafy-z, larivierec The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What this PR does / why we need it:
CORS with multiple allowed origin need to serve the 'Vary: Origin' header.
This can be done on the backend side, however, users delegates the CORS setup to their ingress.
For security reason, we disable their use of the snippet annotations, so they can't use it to insert the header.
This change conditionally add the 'Vary' header to 'Origin', if the header is not defined by the backend and the configured allowed origins matches one of these conditions:
*
)Types of changes
Which issue/s this PR fixes
relates to #8469 (comment)
How Has This Been Tested?
Checklist: