GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — fix: strip CORS headers from applications by code-asher · Pull Request #8057 · coder/coder Conversation
|
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I must be going mad, I have no idea how the response headers could change in perfect opposition to what I pass into the require.Equal for the expected value.
Examples of it swapping:
https://github.com/coder/coder/actions/runs/5284785388/jobs/9562577501
https://github.com/coder/coder/actions/runs/5284691553/jobs/9562383538
And all I did was add "Origin", to the check.
It happens consistently despite multiple attempts, always exactly the opposite. Could be a flake and just a coincidence that it always lines up with me changing the expected value...
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Headers should be case insensitive anyway. Vary: origin,Origin should be equal to Vary: origin. So this is fine imo.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Oddly it was two Origin strings, same capitalization. It seems so bizarre that the headers returned could change based on how I change completely unrelated code, so bizarre that I feel I must be doing something dunderheaded.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Do we need to change this section in our docs?
Applications can set their own headers which will override the defaults but this will only apply to non-preflight requests. Preflight requests through the dashboard are never sent to applications and thus cannot be modified by them. Read more about the difference between simple requests and requests that trigger preflights here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Yup, this PR also makes changes to this section. Let me know if you have any thoughts on the wording! https://github.com/coder/coder/pull/8057/files#diff-fee7817d909d710ad6c6a59e4a5fc65ea0b7608949e74c45e3465b1f51e5cc99R127-R132 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
The problem is that the headers get doubled up (not overwritten) and browsers do not like multiple values for the allowed origin even though it appears the spec allows for it. We could prefer the application's headers instead of ours but since we control OPTIONS I think preferring ours will by the more consistent experience and also aligns with the original RFC.
9aa2e85 to
4fabc54
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| varies := r.Header.Values(httpmw.VaryHeader) | ||
| r.Header.Del(httpmw.VaryHeader) | ||
| forbiddenVary := []string{ | ||
| httpmw.OriginHeader, | ||
| httpmw.AccessControlRequestMethodsHeader, | ||
| httpmw.AccessControlRequestHeadersHeader, | ||
| } | ||
| for _, value := range varies { | ||
| if !slice.ContainsCompare(forbiddenVary, value, strings.EqualFold) { | ||
| r.Header.Add(httpmw.VaryHeader, value) | ||
| } | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
What is this part doing?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I figure an application might Vary based on headers other than CORS-related headers, so I am adding back the ones that are not related to CORS. So if you have Vary: Access-Control-Request-Methods and Vary: X-Foobar the former gets removed while the latter gets kept.
Edit: I said the wrong thing initially, the latter gets kept not axed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Headers should be case insensitive anyway. Vary: origin,Origin should be equal to Vary: origin. So this is fine imo.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Somehow I totally missed the docs changes when I initially reviewed. All LGTM. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Handle case where application sends conflicting CORS headers
There was an error while loading. Please reload this page.