Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.
TypeScript cloud-alternativecollaborationcollaborative-editingdropboxfile-serverfile-sharingfile-storagefile-syncfull-text-searchhomelabnextcloudon-premiseopen-sourceprivacy-firstprivate-cloudrealtimesecureself-hostedstorage-serverwebdav
fix(backend:auth): reject empty passwords before LDAP bind
johaven7e7845e5eebf
diff --git a/backend/src/authentication/guards/auth-basic.guard.spec.ts b/backend/src/authentication/guards/auth-basic.guard.spec.tsindex 148b1b8f..1f0a95ef 100644--- a/backend/src/authentication/guards/auth-basic.guard.spec.ts+++ b/backend/src/authentication/guards/auth-basic.guard.spec.ts@@ -95,6 +95,18 @@ describe(AuthBasicGuard.name, () => {expect(userWithColonPassword.password).toBeUndefined()})+ it('should reject an empty password before calling the authentication provider', async () => {+ const encodedAuthWithEmptyPassword = Buffer.from(`${userTest.login}:`).toString('base64')+ authProvider.validateUser = vi.fn()+ context.switchToHttp().getRequest.mockReturnValue({+ raw: { user: '' },+ headers: { authorization: `Basic ${encodedAuthWithEmptyPassword}` }+ })++ await expect(authBasicGuard.canActivate(context)).rejects.toThrow()+ expect(authProvider.validateUser).not.toHaveBeenCalled()+ })+it('should validate the user authentication with cache', async () => {cache.get = vi.fn().mockReturnValueOnce(userTest)context.switchToHttp().getRequest.mockReturnValue({diff --git a/backend/src/authentication/guards/implementations/http-basic.strategy.ts b/backend/src/authentication/guards/implementations/http-basic.strategy.tsindex 140d20f9..80f1ef7f 100644--- a/backend/src/authentication/guards/implementations/http-basic.strategy.ts+++ b/backend/src/authentication/guards/implementations/http-basic.strategy.ts@@ -62,7 +62,7 @@ export class HttpBasicStrategy extends PassportStrategy {}const [userid, password] = splitFirst(decoded, ':')- if (password === undefined) {+ if (password === undefined || password.length === 0) {return this.fail(400)}diff --git a/backend/src/authentication/providers/ldap/auth-provider-ldap.service.spec.ts b/backend/src/authentication/providers/ldap/auth-provider-ldap.service.spec.tsindex fb30e5ba..d08853a2 100644--- a/backend/src/authentication/providers/ldap/auth-provider-ldap.service.spec.ts+++ b/backend/src/authentication/providers/ldap/auth-provider-ldap.service.spec.ts@@ -187,6 +187,16 @@ describe(AuthProviderLDAP.name, () => {expect(loggerErrorSpy).toHaveBeenCalled()})+ it('should reject an empty password before accessing LDAP', async () => {+ const res = await authProviderLDAP.validateUser('john', '')++ expect(res).toBeNull()+ expect(usersManager.findUser).not.toHaveBeenCalled()+ expect(Client).not.toHaveBeenCalled()+ expect(ldapClient.bind).not.toHaveBeenCalled()+ expect(adminUsersManager.createUserOrGuest).not.toHaveBeenCalled()+ })+it('should return null on invalid LDAP credentials without fallback', async () => {const existingUser: any = buildUser({ id: 1 })usersManager.findUser.mockResolvedValue(existingUser)diff --git a/backend/src/authentication/providers/ldap/auth-provider-ldap.service.ts b/backend/src/authentication/providers/ldap/auth-provider-ldap.service.tsindex dbd46433..18c9b377 100644--- a/backend/src/authentication/providers/ldap/auth-provider-ldap.service.ts+++ b/backend/src/authentication/providers/ldap/auth-provider-ldap.service.ts@@ -34,6 +34,10 @@ export class AuthProviderLDAP implements AuthProvider {) {}async validateUser(loginOrEmail: string, password: string, ip?: string, scope?: AUTH_SCOPE): Promise<UserModel> {+ if (password.length === 0) {+ return null+ }+// Authenticate user via LDAP and sync local user state.// Find user from his login or emailconst localLogin = this.dbLogin(loginOrEmail)diff --git a/backend/src/authentication/providers/ldap/ldap.md b/backend/src/authentication/providers/ldap/ldap.mdindex 26996edb..585105c4 100644--- a/backend/src/authentication/providers/ldap/ldap.md+++ b/backend/src/authentication/providers/ldap/ldap.md@@ -56,6 +56,10 @@ entry, or a successful search that returns an unusable entry ends the authenticaLDAP client connections use a six-second operation timeout and a six-second connect timeout.+Sync-in rejects zero-length user passwords before opening an LDAP connection. Directory operators must also disable unauthenticated simple binds+(a non-empty bind DN with an empty password) and anonymous binds in the LDAP server policy; the application-side check is defense in depth, not a+replacement for that server-side restriction.+## User searchUser searches run under `baseDN` with subtree scope. Sync-in asks LDAP for the known login attributes, common profile attributes, the configured email