Skip to content

Commit 441457e

Browse files
committed
fix(PasswordLoginStrategy): [Auth/PM-21913] Fix Weak MP Login Bug (#14906)
Adds an early `return` after receiving an `IdentityTwoFactorResponse`. (cherry picked from commit 98e4551)
1 parent 3fc4ce7 commit 441457e

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

libs/auth/src/common/login-strategies/password-login.strategy.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,26 @@ describe("PasswordLoginStrategy", () => {
238238
);
239239
});
240240

241+
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 () => {
242+
passwordStrengthService.getPasswordStrength.mockReturnValue({ score: 0 } as any);
243+
policyService.evaluateMasterPassword.mockReturnValue(false);
244+
tokenService.decodeAccessToken.mockResolvedValue({ sub: userId });
245+
246+
const token2FAResponse = new IdentityTwoFactorResponse({
247+
TwoFactorProviders: ["0"],
248+
TwoFactorProviders2: { 0: null },
249+
error: "invalid_grant",
250+
error_description: "Two factor required.",
251+
MasterPasswordPolicy: masterPasswordPolicy,
252+
});
253+
254+
// First login request fails requiring 2FA
255+
apiService.postIdentityToken.mockResolvedValueOnce(token2FAResponse);
256+
await passwordLoginStrategy.logIn(credentials);
257+
258+
expect(masterPasswordService.mock.setForceSetPasswordReason).not.toHaveBeenCalled();
259+
});
260+
241261
it("forces the user to update their master password on successful 2FA login when it does not meet master password policy requirements", async () => {
242262
passwordStrengthService.getPasswordStrength.mockReturnValue({ score: 0 } as any);
243263
policyService.evaluateMasterPassword.mockReturnValue(false);

libs/auth/src/common/login-strategies/password-login.strategy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ export class PasswordLoginStrategy extends LoginStrategy {
186186
...this.cache.value,
187187
forcePasswordResetReason: ForceSetPasswordReason.WeakMasterPassword,
188188
});
189+
return;
189190
}
190191

191192
// Authentication was successful, save the force update password options with the state service

0 commit comments

Comments
 (0)