Skip to content

fix(cors): add 'vary: origin' header if not set by backend #10490

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aslafy-z
Copy link
Contributor

@aslafy-z aslafy-z commented Oct 10, 2023

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:

  • set to any (*)
  • set to more than one entry
  • contains a wildcard

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • CVE Report (Scanner found CVE and adding report)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation only

Which issue/s this PR fixes

relates to #8469 (comment)

How Has This Been Tested?

  • Automatic tests only

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have added unit and/or e2e tests to cover my changes.
  • All new and existing tests passed.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Oct 10, 2023
@netlify
Copy link

netlify bot commented Oct 10, 2023

Deploy Preview for kubernetes-ingress-nginx canceled.

Name Link
🔨 Latest commit 8be3706
🔍 Latest deploy log https://app.netlify.com/projects/kubernetes-ingress-nginx/deploys/6837208b55028800083f8ef5

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Oct 10, 2023
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If Ingress contributors determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Oct 10, 2023
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added needs-priority size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 10, 2023
@aslafy-z aslafy-z changed the title fix: add vary header if unset with cors requests fix(cors): add vary: origin if header unset Oct 10, 2023
@aslafy-z aslafy-z changed the title fix(cors): add vary: origin if header unset fix(cors): add vary: origin if header is not set Oct 10, 2023
@aslafy-z aslafy-z changed the title fix(cors): add vary: origin if header is not set fix(cors): add 'vary: origin' header if not set by backend Oct 10, 2023
@larivierec
Copy link
Contributor

larivierec commented Oct 10, 2023

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.
There are some tests in Go that will need to be modified however

@larivierec
Copy link
Contributor

Should be roughly around this area for cors annotations.

https://github.com/kubernetes/ingress-nginx/blob/main/test/e2e/annotations/cors.go#L430

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 11, 2023
@aslafy-z aslafy-z force-pushed the patch-2 branch 2 times, most recently from fedd8a9 to 25477e5 Compare October 11, 2023 08:06
@aslafy-z aslafy-z marked this pull request as ready for review October 11, 2023 08:43
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 11, 2023
@k8s-ci-robot k8s-ci-robot requested a review from cpanato October 11, 2023 08:43
@aslafy-z
Copy link
Contributor Author

@larivierec I implemented a test, feel free to give a look :)

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 11, 2023
@aslafy-z aslafy-z force-pushed the patch-2 branch 11 times, most recently from 3f8cdbe to cb71d7e Compare November 13, 2023 11:19
@aslafy-z
Copy link
Contributor Author

@larivierec I added a conditional to only insert this header when needed and added tests to validate it. Please give a new look.

@larivierec
Copy link
Contributor

lgtm
:)

@aslafy-z
Copy link
Contributor Author

@rikatz can you please have a look?

@zifeo
Copy link

zifeo commented Jan 30, 2024

@rikatz Is there something missing from that PR or can it go forward?

Copy link
Contributor

@larivierec larivierec left a 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

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 28, 2025
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 28, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: aslafy-z, larivierec
Once this PR has been reviewed and has the lgtm label, please assign gacko for approval. For more information see the Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@aslafy-z aslafy-z force-pushed the patch-2 branch 4 times, most recently from bdd50c4 to 9eca8f3 Compare May 28, 2025 14:38
Signed-off-by: Zadkiel AHARONIAN <hello@zadkiel.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/docs cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants