Skip to content

Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.

fix(backend:auth): increment failed attempts for 2FA-enabled users

johavenb13a4aad5c2b
diff --git a/backend/src/applications/users/services/users-manager.service.spec.ts b/backend/src/applications/users/services/users-manager.service.spec.ts
index 5ec41dc4..758ba44a 100755
--- a/backend/src/applications/users/services/users-manager.service.spec.ts
+++ b/backend/src/applications/users/services/users-manager.service.spec.ts
@@ -279,6 +279,8 @@ describe(UsersManager.name, () => {
const u3 = new UserModel({ ...generateUserTest(), secrets: { twoFaSecret: 'secret' } } as any, false)
await expect(usersManager.updateAccesses(u3, 'new.ip', true)).resolves.toBeUndefined()
expect(usersQueriesService.updateAccesses).toHaveBeenCalledWith(u3.id, 'new.ip', 'preserve')
+ await expect(usersManager.updateAccesses(u3, 'new.ip', false)).resolves.toBeUndefined()
+ expect(usersQueriesService.updateAccesses).toHaveBeenCalledWith(u3.id, 'new.ip', 'increment')
usersQueriesService.updateAccesses = vi.fn().mockResolvedValue(false)
await expect(usersManager.updateAccesses(u1, 'new.ip', false)).rejects.toThrow('Unable to update user accesses')
diff --git a/backend/src/applications/users/services/users-manager.service.ts b/backend/src/applications/users/services/users-manager.service.ts
index 1ed781e6..c01e1164 100755
--- a/backend/src/applications/users/services/users-manager.service.ts
+++ b/backend/src/applications/users/services/users-manager.service.ts
@@ -180,7 +180,7 @@ export class UsersManager {
}
async updateAccesses(user: UserModel, ip: string, success: boolean, isAuthTwoFa = false) {
- const preservePasswordAttempts = !isAuthTwoFa && configuration.auth.mfa.totp.enabled && user.twoFaEnabled
+ const preservePasswordAttempts = success && !isAuthTwoFa && configuration.auth.mfa.totp.enabled && user.twoFaEnabled
if (!(await this.usersQueries.updateAccesses(user.id, ip, preservePasswordAttempts ? 'preserve' : success ? 'reset' : 'increment'))) {
throw new Error('Unable to update user accesses')
}