Auth: Reduce lookup cookie error to warning and invalidate cookie (#53881)

* Reduce lookup cookie error to warning. Delete invalid cookie to avoid continuous refresh

* debug log branch
This commit is contained in:
Jo
2022-08-18 15:24:31 +02:00
committed by GitHub
parent ae69b1d99c
commit 10e6eac632

View File

@@ -397,8 +397,11 @@ func (h *ContextHandler) initContextWithToken(reqContext *models.ReqContext, org
token, err := h.AuthTokenService.LookupToken(ctx, rawToken)
if err != nil {
reqContext.Logger.Error("Failed to look up user based on cookie", "error", err)
reqContext.Logger.Warn("Failed to look up user based on cookie", "error", err)
// Burn the cookie in case of failure
reqContext.Resp.Before(h.deleteInvalidCookieEndOfRequestFunc(reqContext))
reqContext.LookupTokenErr = err
return false
}
@@ -420,6 +423,18 @@ func (h *ContextHandler) initContextWithToken(reqContext *models.ReqContext, org
return true
}
func (h *ContextHandler) deleteInvalidCookieEndOfRequestFunc(reqContext *models.ReqContext) web.BeforeFunc {
return func(w web.ResponseWriter) {
if w.Written() {
reqContext.Logger.Debug("Response written, skipping invalid cookie delete")
return
}
reqContext.Logger.Debug("Expiring invalid cookie")
cookies.DeleteCookie(reqContext.Resp, h.Cfg.LoginCookieName, nil)
}
}
func (h *ContextHandler) rotateEndOfRequestFunc(reqContext *models.ReqContext, authTokenService models.UserTokenService,
token *models.UserToken) web.BeforeFunc {
return func(w web.ResponseWriter) {