From d879cb5c1946a5f760dfd8bc65f9754bd6477afa Mon Sep 17 00:00:00 2001 From: kolaente Date: Mon, 19 Oct 2026 20:52:58 +0200 Subject: [PATCH] fix(ldap): keep the login when storing the synced avatar fails Address pr-swarm finding: a busy decode budget made StoreAvatarFile fail the whole LDAP login with 503, while OIDC skips the avatar. --- pkg/modules/auth/ldap/ldap.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/modules/auth/ldap/ldap.go b/pkg/modules/auth/ldap/ldap.go index 0e88e4127..c4336b072 100644 --- a/pkg/modules/auth/ldap/ldap.go +++ b/pkg/modules/auth/ldap/ldap.go @@ -202,7 +202,6 @@ func AuthenticateUserInLDAP(ctx context.Context, s *xorm.Session, username, pass if avatarSyncAttribute != "" { raw := sr.Entries[0].GetRawAttributeValue(avatarSyncAttribute) - u.AvatarProvider = "ldap" // Process the avatar image to ensure 1:1 aspect ratio processedAvatar, err := utils.CropAvatarTo1x1(ctx, raw) @@ -210,11 +209,15 @@ func AuthenticateUserInLDAP(ctx context.Context, s *xorm.Session, username, pass log.Debugf("Error processing LDAP avatar: %v", err) // Continue without avatar if processing fails } else { + previousProvider := u.AvatarProvider + u.AvatarProvider = "ldap" err = upload.StoreAvatarFile(ctx, s, u, bytes.NewReader(processedAvatar)) if err != nil { - return nil, err + u.AvatarProvider = previousProvider + log.Errorf("Error storing LDAP avatar for user %s: %v", u.Username, err) + } else { + avatar.FlushAllCaches(u) } - avatar.FlushAllCaches(u) } }