-
Notifications
You must be signed in to change notification settings - Fork 926
fix: strip CORS headers from applications #8057
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ import ( | |
"github.com/coder/coder/coderd/httpapi" | ||
"github.com/coder/coder/coderd/httpmw" | ||
"github.com/coder/coder/coderd/tracing" | ||
"github.com/coder/coder/coderd/util/slice" | ||
"github.com/coder/coder/coderd/wsconncache" | ||
"github.com/coder/coder/codersdk" | ||
"github.com/coder/coder/site" | ||
|
@@ -541,6 +542,26 @@ func (s *Server) proxyWorkspaceApp(rw http.ResponseWriter, r *http.Request, appT | |
defer release() | ||
proxy.Transport = conn.HTTPTransport() | ||
|
||
proxy.ModifyResponse = func(r *http.Response) error { | ||
r.Header.Del(httpmw.AccessControlAllowOriginHeader) | ||
r.Header.Del(httpmw.AccessControlAllowCredentialsHeader) | ||
r.Header.Del(httpmw.AccessControlAllowMethodsHeader) | ||
r.Header.Del(httpmw.AccessControlAllowHeadersHeader) | ||
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) | ||
} | ||
} | ||
Comment on lines
+550
to
+561
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this part doing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I figure an application might Edit: I said the wrong thing initially, the latter gets kept not axed. |
||
return nil | ||
} | ||
|
||
// This strips the session token from a workspace app request. | ||
cookieHeaders := r.Header.Values("Cookie")[:] | ||
r.Header.Del("Cookie") | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for 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...
There was a problem hiding this comment.
Choose a reason for 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 toVary: origin
. So this is fine imo.There was a problem hiding this comment.
Choose a reason for 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.