Skip to content

Commit

Permalink
authenticate: add CSP headers to this service only (pomerium#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
desimone authored May 15, 2019
1 parent cfac5f1 commit 27d4683
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
17 changes: 12 additions & 5 deletions authenticate/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,24 @@ import (
"github.com/pomerium/pomerium/internal/version"
)

// CSPHeaders adds content security headers for authenticate's handlers
var CSPHeaders = map[string]string{
"Content-Security-Policy": "default-src 'none'; style-src 'self' 'sha256-pSTVzZsFAqd2U3QYu+BoBDtuJWaPM/+qMy/dBRrhb5Y='; img-src 'self';",
"Referrer-Policy": "Same-origin",
}

// Handler returns the authenticate service's HTTP request multiplexer, and routes.
func (a *Authenticate) Handler() http.Handler {
// validation middleware chain
validate := middleware.NewChain()
validate = validate.Append(middleware.ValidateSignature(a.SharedKey))
c := middleware.NewChain()
c = c.Append(middleware.SetHeaders(CSPHeaders))
validate := c.Append(middleware.ValidateSignature(a.SharedKey))
validate = validate.Append(middleware.ValidateRedirectURI(a.RedirectURL))
mux := http.NewServeMux()
mux.HandleFunc("/robots.txt", a.RobotsTxt)
mux.Handle("/robots.txt", c.ThenFunc(a.RobotsTxt))
// Identity Provider (IdP) callback endpoints and callbacks
mux.HandleFunc("/start", a.OAuthStart)
mux.HandleFunc("/oauth2/callback", a.OAuthCallback)
mux.Handle("/start", c.ThenFunc(a.OAuthStart))
mux.Handle("/oauth2/callback", c.ThenFunc(a.OAuthCallback))
// authenticate-server endpoints
mux.Handle("/sign_in", validate.ThenFunc(a.SignIn))
mux.Handle("/sign_out", validate.ThenFunc(a.SignOut)) // GET POST
Expand Down
2 changes: 0 additions & 2 deletions cmd/pomerium/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ var defaultOptions = &Options{
"X-Frame-Options": "SAMEORIGIN",
"X-XSS-Protection": "1; mode=block",
"Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload",
"Content-Security-Policy": "default-src 'none'; style-src 'self' 'sha256-pSTVzZsFAqd2U3QYu+BoBDtuJWaPM/+qMy/dBRrhb5Y='; img-src 'self';",
"Referrer-Policy": "Same-origin",
},
}

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/certificates.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ It should be noted that there are countless ways of building and managing [publi

::: warning

LetsEncrypt certificates certificates must be renewed [every 90 days](https://letsencrypt.org/2015/11/09/why-90-days.html).
LetsEncrypt certificates must be renewed [every 90 days](https://letsencrypt.org/2015/11/09/why-90-days.html).

:::

Expand Down

0 comments on commit 27d4683

Please sign in to comment.