-
Notifications
You must be signed in to change notification settings - Fork 222
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
[v0.11.0] Access-Control-Request-Headers
is matched as-is, without normalization.
#183
Comments
Please see #176 |
@stonedu1011 This is working as expected. In addition to #176, see #180 and #181. TL;DR: According to the Fetch standard, the |
@stonedu1011 Can we close this issue? |
@rs Without feedback from the OP, I'm inclined to close this. |
I was also hit by this and had to spend an hour now debugging why upgrading this library is breaking tests. I am not sure if it is really so costly to convert all incoming headers to lowercase before proceeding? I mean, in general in Internet protocols you should be standard-strict in your outputs and lenient in your inputs to maximize interoperability. This has now been reported few times, here, #174, #176, #181. Also, I do not find it nice that headers in |
Sorry about the breakage, which indeed seems to have affected several people. Perhaps one mistake was not to highlight, in the library's changelog, the change in behaviour. Note that all those issues have now been closed, though, and people seem far from outraged. As explained in those other issues, if you must test your CORS-aware server, make sure to respect the format for the ACRH header: comma-separated, lowercase, unique, lexicographically ordered values.
The Fetch standard does specify that the ACRH header contains lowercase elements and, although field names are case-insensitive, intermediates (proxies, gateways, middleware, etc.) must not change the case of field values; at least, that's my understanding of HTTP standards. Therefore, CORS middleware should reasonably expect elements of ACRH to be lowercase. As for Postel's law, I believe that @rs agrees with me about not being too liberal, in order to guarantee better performance. But if you can implement the behaviour you desire without affecting performance too detrimentally, be my guest and submit a PR; @rs might be willing to accept it.
I'm puzzled: why would you care? The CORS protocol is not for human consumption... You configure your CORS middleware, apply it where it counts, and you should be able to forget about it.
Elements in the value of the |
It is OK. Thanks for all the work and attention to details here. It is just frustrating that this might be much easier with some changelog entry or README entry or something, explaining that headers have to be now lower case and sorted
I am not familiar enough with implementation here and no time to really go into it, but doing lowercase on a string should be O(n) on the string and that should not be too expensive? But I am not sure what margin of performance people are going for here. Sorting can be probably slow, true. In any case, I think it is fine how it is, we should optimize for the main use case, not for testing. But README entry might be enough here.
You might have to go around the web fixing more pages: |
I strongly agree: rs/cors does need a changelog; feel free (if time allows) to open an issue about that. FWIW, jub0bs/cors has one, in which I endeavour to highlight all important changes.
I'm curious about this. What are those tests meant to check? That the
Lowercasing a string indeed takes O(n) time (where n is the string's length), but may require an allocation, and one of my goals is to minimise needless allocations. I don't know of any compiler optimisation that eliminates this allocation; see https://go.dev/play/p/4EiSWuHvtT1
That's the thing: it's not just about making the library easy for normal people to use, but also to make its middleware hard for adversaries to abuse. In this connection, see #170 (if you haven't already).
Good catch. I wasn't familiar with http.dev. I'll see if I can fix that page, somehow. |
In my case I use many library to build my HTTP stack for apps and I have tests which check that given a particular HTTP request I get expected HTTP response. It is useful to check that behavior is consistent as I upgrade libraries and dependencies. Or at least that I am aware of a change. But yes, the client is simulated which was a problem in this case. :-)
I think using the following to convert string into
And then going into a loop over |
Thanks for the additional context.
That requires the |
It would be dangerous to use unsafe on strings we don't own. An alternative way may be to have both lowercase and mime-case versions of allowed headers in the allow set with equal position value? |
If case insensitivity is the goal, the library should cater for all case variations, e.g. not just |
I think the library's goal is easy of used combined with performance and safety. To me only supporting the two most common cases and leaving the unusual ones for performance reasons feels reasonable. What do you think? |
I think it is fine as it is, just document it somewhere. :-) Something like:
|
If you're asking me, I think case sensitivity in ACRH should be maintained, for reasons explained in an earlier comment. As far as jub0bs/cors is concerned, unless someone can offer convincing counterarguments, I'm unwilling to compromise on case sensitivity. As for rs/cors, it's out of my hands, but implementing what you suggested seems straightforward. |
Test to reproduce the issue:
Result: The test succeeded in
v0.10.1
but failed inv0.11.0
:Cause:
In
v0.10.1
and previous versions, bothAllowedHeaders
and actual header values were normalized withhttp.CanonicalHeaderKey
.In
v0.11.1
,AllowedHeaders
is normalized usingstrings.ToLower
(cors.go
Ln 199). However, the actual header values are not normalized (internal/sortedset.go
Ln 69-79)The text was updated successfully, but these errors were encountered: