authenticate: support webauthn redirects to non-pomerium domains (#2936)

* authenticate: support webauthn redirects to non-pomerium domains

* add test

* remove dead code
This commit is contained in:
Caleb Doxsey 2022-01-19 15:10:57 -07:00 committed by GitHub
parent 6b26f58e4f
commit 95d6d97143
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 191 additions and 93 deletions

View file

@ -50,12 +50,13 @@ var (
// State is the state needed by the Handler to handle requests.
type State struct {
SharedKey []byte
Client databroker.DataBrokerServiceClient
Session *session.Session
SessionState *sessions.State
SessionStore sessions.SessionStore
RelyingParty *webauthn.RelyingParty
SharedKey []byte
Client databroker.DataBrokerServiceClient
PomeriumDomains []string
Session *session.Session
SessionState *sessions.State
SessionStore sessions.SessionStore
RelyingParty *webauthn.RelyingParty
}
// A StateProvider provides state for the handler.
@ -392,6 +393,12 @@ func (h *Handler) handleView(w http.ResponseWriter, r *http.Request, state *Stat
}
func (h *Handler) saveSessionAndRedirect(w http.ResponseWriter, r *http.Request, state *State, rawRedirectURI string) error {
// if the redirect URL is for a URL we don't control, just do a plain redirect
if !isURLForPomerium(state.PomeriumDomains, rawRedirectURI) {
httputil.Redirect(w, r, rawRedirectURI, http.StatusFound)
return nil
}
// save the session to the databroker
res, err := session.Put(r.Context(), state.Client, state.Session)
if err != nil {
@ -513,3 +520,18 @@ func getOrCreateDeviceEnrollment(
}
return deviceEnrollment, nil
}
func isURLForPomerium(pomeriumDomains []string, rawURI string) bool {
uri, err := urlutil.ParseAndValidateURL(rawURI)
if err != nil {
return false
}
for _, domain := range pomeriumDomains {
if urlutil.StripPort(domain) == urlutil.StripPort(uri.Host) {
return true
}
}
return false
}