Skip to content

Commit

Permalink
Remove ineffective CSRF check for /webconfirm (#50102)
Browse files Browse the repository at this point in the history
The WithAuthCookieAndCSRF checks only apply CSRF checks for
state-changing (ie non-GET) requests. Since /webconfirm is
always a GET request, the previous code gave the impression
that CSRF tokens were validated which is not the case.

No behavior change here - just being more explicit about what is
being checked. There is no exploit due to not checking CSRF here
due to the strict session verification performed on the confirmation
token.
  • Loading branch information
zmb3 authored Dec 13, 2024
1 parent 1c0f919 commit 540f839
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/web/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ func (h *Handler) bindDefaultEndpoints() {
// Device Trust.
// Do not enforce bearer token for /webconfirm, it is called from outside the
// Web UI.
h.GET("/webapi/devices/webconfirm", h.WithAuthCookieAndCSRF(h.deviceWebConfirm))
h.GET("/webapi/devices/webconfirm", h.WithSession(h.deviceWebConfirm))

// trusted clusters
h.POST("/webapi/trustedclusters/validate", h.WithUnauthenticatedLimiter(h.validateTrustedCluster))
Expand Down Expand Up @@ -4698,9 +4698,22 @@ func (h *Handler) WithMetaRedirect(fn redirectHandlerFunc) httprouter.Handle {
}

// WithAuth ensures that a request is authenticated.
// Authenticated requests require both a session cookie as well as a bearer token.
func (h *Handler) WithAuth(fn ContextHandler) httprouter.Handle {
return httplib.MakeHandler(func(w http.ResponseWriter, r *http.Request, p httprouter.Params) (interface{}, error) {
sctx, err := h.AuthenticateRequest(w, r, true)
sctx, err := h.AuthenticateRequest(w, r, true /* check bearer token */)
if err != nil {
return nil, trace.Wrap(err)
}
return fn(w, r, p, sctx)
})
}

// WithSession ensures that the request provides a session cookie.
// It does not check for a bearer token.
func (h *Handler) WithSession(fn ContextHandler) httprouter.Handle {
return httplib.MakeHandler(func(w http.ResponseWriter, r *http.Request, p httprouter.Params) (interface{}, error) {
sctx, err := h.AuthenticateRequest(w, r, false /* check bearer token */)
if err != nil {
return nil, trace.Wrap(err)
}
Expand Down

0 comments on commit 540f839

Please sign in to comment.