Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Update browser extension autofill form detection for TOTP false positives (#2394)

Leendert de Borst8475a477eccf
diff --git a/apps/browser-extension/src/utils/formDetector/FieldPatterns.ts b/apps/browser-extension/src/utils/formDetector/FieldPatterns.ts
index e08516686..1deb8ab80 100644
--- a/apps/browser-extension/src/utils/formDetector/FieldPatterns.ts
+++ b/apps/browser-extension/src/utils/formDetector/FieldPatterns.ts
@@ -121,9 +121,11 @@ export const EnglishFieldPatterns: FieldPatterns = {
totp: {
include: {
// specific: strong terms that can clearly identify a TOTP field on their own.
- specific: ['totp', 'otp', 'one-time', 'onetime', 'six-digit', 'digit-code', 'authenticator', 'authentication', '2fa', 'twofa', 'two-factor', 'mfa', 'security-code', 'auth-code', 'passcode', 'pin-code', 'pincode', 'google_code', 'verification-code', 'verificationcode', 'tfa', 'tfacode', 'second-factor', 'one time password'],
- // generic: terms too weak to match on their own (can create false positives), but can be used for additional context matching.
- generic: ['token', 'code']
+ specific: ['totp', 'otp', 'one-time', 'onetime', 'six-digit', 'digit-code', 'authenticator', 'authentication', '2fa', 'twofa', 'two-factor', 'mfa', 'security-code', 'auth-code', 'pin-code', 'pincode', 'google_code', 'verification-code', 'verificationcode', 'tfa', 'tfacode', 'second-factor', 'one time password'],
+ /*
+ * generic: terms too weak to match on their own (can create false positives), but can be used for additional context matching.
+ */
+ generic: ['token', 'code', 'passcode']
},
// exclude: whole-word terms that if found negate the TOTP match.
exclude: ['test']
diff --git a/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.en.test.ts b/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.en.test.ts
index 2158a6247..1ea50da13 100644
--- a/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.en.test.ts
+++ b/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.en.test.ts
@@ -1,6 +1,7 @@
import { describe, expect, it } from 'vitest';
import { FormDetector } from '../FormDetector';
+import { DetectedFieldType } from '../types/FormFields';
import { FormField, testField, createTestDom } from './TestUtils';
@@ -423,4 +424,38 @@ describe('FormDetector English tests', () => {
});
});
+ /*
+ * Password step of a multi-step sign-in flow whose password input is named
+ * "credentials.passcode" (a name also used for TOTP challenge inputs).
+ * The "passcode" term alone must not turn a type="password" field
+ * with a "Password" label into a 2FA field.
+ */
+ describe('English login form 6 detection (password input named "passcode")', () => {
+ const htmlFile = 'en-login-form6.html';
+
+ testField(FormField.Password, 'input84', htmlFile);
+
+ it('should classify the clicked field as a password field, not TOTP', () => {
+ const dom = createTestDom(htmlFile);
+ const document = dom.window.document;
+
+ const passwordInput = document.getElementById('input84');
+ const formDetector = new FormDetector(document, passwordInput as HTMLElement);
+
+ expect(formDetector.getDetectedFieldType()).toBe(DetectedFieldType.Password);
+ });
+
+ it('should not detect a TOTP field in the form', () => {
+ const dom = createTestDom(htmlFile);
+ const document = dom.window.document;
+
+ const passwordInput = document.getElementById('input84');
+ const formDetector = new FormDetector(document, passwordInput as HTMLElement);
+ const form = formDetector.getForm();
+
+ expect(form?.passwordField?.id).toBe('input84');
+ expect(form?.totpField).toBeFalsy();
+ });
+ });
+
});
diff --git a/apps/browser-extension/src/utils/formDetector/__tests__/test-forms/en-login-form6.html b/apps/browser-extension/src/utils/formDetector/__tests__/test-forms/en-login-form6.html
new file mode 100644
index 000000000..ca5804d3e
--- /dev/null
+++ b/apps/browser-extension/src/utils/formDetector/__tests__/test-forms/en-login-form6.html
@@ -0,0 +1,38 @@
+<!--
+ Password step of a multi-step sign-in flow. The password input is named
+ "credentials.passcode" (a name also used for TOTP challenge inputs), so the
+ "passcode" term alone must not turn a type="password" field into a 2FA field.
+-->
+<html>
+ <body>
+ <form method="POST" action="/oauth2/v1/authorize" data-se="o-form" slot="content" id="form76" class="ion-form o-form o-form-edit-mode">
+ <div data-se="o-form-content" class="o-form-content o-form-theme clearfix">
+ <h2 data-se="o-form-head" class="form-title o-form-head" style="color: rgb(5, 5, 4);">Verify with your password</h2>
+ <div class="identifier-container no-overflow">
+ <span class="identifier no-translate mfa-selection-id" data-se="identifier" title="[email protected]">[email protected]</span>
+ <a data-se="cancel" href="#" class="link js-cancel mfa-selection-change-id">Change</a>
+ </div>
+ <div class="o-form-info-container"></div>
+ <div class="o-form-error-container" data-se="o-form-error-container" role="alert"></div>
+ <div class="o-form-fieldset-container" data-se="o-form-fieldset-container">
+ <div class="infobox infobox-error invalid-pw-error" role="alert" style="display: none;">
+ <span class="icon error-16"></span>
+ <p class="invalid-pw-error"><span class="pw-err-1">Oops! The entered password is invalid</span><span class="pw-err-2">Please check for typos </span><span class="pw-err-3">or refer to your notes. Have you recently changed your password?</span><span class="pw-err-sp"></span><span class="pw-err-4">You can also choose to </span><a data-se="switchAuthenticator" href="#" class="link js-switchAuthenticator custom-link">use another sign-in method</a><span class="pw-err-5"> or click </span><a data-se="forgot-password" href="#" class="link js-forgot-password custom-link">reset your password</a><span class="pw-err-6"> now.</span></p>
+ </div>
+ <div data-se="o-form-fieldset-credentials.passcode" class="o-form-fieldset o-form-label-top">
+ <div data-se="o-form-label" class="form-label o-form-label">
+ <label for="input84" style="font-size: 16px; line-height: 24px; font-weight: 700;">Password&nbsp;</label>
+ </div>
+ <div data-se="o-form-input-container" class="o-form-input">
+ <span data-se="o-form-input-credentials.passcode" class="o-form-input-name-credentials.passcode o-form-control form-input-field input-fix">
+ <input type="password" placeholder="" name="credentials.passcode" id="input84" value="" aria-label="" autocomplete="off" class="password-with-toggle">
+ <span class="password-toggle"><span class="eyeicon visibility-16 button-show"></span><span class="eyeicon visibility-off-16 button-hide"></span></span>
+ </span>
+ </div>
+ </div>
+ </div>
+ </div>
+ <div class="o-form-button-bar"><input class="button button-primary" type="submit" value="VERIFY" data-type="save"></div>
+ </form>
+ </body>
+</html>