1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-06 00:13:28 +00:00

fix(PasswordLoginStrategy): [Auth/PM-21913] Fix Weak MP Login Bug (#14906)

Adds an early `return` after receiving an `IdentityTwoFactorResponse`.
This commit is contained in:
rr-bw
2025-05-23 12:02:01 -07:00
committed by GitHub
parent 217014a30e
commit 98e4551f70
2 changed files with 21 additions and 0 deletions

View File

@@ -238,6 +238,26 @@ describe("PasswordLoginStrategy", () => {
);
});
it("should not set a force set password reason if we get an IdentityTwoFactorResponse after entering a weak MP that does not meet policy requirements", async () => {
passwordStrengthService.getPasswordStrength.mockReturnValue({ score: 0 } as any);
policyService.evaluateMasterPassword.mockReturnValue(false);
tokenService.decodeAccessToken.mockResolvedValue({ sub: userId });
const token2FAResponse = new IdentityTwoFactorResponse({
TwoFactorProviders: ["0"],
TwoFactorProviders2: { 0: null },
error: "invalid_grant",
error_description: "Two factor required.",
MasterPasswordPolicy: masterPasswordPolicy,
});
// First login request fails requiring 2FA
apiService.postIdentityToken.mockResolvedValueOnce(token2FAResponse);
await passwordLoginStrategy.logIn(credentials);
expect(masterPasswordService.mock.setForceSetPasswordReason).not.toHaveBeenCalled();
});
it("forces the user to update their master password on successful 2FA login when it does not meet master password policy requirements", async () => {
passwordStrengthService.getPasswordStrength.mockReturnValue({ score: 0 } as any);
policyService.evaluateMasterPassword.mockReturnValue(false);

View File

@@ -186,6 +186,7 @@ export class PasswordLoginStrategy extends LoginStrategy {
...this.cache.value,
forcePasswordResetReason: ForceSetPasswordReason.WeakMasterPassword,
});
return;
}
// Authentication was successful, save the force update password options with the state service