From 9637dcfcf8dac5aa5a0a91b2b07ece271b44895a Mon Sep 17 00:00:00 2001 From: Cesar Gonzalez Date: Fri, 27 Sep 2024 16:07:03 -0500 Subject: [PATCH] [PM-12775] Autofill should not occur within 2FA fields --- .../autofill/services/autofill-constants.ts | 1 + .../services/autofill.service.spec.ts | 20 +++++++------------ .../src/autofill/services/autofill.service.ts | 5 +++++ ...inline-menu-field-qualification.service.ts | 3 +-- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/apps/browser/src/autofill/services/autofill-constants.ts b/apps/browser/src/autofill/services/autofill-constants.ts index c379daaf2d..be8167e370 100644 --- a/apps/browser/src/autofill/services/autofill-constants.ts +++ b/apps/browser/src/autofill/services/autofill-constants.ts @@ -55,6 +55,7 @@ export class AutoFillConstants { static readonly PasswordFieldExcludeList: string[] = [ ...AutoFillConstants.FieldIgnoreList, + "hint", "onetimepassword", ]; diff --git a/apps/browser/src/autofill/services/autofill.service.spec.ts b/apps/browser/src/autofill/services/autofill.service.spec.ts index 455c171e59..7bd08caaf3 100644 --- a/apps/browser/src/autofill/services/autofill.service.spec.ts +++ b/apps/browser/src/autofill/services/autofill.service.spec.ts @@ -2260,29 +2260,23 @@ describe("AutofillService", () => { options, ); - expect(AutofillService.fieldIsFuzzyMatch).toHaveBeenCalledTimes(4); - expect(AutofillService.fieldIsFuzzyMatch).toHaveBeenNthCalledWith( - 1, + expect(AutofillService.fieldIsFuzzyMatch).toHaveBeenCalledWith( usernameField, AutoFillConstants.UsernameFieldNames, ); - expect(AutofillService.fieldIsFuzzyMatch).toHaveBeenNthCalledWith( - 2, + expect(AutofillService.fieldIsFuzzyMatch).toHaveBeenCalledWith( emailField, AutoFillConstants.UsernameFieldNames, ); - expect(AutofillService.fieldIsFuzzyMatch).toHaveBeenNthCalledWith( - 3, + expect(AutofillService.fieldIsFuzzyMatch).toHaveBeenCalledWith( telephoneField, AutoFillConstants.UsernameFieldNames, ); - expect(AutofillService.fieldIsFuzzyMatch).toHaveBeenNthCalledWith( - 4, + expect(AutofillService.fieldIsFuzzyMatch).toHaveBeenCalledWith( totpField, AutoFillConstants.UsernameFieldNames, ); - expect(AutofillService.fieldIsFuzzyMatch).not.toHaveBeenNthCalledWith( - 5, + expect(AutofillService.fieldIsFuzzyMatch).not.toHaveBeenCalledWith( nonViewableField, AutoFillConstants.UsernameFieldNames, ); @@ -2328,6 +2322,7 @@ describe("AutofillService", () => { it("will not attempt to fuzzy match a totp field if totp autofill is not allowed", async () => { options.allowTotpAutofill = false; + jest.spyOn(autofillService as any, "findMatchingFieldIndex"); await autofillService["generateLoginFillScript"]( fillScript, @@ -2336,7 +2331,7 @@ describe("AutofillService", () => { options, ); - expect(AutofillService.fieldIsFuzzyMatch).not.toHaveBeenCalledWith( + expect(autofillService["findMatchingFieldIndex"]).not.toHaveBeenCalledWith( expect.anything(), AutoFillConstants.TotpFieldNames, ); @@ -2386,7 +2381,6 @@ describe("AutofillService", () => { false, false, ); - expect(AutofillService.fieldIsFuzzyMatch).not.toHaveBeenCalled(); expect(AutofillService.fillByOpid).toHaveBeenCalledTimes(2); expect(AutofillService.fillByOpid).toHaveBeenNthCalledWith( 1, diff --git a/apps/browser/src/autofill/services/autofill.service.ts b/apps/browser/src/autofill/services/autofill.service.ts index cd49da7219..fc9b664415 100644 --- a/apps/browser/src/autofill/services/autofill.service.ts +++ b/apps/browser/src/autofill/services/autofill.service.ts @@ -2556,6 +2556,11 @@ export default class AutofillService implements AutofillServiceInterface { return; } + // We want to avoid treating TOTP fields as password fields + if (AutofillService.fieldIsFuzzyMatch(f, AutoFillConstants.TotpFieldNames)) { + return; + } + const isLikePassword = () => { if (f.type !== "text") { return false; diff --git a/apps/browser/src/autofill/services/inline-menu-field-qualification.service.ts b/apps/browser/src/autofill/services/inline-menu-field-qualification.service.ts index 0b04b83ce4..778e6a720a 100644 --- a/apps/browser/src/autofill/services/inline-menu-field-qualification.service.ts +++ b/apps/browser/src/autofill/services/inline-menu-field-qualification.service.ts @@ -30,7 +30,6 @@ export class InlineMenuFieldQualificationService this.webAuthnAutocompleteValue, ]); private fieldIgnoreListString = AutoFillConstants.FieldIgnoreList.join(","); - private passwordFieldExcludeListString = AutoFillConstants.PasswordFieldExcludeList.join(","); private currentPasswordAutocompleteValue = "current-password"; private newPasswordAutoCompleteValue = "new-password"; private autofillFieldKeywordsMap: AutofillKeywordsMap = new WeakMap(); @@ -927,7 +926,7 @@ export class InlineMenuFieldQualificationService return false; } - return !(this.passwordFieldExcludeListString.indexOf(cleanedValue) > -1); + return !AutoFillConstants.PasswordFieldExcludeList.some((i) => cleanedValue.indexOf(i) > -1); } /**