Skip to content

CORS: HTTPCORSFilter and GEP 1767 clean-ups - #4506

Merged
k8s-ci-robot merged 8 commits into
kubernetes-sigs:mainfrom
DamianSawicki:GEP-1767-improvements
Feb 6, 2026
Merged

k8s-ci-robot merged 8 commits into
kubernetes-sigs:mainfrom
DamianSawicki:GEP-1767-improvements

Conversation

@DamianSawicki

@DamianSawicki DamianSawicki commented Feb 6, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind gep

What this PR does / why we need it:
This cleans up certain aspects in GEP 1767 and the corresponding apis/v1/httproute_types.go file.

  • Omit the vague mention of "implementation-specific default" methods and headers.
  • Unify the GEP and the Golang file as they have diverged during edits.
  • In the GEP, allow using specific values in Access-Control-Allow-Methods and Access-Control-Allow-Headers response headers even if the corresponding config contains the wildcard and the request is not credentialed. The previous specification was overly restrictive: using specific values seems allowed by standards in such cases and it is actually how some implementations behave.
  • Unify the wording and validation between allowMethods and allowHeaders.
  • Last but not least: add a new GEP section to clarify confusion regarding Wildcards are forbidden in CORS response headers to credentialed requests rather than with allowCredentials: True #4281.

Which issue(s) this PR fixes:

Addresses #3861 and #4493.

Does this PR introduce a user-facing change?:

Not sure.


Previously, the GEP mentioned allowing "implementatio-specific default
methods and headers". It's not obvious what that means, but my
understanding is that this would allow implementations to arbitrarily
add certain values (not specified by the user) to the headers
Access-Control-Allow-Methods and Access-Control-Request-Headers`.
It does not seem to be needed. We can revisit this aspect
if it turns out otherwise.

Signed-off-by: Damian Sawicki <dsawicki@google.com>
It seems that not all changes in GEP 1767 were correctly reflected in
apis/v1/httproute_types.go. This is now fixed.

Signed-off-by: Damian Sawicki <dsawicki@google.com>
@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. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/gep PRs related to Gateway Enhancement Proposal(GEP) cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Feb 6, 2026
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 6, 2026
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

Hi @DamianSawicki. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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.

Details

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-sigs/prow repository.

As per
kubernetes-sigs#4494 (comment)
Mozilla has an example where in response to an uncredentialed request,
the server responds with `Access-Control-Allow-Origin: *`.

However, responding with the value of the Origin from the request is
also valid (and the only allowed behavior for credentialed requests),
and it is the behavior of some implementations as per
https://github.com/kubernetes-sigs/gateway-api/blob/b1a7a927b098a4ab99c3bf9983412cb2f1a419fd/conformance/tests/httproute-cors.go#L399-L401
so let's relax the requirement in the GEP to allow it.
As per
https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Methods#syntax
wildcard is a valid value for the Access-Control-Allow-Methods header.

However, as per
 * envoyproxy/envoy#8218
 * https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Methods#browser_compatibility
the wildcard was not universally supported by browsers in 2019,
and hence many implementations don't use the wildcard.

Signed-off-by: Damian Sawicki <dsawicki@google.com>
@rikatz

rikatz commented Feb 6, 2026

Copy link
Copy Markdown
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 6, 2026
Comment thread apis/v1/httproute_types.go Outdated
// A wildcard indicates that the requests with all HTTP headers are allowed.
// The `Access-Control-Allow-Headers` response header can only use `*`
// wildcard as value when the `AllowCredentials` field is false or omitted.
// wildcard as value when the request is not credentialed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

one information that I got when checking for it was that the behavior of "*" on the Access-Control-Allow-Headers is supported just on modern browsers.

Also, I am wondering if we want to enforce the validation on the API: https://github.com/kubernetes-sigs/gateway-api/blob/main/apis/v1/httproute_types.go#L1483

We can probably say that if the allowCredentials = true on the API, the usage of wildcard is disabled on allow methods and allow headers

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

one information that I got when checking for it was that the behavior of "*" on the Access-Control-Allow-Headers is supported just on modern browsers.

Yeah, I've just relaxed that in the following commit 9bf6df2:

Allow specific Allow-Methods despite wildcard
As per
https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Methods#syntax
wildcard is a valid value for the Access-Control-Allow-Methods header.

However, as per

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also, I am wondering if we want to enforce the validation on the API: https://github.com/kubernetes-sigs/gateway-api/blob/main/apis/v1/httproute_types.go#L1483

I don't have a strong opinion on that, but I guess I'd keep this validation. It does not really make sense to specify anything else when the wildcard is specified, does it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We can probably say that if the allowCredentials = true on the API, the usage of wildcard is disabled on allow methods and allow headers

No. Wildcard is forbidden in Access-Control-Request-Method and Access-Control-Request-Headers when the request is credentialed, not when "allowCredentials = true on the API". This is the fundamental confusion from #3861.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

per Mozilla spec on https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS

When responding to a credentialed request:

    The server must not specify the * wildcard for the Access-Control-Allow-Origin response-header value, but must instead specify an explicit origin; for example: Access-Control-Allow-Origin: https://example.com

    The server must not specify the * wildcard for the Access-Control-Allow-Headers response-header value, but must instead specify an explicit list of header names; for example, Access-Control-Allow-Headers: X-PINGOTHER, Content-Type

    The server must not specify the * wildcard for the Access-Control-Allow-Methods response-header value, but must instead specify an explicit list of method names; for example, Access-Control-Allow-Methods: POST, GET

    The server must not specify the * wildcard for the Access-Control-Expose-Headers response-header value, but must instead specify an explicit list of header names; for example, Access-Control-Expose-Headers: Content-Encoding, Kuma-Revision

So, I can test here on Envoy, and check if we set the allowCredentials if Envoy will filter out the wildcard methods to the requested method on the preflight or not, my concern is that if it doesn't, it will be very hard to make Envoy define when wildcard should be answered vs when the specific list of headers on the request headers will be used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

if Envoy will filter out the wildcard methods to the requested method on the preflight or not, my concern is that if it doesn't

It does. See envoyproxy/envoy#8218 quoted above in #4506 (comment) from the commit description. This was addressed by envoyproxy/envoy#19882 (perhaps the PR did more than the Issue asked, but in particular it addressed the issue).

Signed-off-by: Damian Sawicki <dsawicki@google.com>
@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 Feb 6, 2026
This uniformizes the validation for allowMethods and allowHeaders by
requiring that when '*' appears in allowHeaders, it must be the only
value in the list.

Signed-off-by: Damian Sawicki <dsawicki@google.com>
Signed-off-by: Damian Sawicki <dsawicki@google.com>
@DamianSawicki DamianSawicki changed the title CORS GEP 1767 clean-ups CORS: HTTPCORSFilter and GEP 1767 clean-ups Feb 6, 2026
@DamianSawicki
DamianSawicki marked this pull request as ready for review February 6, 2026 17:53
@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 Feb 6, 2026

@robscott robscott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @DamianSawicki!

Comment on lines +1592 to +1593
// When the `MaxAge` field is unspecified, the gateway sets the response
// header "Access-Control-Max-Age: 5" by default.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Isn't this the same as the sentence above?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I just reconciled the Golang file accordingly; it's been like that in the GEP already.

// The default value of `Access-Control-Max-Age` response header is
// 5 (seconds).
//
// When the `MaxAge` field is unspecified, the gateway sets the response
// header "Access-Control-Max-Age: 5" by default.

Having that said, I believe these two sentences differ as follows:

  • The first sentence means that according to HTTP standards, when Access-Control-Max-Age is unset, the browser assumes 5 s as the default.
  • The second sentence says that in order not to rely on browsers, Gateway API requires the proxy to explicitely set Access-Control-Max-Age: 5 when the Gateway user does not specify HTTPCorsFilter.maxAge.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The first sentence means that according to HTTP standards, when Access-Control-Max-Age is unset, the browser assumes 5 s as the default.

Oh interesting, I'd interpreted that as meaning the default value of the field to be 5, which it is below. In practice that API-level default means that Gateway implementations don't really need to do anything special for this 5s default to apply.

In any case, although this is slightly confusing/repetitive, all statements are correct, so don't want to block this PR on this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am not sure this is always truth, like NGINX may set a different response. I would probably leave this as "if not set, the proxy will set a default" or whatever

eg.: on NGINX: https://enable-cors.org/server_nginx.html

if you don't set explicitly the answers, it will not send any default.

Comment thread geps/gep-1767/index.md
configuration the gateway will _not_ include the
`Access-Control-Allow-Credentials` header in responses.

## Wildcard Resolution and Credentials

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This section is incredibly helpful, thanks for adding this @DamianSawicki!

Comment thread geps/gep-1767/index.md Resolved
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: DamianSawicki, robscott

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details 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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 6, 2026
Signed-off-by: Damian Sawicki <dsawicki@google.com>
@rikatz

rikatz commented Feb 6, 2026

Copy link
Copy Markdown
Member

/lgtm
discussed it with Rob, we are fine with the current changes. I will be working a bit more on it during weekend/next week to cleanup and clarify a bit more of expected behavior and conformance, and this should be good to go

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 6, 2026
@rikatz

rikatz commented Feb 6, 2026

Copy link
Copy Markdown
Member

/release-note-none
/hold cancel

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Feb 6, 2026
@rikatz

rikatz commented Feb 6, 2026

Copy link
Copy Markdown
Member

/cherry-pick release-1.5

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown
Contributor

@rikatz: once the present PR merges, I will cherry-pick it on top of release-1.5 in a new PR and assign it to you.

Details

In response to this:

/cherry-pick release-1.5

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-sigs/prow repository.

@k8s-ci-robot
k8s-ci-robot merged commit 8ecfe98 into kubernetes-sigs:main Feb 6, 2026
20 checks passed
@k8s-infra-cherrypick-robot

Copy link
Copy Markdown
Contributor

@rikatz: new pull request created: #4510

Details

In response to this:

/cherry-pick release-1.5

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-sigs/prow repository.

danehans pushed a commit to danehans/gateway-api that referenced this pull request Mar 10, 2026
* Remove implementation-specific methods/headers

Previously, the GEP mentioned allowing "implementatio-specific default
methods and headers". It's not obvious what that means, but my
understanding is that this would allow implementations to arbitrarily
add certain values (not specified by the user) to the headers
Access-Control-Allow-Methods and Access-Control-Request-Headers`.
It does not seem to be needed. We can revisit this aspect
if it turns out otherwise.

Signed-off-by: Damian Sawicki <dsawicki@google.com>

* Unify gep-1767 and httproute_types.go

It seems that not all changes in GEP 1767 were correctly reflected in
apis/v1/httproute_types.go. This is now fixed.

Signed-off-by: Damian Sawicki <dsawicki@google.com>

* Allow specific Allow-Origin despite wildcard

As per
kubernetes-sigs#4494 (comment)
Mozilla has an example where in response to an uncredentialed request,
the server responds with `Access-Control-Allow-Origin: *`.

However, responding with the value of the Origin from the request is
also valid (and the only allowed behavior for credentialed requests),
and it is the behavior of some implementations as per
https://github.com/kubernetes-sigs/gateway-api/blob/b1a7a927b098a4ab99c3bf9983412cb2f1a419fd/conformance/tests/httproute-cors.go#L399-L401
so let's relax the requirement in the GEP to allow it.

* Allow specific Allow-Methods despite wildcard

As per
https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Methods#syntax
wildcard is a valid value for the Access-Control-Allow-Methods header.

However, as per
 * envoyproxy/envoy#8218
 * https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Methods#browser_compatibility
the wildcard was not universally supported by browsers in 2019,
and hence many implementations don't use the wildcard.

Signed-off-by: Damian Sawicki <dsawicki@google.com>

* Reword comment for allowHeaders to match methods

Signed-off-by: Damian Sawicki <dsawicki@google.com>

* Copy validation for * from allowMethods to headers

This uniformizes the validation for allowMethods and allowHeaders by
requiring that when '*' appears in allowHeaders, it must be the only
value in the list.

Signed-off-by: Damian Sawicki <dsawicki@google.com>

* Add section on wildcards to GEP 1767

Signed-off-by: Damian Sawicki <dsawicki@google.com>

* Update GEP 1767 metadata with new PR

Signed-off-by: Damian Sawicki <dsawicki@google.com>

---------

Signed-off-by: Damian Sawicki <dsawicki@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/gep PRs related to Gateway Enhancement Proposal(GEP) lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesn't merit a release note. 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.

5 participants