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

fix(cors): don't send Access-Control-Allow-Origin header where a single origin(not regex) is configured #10898

Closed
wants to merge 2 commits into from

Conversation

ms2008
Copy link
Contributor

@ms2008 ms2008 commented May 19, 2023

Summary

The CORS plugin currently always sets the Access-Control-Allow-Origin header based on the plugin configuration if the configuration only has a single entry and contains only non-PCRE metacharacters. This behavior is first introduced in #2482 and doesn't seem to have any real impact on the functionality I think.

But this seems is not following the mozilla guidelines

Specifies an origin. Only a single origin can be specified. If the server supports clients from multiple origins, it must return the origin for the specific client making the request.

This fixes behavior by no longer sending an ACAO header in this case.

These changes seem reasonable to me, but happy to hear feedback.

Checklist

Full changelog

  • don't send ACAO header where a single origin(not regex) is configured in case of non-matched.

Issue reference

Fix FTI-4745

@ms2008 ms2008 marked this pull request as ready for review May 19, 2023 04:23
Copy link
Member

@sumimakito sumimakito left a comment

Choose a reason for hiding this comment

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

LGTM

@ms2008 ms2008 force-pushed the fix/cors-align-with-mdn branch 2 times, most recently from 4e77aa2 to cced81e Compare May 29, 2023 06:45
@bungle
Copy link
Member

bungle commented May 29, 2023

Since this has been so long in a products, do we consider this as a fix. It seems like a potentially breaking change?

@hbagdi, @kikito?

ms2008 added 2 commits June 12, 2023 08:45
configured in case of non-matched.

The CORS plugin currently always sets the ACAO header based on the
plugin configuration if the configuration only has a single entry and
contains only non-PCRE metacharacters. This behavior is first introduced
in #2482 and doesn't seem to have any real impact on the functionality I
think.

But this seems is not following the [mozilla
guidelines](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin)

> Specifies an origin. Only a single origin can be specified. If the
server supports clients from multiple origins, it must return the origin
for the specific client making the request.

This fixes behavior by no longer sending an ACAO header in this case.
@ms2008 ms2008 force-pushed the fix/cors-align-with-mdn branch from cced81e to 4a6c032 Compare June 12, 2023 00:46
@hbagdi
Copy link
Member

hbagdi commented Jun 12, 2023

I recall putting in a comment but I cannot see it here now.
I agree with Aapo that this can cause breakage, a large one because we put this in to be smart about this.

@ms2008
Copy link
Contributor Author

ms2008 commented Jun 30, 2023

Please move this forward @hbagdi @kikito

@kikito
Copy link
Member

kikito commented Jul 4, 2023

I don’t like what we are currently doing, and I don’t like that we are not following the CORS standard. I would have zero concerns about doing this on a major release (4.0).

However, CORS is our most used plugin according to our stats. Making changes such as this on a minor release can be very problematic.

@ms2008 is it possible to fix the customer issue (missing port) without removing the "smartness" from the plugin? If there is, that would be my preferred way to do this.

While we decide this, can we give the customer a workaround? E.g. would it be possible to sidestep this problem by adding a "dummy" domain in the config?

To summarize, my proposed solution would be:

  • Give the customer a workaround if there's any
  • Close this PR and open a new one.
  • Add the port to the current "smart" code
  • Add a deprecation notice that puts a log line saying that this behavior is deprecated and will change in 4.0. Put a comment linking to this PR
  • Document this behavior (and the fact that it will change in 4.0) on the plugin docs page.
  • When we start implementing 4.0, we should be able to grep for deprecation deprecation notices, and be pointed to this PR.

@ms2008
Copy link
Contributor Author

ms2008 commented Jul 5, 2023

@kikito I read the RFC and W3C specifications carefully, and I think the behavior of stripping the port part(if it is equal to the default value) is reasonable even though they are explicitly specified in the Origin request header.

I have tried to verify this behavior(stripping the default port) on Chrome and have determined if Chrome recognizes this behavior. Unfortunately, Chrome does not allow custom CORS requests for origin at all.

I still think this is an issue with the customer's own specific software and should be left up to them to fix(e.g. customize their own CORS plugin), not to change our behavior.

@VicYP
Copy link

VicYP commented Jul 11, 2023

@kikito @hbagdi We do need to consider fixing this one in the future major release. Could we "freeze" this one and let it be ready for the coming major release.

@hbagdi
Copy link
Member

hbagdi commented Jul 11, 2023

Could we "freeze" this one and

What does 'freeze' mean in the context of this PR?

@VicYP
Copy link

VicYP commented Sep 10, 2023

Can this one be a feature candidate in 3.5? @hbagdi @ms2008

@hanshuebner hanshuebner changed the title fix(cors): don't send ACAO header where a single origin(not regex) is configured fix(cors): don't send Access-Control-Allow-Origin header where a single origin(not regex) is configured Sep 10, 2023
@ms2008
Copy link
Contributor Author

ms2008 commented Sep 11, 2023

I think the concerns raised by Apao and Enrique are valid. Considering that it seems like a potentially breaking change and doesn't have any substantial impact on functionality, I lean towards closing this PR.

@ms2008 ms2008 closed this Sep 13, 2023
@kong-rob kong-rob deleted the fix/cors-align-with-mdn branch January 29, 2025 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants