mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 21:17:37 +03:00
fix(server): do not try to validate credentials if the request is canceled (#3650)
Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
parent
c37583fa9f
commit
47e3fdb1b8
1 changed files with 9 additions and 0 deletions
|
@ -2,6 +2,7 @@ package subsonic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cmp"
|
"cmp"
|
||||||
|
"context"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
|
@ -88,6 +89,10 @@ func authenticate(ds model.DataStore) func(next http.Handler) http.Handler {
|
||||||
|
|
||||||
if username := server.UsernameFromReverseProxyHeader(r); username != "" {
|
if username := server.UsernameFromReverseProxyHeader(r); username != "" {
|
||||||
usr, err = ds.User(ctx).FindByUsername(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) {
|
if errors.Is(err, model.ErrNotFound) {
|
||||||
log.Warn(ctx, "API: Invalid login", "auth", "reverse-proxy", "username", username, "remoteAddr", r.RemoteAddr, err)
|
log.Warn(ctx, "API: Invalid login", "auth", "reverse-proxy", "username", username, "remoteAddr", r.RemoteAddr, err)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
|
@ -102,6 +107,10 @@ func authenticate(ds model.DataStore) func(next http.Handler) http.Handler {
|
||||||
jwt, _ := p.String("jwt")
|
jwt, _ := p.String("jwt")
|
||||||
|
|
||||||
usr, err = ds.User(ctx).FindByUsernameWithPassword(username)
|
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) {
|
if errors.Is(err, model.ErrNotFound) {
|
||||||
log.Warn(ctx, "API: Invalid login", "auth", "subsonic", "username", username, "remoteAddr", r.RemoteAddr, err)
|
log.Warn(ctx, "API: Invalid login", "auth", "subsonic", "username", username, "remoteAddr", r.RemoteAddr, err)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue