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

Add some basic headers to OSIN provided pages #17010

Merged
merged 2 commits into from
Oct 25, 2017

Conversation

simo5
Copy link
Contributor

@simo5 simo5 commented Oct 23, 2017

Use restrictive defaults for basic security hygiene.

@openshift-ci-robot openshift-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 23, 2017
@simo5
Copy link
Contributor Author

simo5 commented Oct 23, 2017

@enj PTAL

Copy link
Contributor

@enj enj left a 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.


// We cannot set HSTS by default, it has too many drawbacks in environments
// that use self-signed certs
const standardHeaders map[string]string{
Copy link
Contributor

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.

Copy link
Contributor Author

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.


func SetStandardHeaders(w http.ResponseWriter) {
for key, val := range standardHeaders {
w.Header.Add(key, val)
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok

@enj
Copy link
Contributor

enj commented Oct 24, 2017

cc @openshift/sig-security

@enj
Copy link
Contributor

enj commented Oct 24, 2017

@simo5 maps cannot be consts.

++ Building go targets for linux/amd64: cmd/openshift cmd/oc cmd/kubefed cmd/template-service-broker pkg/network/sdn-cni-plugin vendor/github.com/containernetworking/cni/plugins/ipam/host-local vendor/github.com/containernetworking/cni/plugins/main/loopback
# github.com/openshift/origin/pkg/auth/server/headers
pkg/auth/server/headers/headers.go:9: syntax error: unexpected { after top level declaration
pkg/auth/server/headers/headers.go:9: const declaration cannot have type without expression
pkg/auth/server/headers/headers.go:9: missing value in const declaration
[ERROR] PID 105: hack/lib/build/binaries.sh:228: `GOOS=${platform%/*} GOARCH=${platform##*/} go install -pkgdir "${OS_OUTPUT_PKGDIR}/${platform}" -tags "${OS_GOFLAGS_TAGS-} ${!platform_gotags_envvar:-}" -ldflags="${local_ldflags}" "${goflags[@]:+${goflags[@]}}" "${nonstatics[@]}"` exited with status 2.

tiran
tiran previously requested changes Oct 24, 2017
// 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",
Copy link
Contributor

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.

Copy link
Contributor Author

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.

"X-Content-Type-Options": "nosniff",
"X-DNS-Prefetch-Control": "off",
"X-XSS-Protection": "1; mode=block",
}
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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.

@php-coder
Copy link
Contributor

Maybe it's better to re-use this code also for #17002 or it's impossible?

@enj
Copy link
Contributor

enj commented Oct 24, 2017

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.

@simo5 simo5 force-pushed the authheaders branch 2 times, most recently from 2820ab0 to 10a7b84 Compare October 24, 2017 12:50
@simo5
Copy link
Contributor Author

simo5 commented Oct 24, 2017

@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.

@jwforres
Copy link
Member

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.

@simo5
Copy link
Contributor Author

simo5 commented Oct 24, 2017

@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.

@simo5
Copy link
Contributor Author

simo5 commented Oct 24, 2017

/test cmd

@eparis
Copy link
Member

eparis commented Oct 24, 2017

please open a BZ so QA looks specifically in this area, then feel free

@simo5
Copy link
Contributor Author

simo5 commented Oct 24, 2017

@eparis we have a BZ, thanks

@simo5 simo5 added the kind/bug Categorizes issue or PR as related to a bug. label Oct 24, 2017
@simo5
Copy link
Contributor Author

simo5 commented Oct 24, 2017

/test extended_conformance_gce

@simo5
Copy link
Contributor Author

simo5 commented Oct 24, 2017

@cheimes CSP tracked here #17021

This code is not wired anywhere.

Signed-off-by: Simo Sorce <[email protected]>
@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 25, 2017
enj
enj previously requested changes Oct 25, 2017
Copy link
Contributor

@enj enj left a 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{}
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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.

@enj
Copy link
Contributor

enj commented Oct 25, 2017

@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]>
@liggitt
Copy link
Contributor

liggitt commented Oct 25, 2017

/approve

@openshift-merge-robot openshift-merge-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 25, 2017
@enj
Copy link
Contributor

enj commented Oct 25, 2017

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 25, 2017
@openshift-merge-robot
Copy link
Contributor

[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 /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@openshift-merge-robot
Copy link
Contributor

Automatic merge from submit-queue (batch tested with PRs 17020, 17026, 17000, 17010).

@openshift-merge-robot openshift-merge-robot merged commit 87e24b0 into openshift:master Oct 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.