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

authenticate: only use csrf none for apple #3979

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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