Skip to content

Commit

Permalink
authenticate: only use csrf none for apple
Browse files Browse the repository at this point in the history
  • Loading branch information
calebdoxsey committed Feb 15, 2023
1 parent f2a5bda commit ae79bca
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions authenticate/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/pomerium/pomerium/internal/handlers"
"github.com/pomerium/pomerium/internal/httputil"
"github.com/pomerium/pomerium/internal/identity"
"github.com/pomerium/pomerium/internal/identity/oauth/apple"
"github.com/pomerium/pomerium/internal/identity/oidc"
"github.com/pomerium/pomerium/internal/log"
"github.com/pomerium/pomerium/internal/middleware"
Expand All @@ -45,8 +46,7 @@ func (a *Authenticate) Mount(r *mux.Router) {
options := a.options.Load()
state := a.state.Load()
csrfKey := fmt.Sprintf("%s_csrf", options.CookieName)
return csrf.Protect(
state.cookieSecret,
csrfOptions := []csrf.Option{
csrf.Secure(options.CookieSecure),
csrf.Path("/"),
csrf.UnsafePaths(
Expand All @@ -56,12 +56,19 @@ func (a *Authenticate) Mount(r *mux.Router) {
csrf.FormValueName("state"), // rfc6749#section-10.12
csrf.CookieName(csrfKey),
csrf.FieldName(csrfKey),
csrf.ErrorHandler(httputil.HandlerFunc(httputil.CSRFFailureHandler)),
}

if options.Provider == apple.Name {
// csrf.SameSiteLaxMode will cause browsers to reset
// the session on POST. This breaks Appleid being able
// to verify the csrf token.
csrf.SameSite(csrf.SameSiteNoneMode),
csrf.ErrorHandler(httputil.HandlerFunc(httputil.CSRFFailureHandler)),
)(h)
csrfOptions = append(csrfOptions, csrf.SameSite(csrf.SameSiteNoneMode))
} else {
csrfOptions = append(csrfOptions, csrf.SameSite(csrf.SameSiteLaxMode))
}

return csrf.Protect(state.cookieSecret, csrfOptions...)(h)
})

// redirect / to /.pomerium/
Expand Down

0 comments on commit ae79bca

Please sign in to comment.