From 47e3fdb1b8e0ad795485a615dde7865c45e65dfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deluan=20Quint=C3=A3o?= Date: Thu, 16 Jan 2025 22:32:11 -0300 Subject: [PATCH] fix(server): do not try to validate credentials if the request is canceled (#3650) Signed-off-by: Deluan --- server/subsonic/middlewares.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server/subsonic/middlewares.go b/server/subsonic/middlewares.go index 78e7a0640..9c578a8e8 100644 --- a/server/subsonic/middlewares.go +++ b/server/subsonic/middlewares.go @@ -2,6 +2,7 @@ package subsonic import ( "cmp" + "context" "crypto/md5" "encoding/hex" "errors" @@ -88,6 +89,10 @@ func authenticate(ds model.DataStore) func(next http.Handler) http.Handler { if username := server.UsernameFromReverseProxyHeader(r); username != "" { usr, err = ds.User(ctx).FindByUsername(username) + if errors.Is(err, context.Canceled) { + log.Debug(ctx, "API: Request canceled when authenticating", "auth", "reverse-proxy", "username", username, "remoteAddr", r.RemoteAddr, err) + return + } if errors.Is(err, model.ErrNotFound) { log.Warn(ctx, "API: Invalid login", "auth", "reverse-proxy", "username", username, "remoteAddr", r.RemoteAddr, err) } else if err != nil { @@ -102,6 +107,10 @@ func authenticate(ds model.DataStore) func(next http.Handler) http.Handler { jwt, _ := p.String("jwt") usr, err = ds.User(ctx).FindByUsernameWithPassword(username) + if errors.Is(err, context.Canceled) { + log.Debug(ctx, "API: Request canceled when authenticating", "auth", "subsonic", "username", username, "remoteAddr", r.RemoteAddr, err) + return + } if errors.Is(err, model.ErrNotFound) { log.Warn(ctx, "API: Invalid login", "auth", "subsonic", "username", username, "remoteAddr", r.RemoteAddr, err) } else if err != nil {