From 391c8671e9eaa11c51ca9c7d3ed8803b1e034981 Mon Sep 17 00:00:00 2001 From: James Elliott Date: Sat, 13 Mar 2021 15:52:07 +1100 Subject: [PATCH] fix(handlers): log user as '' instead of a blank string (#1808) --- internal/handlers/handler_verify.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/handlers/handler_verify.go b/internal/handlers/handler_verify.go index 37ccfe483..a1c305936 100644 --- a/internal/handlers/handler_verify.go +++ b/internal/handlers/handler_verify.go @@ -236,8 +236,13 @@ func verifySessionCookie(ctx *middlewares.AutheliaCtx, targetURL *url.URL, userS } func handleUnauthorized(ctx *middlewares.AutheliaCtx, targetURL fmt.Stringer, isBasicAuth bool, username string, method []byte) { + friendlyUsername := "" + if username != "" { + friendlyUsername = username + } + if isBasicAuth { - ctx.Logger.Infof("Access to %s is not authorized to user %s, sending 401 response with basic auth header", targetURL.String(), username) + ctx.Logger.Infof("Access to %s is not authorized to user %s, sending 401 response with basic auth header", targetURL.String(), friendlyUsername) ctx.ReplyUnauthorized() ctx.Response.Header.Add("WWW-Authenticate", "Basic realm=\"Authentication required\"") @@ -265,11 +270,11 @@ func handleUnauthorized(ctx *middlewares.AutheliaCtx, targetURL fmt.Stringer, is redirectionURL = fmt.Sprintf("%s?rd=%s", rd, url.QueryEscape(targetURL.String())) } - ctx.Logger.Infof("Access to %s (method %s) is not authorized to user %s, redirecting to %s", targetURL.String(), friendlyMethod, username, redirectionURL) + ctx.Logger.Infof("Access to %s (method %s) is not authorized to user %s, redirecting to %s", targetURL.String(), friendlyMethod, friendlyUsername, redirectionURL) ctx.Redirect(redirectionURL, 302) ctx.SetBodyString(fmt.Sprintf("Found. Redirecting to %s", redirectionURL)) } else { - ctx.Logger.Infof("Access to %s (method %s) is not authorized to user %s, sending 401 response", targetURL.String(), friendlyMethod, username) + ctx.Logger.Infof("Access to %s (method %s) is not authorized to user %s, sending 401 response", targetURL.String(), friendlyMethod, friendlyUsername) ctx.ReplyUnauthorized() } }