mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user