Skip to content

Commit

Permalink
web: don't log unauthenticated requests for index.html
Browse files Browse the repository at this point in the history
It's super common to see requests for index.html that either have
an expired or missing session cookie. Stop logging an error with a
long stack trace since there's nothing unusual happening here.

This removes the "need auth" or "missing session cookie" noise that
often clutters debug logs.
  • Loading branch information
zmb3 committed Dec 23, 2024
1 parent 60aaa6d commit 85714e7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/web/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,10 +657,10 @@ func NewHandler(cfg Config, opts ...HandlerOption) (*APIHandler, error) {
h.logger.WarnContext(r.Context(), "Failed to generate CSRF token", "error", err)
}

session, err := h.authenticateWebSession(w, r)
if err != nil {
h.logger.DebugContext(r.Context(), "Could not authenticate", "error", err)
}
// Ignore errors here, as unauthenticated requests for index.html are common - the user might
// not have logged in yet, or their session may have expired.
// The web app will show them the login page in this case.
session, _ := h.authenticateWebSession(w, r)
session.XCSRF = csrfToken

httplib.SetNoCacheHeaders(w.Header())
Expand Down Expand Up @@ -724,7 +724,7 @@ type webSession struct {
}

func (h *Handler) authenticateWebSession(w http.ResponseWriter, r *http.Request) (webSession, error) {
ctx, err := h.AuthenticateRequest(w, r, false)
ctx, err := h.AuthenticateRequest(w, r, false /* validate bearer token */)
if err != nil {
return webSession{}, trace.Wrap(err)
}
Expand Down

0 comments on commit 85714e7

Please sign in to comment.