-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Add some basic headers to OSIN provided pages #17010
Conversation
@enj PTAL |
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.
Needs review from @openshift/api-review and @jwforres to make sure this won't break anything.
pkg/auth/server/headers/headers.go
Outdated
|
||
// We cannot set HSTS by default, it has too many drawbacks in environments | ||
// that use self-signed certs | ||
const standardHeaders map[string]string{ |
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 don't know what half of these mean.
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.
It means I should commit -a --amend it with the code I had locally, before sending half baked code from when I drafted the first write. sigh.
pkg/auth/server/headers/headers.go
Outdated
|
||
func SetStandardHeaders(w http.ResponseWriter) { | ||
for key, val := range standardHeaders { | ||
w.Header.Add(key, val) |
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.
Set seems more appropriate than add.
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.
Ok
cc @openshift/sig-security |
@simo5 maps cannot be consts.
|
pkg/auth/server/headers/headers.go
Outdated
// Do not allow embedding as that can lead to clickjacking attacks | ||
"X-Frame-Options": "DENY", | ||
// Add other basic scurity hygiene headers | ||
"X-Content-Type-Options": "nosniff", |
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.
According to https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options nosniff
could be troublesome if applied to image resources. Are default header only applied to HTML sources?
Note: nosniff only applies to "script" and "style" types. Also applying nosniff to images turned out to be incompatible with existing web sites.
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.
We do not send images in OSIN afaik, but also that page says:
"Note: nosniff only applies to "script" and "style" types." so I don't think we have a problem.
pkg/auth/server/headers/headers.go
Outdated
"X-Content-Type-Options": "nosniff", | ||
"X-DNS-Prefetch-Control": "off", | ||
"X-XSS-Protection": "1; mode=block", | ||
} |
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.
What about CSP headers, https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP ?
We might want to set script src and style src.
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.
Just like for HSTS I am not sure we can set a static CSP because branding may add stuff to pages I think.
But I'll let @enj comment on that
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.
Yeah customer branding would definitely be an issue here, you would have to make the CSP configurable. Seems outside the scope of this particular PR.
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.
Indeed @jwforres , I am going to make an Issue and we can resolve that in 3.8
CSP sounds like something we may want to share with Web console as far as using a common option when customer needs changes, perhaps.
Maybe it's better to re-use this code also for #17002 or it's impossible? |
We should be able to wrap the entire OAuth mux with a handler that adds these headers so we only have to do it in one place. |
2820ab0
to
10a7b84
Compare
@php-coder we are adding more headers (namely those to prevent caching) which cannot be added by default to web console because they have a lot of static assets (images/css) that should be cached. Perhaps we could have acommon set and then wrap it, but OSIN and Webconsole may have differeing opinions and I do not see that much value in sharing a for loop over a constant that may need to differ. |
Yeah I tend to agree with @simo5 on having a separate handler from the console. If we shared I would worry about headers getting added that weren't appropriate in one case or the other. Plus we still intend to split out the console from the master at some point. |
@eparis I am goign to add kind/bug to this PR and push it to master as the lack of headers is aguably a bug, as we should always have sent more restrictive ones. However it is a tiny change in behavior so I want your belssing. |
/test cmd |
please open a BZ so QA looks specifically in this area, then feel free |
@eparis we have a BZ, thanks |
/test extended_conformance_gce |
@cheimes CSP tracked here #17021 |
This code is not wired anywhere. Signed-off-by: Simo Sorce <[email protected]>
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.
Just some minor nits.
} | ||
|
||
// Hit the login URL | ||
loginURL := &url.URL{} |
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.
loginURL := *baseURL
is the normal way to do this.
|
||
// Hit the grant URL | ||
grantURL := &url.URL{} | ||
*grantURL = *baseURL |
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.
Same comment.
for key, val := range checkImportantHeaders { | ||
header := resp.Header.Get(key) | ||
if header != val { | ||
t.Fatalf("While probing %s expected header %s: %s, got {%v}", check_url, key, val, header) |
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.
t.Errorf
seems more appropriate so that you do not quit the test early.
@liggitt PTAL at the headers and dead code that was removed. |
Use restrictive defaults for basic security hygiene. Signed-off-by: Simo Sorce <[email protected]>
/approve |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: enj, liggitt, simo5 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
Automatic merge from submit-queue (batch tested with PRs 17020, 17026, 17000, 17010). |
Use restrictive defaults for basic security hygiene.