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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion 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 @@ -106,12 +107,13 @@ func (l *Grant) Install(mux Mux, paths ...string) {
}

func (l *Grant) ServeHTTP(w http.ResponseWriter, req *http.Request) {
headers.SetStandardHeaders(w)

user, ok, err := l.auth.AuthenticateRequest(req)
if err != nil || !ok {
l.redirect("You must reauthenticate before continuing", w, req)
return
}

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)
}
}
151 changes: 0 additions & 151 deletions pkg/auth/server/login/implicit.go

This file was deleted.

146 changes: 0 additions & 146 deletions pkg/auth/server/login/implicit_test.go

This file was deleted.

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
Loading