Skip to content

Commit

Permalink
Add some basic headers to OSIN provided pages
Browse files Browse the repository at this point in the history
Use restrictive defaults for basic security hygiene.

Signed-off-by: Simo Sorce <simo@redhat.com>
  • Loading branch information
simo5 committed Oct 24, 2017
1 parent f10a493 commit 10a7b84
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/auth/server/grant/grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/golang/glog"
"github.com/openshift/origin/pkg/auth/authenticator"
"github.com/openshift/origin/pkg/auth/server/csrf"
"github.com/openshift/origin/pkg/auth/server/headers"
scopeauthorizer "github.com/openshift/origin/pkg/authorization/authorizer/scope"
oapi "github.com/openshift/origin/pkg/oauth/apis/oauth"
oauthclient "github.com/openshift/origin/pkg/oauth/generated/internalclientset/typed/oauth/internalversion"
Expand Down Expand Up @@ -112,6 +113,8 @@ func (l *Grant) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return
}

headers.SetStandardHeaders(w)

switch req.Method {
case "GET":
l.handleForm(user, w, req)
Expand Down
29 changes: 29 additions & 0 deletions pkg/auth/server/headers/headers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package headers

import (
"net/http"
)

func SetStandardHeaders(w http.ResponseWriter) {

// We cannot set HSTS by default, it has too many drawbacks in environments
// that use self-signed certs
standardHeaders := map[string]string{
// Turn off caching, it never makes sense for authorization pages
"Cache-Control": "no-cache, no-store",
"Pragma": "no-cache",
"Expires": "0",
// Use a reasonably strict Referer policy by default
"Referrer-Policy": "strict-origin-when-cross-origin",
// 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",
"X-DNS-Prefetch-Control": "off",
"X-XSS-Protection": "1; mode=block",
}

for key, val := range standardHeaders {
w.Header().Set(key, val)
}
}
2 changes: 2 additions & 0 deletions pkg/auth/server/login/implicit.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/openshift/origin/pkg/auth/authenticator"
"github.com/openshift/origin/pkg/auth/oauth/handlers"
"github.com/openshift/origin/pkg/auth/server/csrf"
"github.com/openshift/origin/pkg/auth/server/headers"
)

type RequestAuthenticator interface {
Expand Down Expand Up @@ -51,6 +52,7 @@ func NewConfirm(csrf csrf.CSRF, auth RequestAuthenticator, render ConfirmFormRen
}

func (c *Confirm) ServeHTTP(w http.ResponseWriter, req *http.Request) {
headers.SetStandardHeaders(w)
switch req.Method {
case "GET":
c.handleConfirmForm(w, req)
Expand Down
2 changes: 2 additions & 0 deletions pkg/auth/server/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/openshift/origin/pkg/auth/prometheus"
"github.com/openshift/origin/pkg/auth/server/csrf"
"github.com/openshift/origin/pkg/auth/server/errorpage"
"github.com/openshift/origin/pkg/auth/server/headers"
)

const (
Expand Down Expand Up @@ -95,6 +96,7 @@ func (l *Login) Install(mux Mux, paths ...string) {
}

func (l *Login) ServeHTTP(w http.ResponseWriter, req *http.Request) {
headers.SetStandardHeaders(w)
switch req.Method {
case "GET":
l.handleLoginForm(w, req)
Expand Down

0 comments on commit 10a7b84

Please sign in to comment.