Skip to content

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

Add new FormDetector tests (#2270)

Leendert de Borst743f4c0187bb
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 3ed6c331a..2158a6247 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
@@ -327,6 +327,56 @@ describe('FormDetector English tests', () => {
});
});
+ /*
+ * Login form popup 1 detection.
+ */
+ describe('English login form popup 1 detection', () => {
+ const htmlFile = 'en-login-form-popup1.html';
+
+ testField(FormField.Email, 'Form_Email', htmlFile);
+ testField(FormField.Password, 'Form_Password', htmlFile);
+
+ it('should detect the popup form as a login form', () => {
+ const dom = createTestDom(htmlFile);
+ const document = dom.window.document;
+
+ const emailInput = document.getElementById('Form_Email');
+ const formDetector = new FormDetector(document, emailInput as HTMLElement);
+ expect(formDetector.containsLoginForm()).toBe(true);
+ });
+
+ it('should trigger autofill when clicking the Email/Username field', () => {
+ const dom = createTestDom(htmlFile);
+ const document = dom.window.document;
+
+ const emailInput = document.getElementById('Form_Email');
+ const formDetector = new FormDetector(document, emailInput as HTMLElement);
+ expect(formDetector.isAutofillTriggerableField()).toBe(true);
+ });
+
+ it('should trigger autofill when clicking the password field', () => {
+ const dom = createTestDom(htmlFile);
+ const document = dom.window.document;
+
+ const passwordInput = document.getElementById('Form_Password');
+ const formDetector = new FormDetector(document, passwordInput as HTMLElement);
+ expect(formDetector.isAutofillTriggerableField()).toBe(true);
+ });
+
+ it('should not autofill the hidden honeypot/system fields', () => {
+ const dom = createTestDom(htmlFile);
+ const document = dom.window.document;
+
+ const emailInput = document.getElementById('Form_Email');
+ const formDetector = new FormDetector(document, emailInput as HTMLElement);
+ const form = formDetector.getForm();
+
+ expect(form?.emailField?.id).toBe('Form_Email');
+ expect(form?.passwordField?.id).toBe('Form_Password');
+ expect(form?.usernameField?.id).not.toBe('Form_ClientHour');
+ });
+ });
+
/*
* Counterpart to the test above: when type="password" is (mis)used to mask
* an OTP/2FA input, the password detector must NOT classify it as a
diff --git a/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.exclusion.test.ts b/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.exclusion.test.ts
index e7b748be6..8980ad30a 100644
--- a/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.exclusion.test.ts
+++ b/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.exclusion.test.ts
@@ -79,6 +79,47 @@ describe('FormDetector - Field Exclusion Patterns', () => {
});
});
+ /*
+ * Exclusion words appearing in surrounding text (placeholder "Enter your configuration password")
+ * must not veto a field that carries explicit credential signals (type="password" / autocomplete="current-password").
+ */
+ describe('Real-world scenario: "Load Configuration" dialog with password field', () => {
+ const htmlFile = 'exclusion-config-password-dialog.html';
+
+ it('should detect the dialog as a login form despite "configuration" placeholders', () => {
+ const dom = createTestDom(htmlFile);
+ const document = dom.window.document;
+
+ const passwordInput = document.getElementById('password');
+ const formDetector = new FormDetector(document, passwordInput as HTMLElement);
+
+ expect(formDetector.containsLoginForm()).toBe(true);
+ });
+
+ it('should trigger autofill when clicking the type="password" field', () => {
+ const dom = createTestDom(htmlFile);
+ const document = dom.window.document;
+
+ const passwordInput = document.getElementById('password');
+ const formDetector = new FormDetector(document, passwordInput as HTMLElement);
+
+ expect(formDetector.isAutofillTriggerableField()).toBe(true);
+
+ const form = formDetector.getForm();
+ expect(form?.passwordField).toBe(passwordInput);
+ });
+
+ it('should detect the login form when focusing the UUID field too', () => {
+ const dom = createTestDom(htmlFile);
+ const document = dom.window.document;
+
+ const uuidInput = document.getElementById('uuid');
+ const formDetector = new FormDetector(document, uuidInput as HTMLElement);
+
+ expect(formDetector.containsLoginForm()).toBe(true);
+ });
+ });
+
describe('Exclusion patterns should not affect legitimate login fields', () => {
const htmlFile = 'exclusion-legitimate-login.html';
diff --git a/apps/browser-extension/src/utils/formDetector/__tests__/test-forms/en-login-form-popup1.html b/apps/browser-extension/src/utils/formDetector/__tests__/test-forms/en-login-form-popup1.html
new file mode 100644
index 000000000..b981ffd28
--- /dev/null
+++ b/apps/browser-extension/src/utils/formDetector/__tests__/test-forms/en-login-form-popup1.html
@@ -0,0 +1,56 @@
+<!DOCTYPE html>
+<html>
+<head><title>Sign In - Example Forum</title></head>
+<body>
+<!-- Full-page overlay: computed bottom goes far negative on long pages while remaining fully visible. -->
+<div class="Overlay" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: -5710px;">
+<div id="Popup" class="Popup SignInPopup" style="top: 92.1px; left: 0px;">
+ <div class="Border">
+ <div class="Body" style="max-height: 736.8px; overflow-y: auto;">
+ <div class="Content" style="display: block;">
+ <div class="FormTitleWrapper AjaxForm">
+ <h1>Sign In</h1>
+ <div class="FormWrapper">
+ <form id="Form_User_SignIn" method="post" action="/entry/signin">
+ <div>
+ <input type="hidden" id="Form_TransientKey" name="TransientKey" value="">
+ <input type="hidden" id="Form_hpt" name="hpt" value="" style="display: none;">
+ <input type="hidden" id="Form_Target" name="Target" value="/">
+ <input type="hidden" id="Form_ClientHour" name="ClientHour" value="2026-07-14 10:00">
+ <div class="Entry SingleEntryMethod">
+ <div class="MainForm">
+ <ul>
+ <li>
+ <label for="Form_Email">Email/Username</label>
+ <div class="TextBoxWrapper"><input type="text" id="Form_Email" name="Email" value="" autocorrect="off" autocapitalize="off" class="InputBox" autocomplete="off" data-av-autocomplete="off"></div>
+ </li>
+ <li>
+ <label for="Form_Password">Password</label>
+ <input type="password" id="Form_Password" name="Password" value="" class="InputBox Password" autocomplete="off" data-av-autocomplete="off"><a href="/entry/passwordrequest" class="ForgotPassword">Forgot?</a>
+ </li>
+ </ul>
+ </div>
+ </div>
+ <div class="Buttons">
+ <input type="submit" id="Form_SignIn" name="Sign In" class="Button Primary" value="Sign In">
+ <label for="SignInRememberMe" class="CheckBoxLabel"><input type="hidden" name="Checkboxes[]" value="RememberMe"><input type="checkbox" id="SignInRememberMe" name="RememberMe" value="1" checked="checked" class=""> Keep me signed in</label>
+ <div class="CreateAccount">
+ Don't have an account? <a href="/entry/register?Target=%2F">Create One.</a>
+ </div>
+ </div>
+ </div>
+ </form>
+ <div></div>
+ <div></div>
+ </div>
+ </div>
+ </div>
+ <div class="Footer" style="display: block;">
+ <a href="#" class="Close"><span>x</span></a>
+ </div>
+ </div>
+ </div>
+</div>
+</div>
+</body>
+</html>
diff --git a/apps/browser-extension/src/utils/formDetector/__tests__/test-forms/exclusion-config-password-dialog.html b/apps/browser-extension/src/utils/formDetector/__tests__/test-forms/exclusion-config-password-dialog.html
new file mode 100644
index 000000000..49433cb8a
--- /dev/null
+++ b/apps/browser-extension/src/utils/formDetector/__tests__/test-forms/exclusion-config-password-dialog.html
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<head><title>Load Configuration</title></head>
+<body>
+<!--
+ The password field is a genuine credential field (type="password",
+ autocomplete="current-password") and must not be vetoed by exclusion words.
+-->
+<div role="dialog" id="radix-_r_1a_" aria-describedby="radix-_r_1c_" aria-labelledby="radix-_r_1b_" data-state="open" class="UI-Modal__content" tabindex="-1" style="pointer-events: auto;">
+ <div class="UI-Modal__header">
+ <h2 id="radix-_r_1b_" class="UI-Modal__title">Load Configuration</h2>
+ </div>
+ <form class="space-y-4">
+ <div class="UI-BasicField__field">
+ <label for="uuid" class="UI-BasicField__fieldLabel" data-error="false">UUID<span class="UI-BasicField__fieldAsterisk">*</span></label>
+ <div class="UI-Input__inputContainer">
+ <input id="uuid" class="form-input UI-Input__root" data-disabled="false" data-readonly="false" aria-readonly="false" required="" placeholder="Enter your configuration UUID" value="" autocomplete="off" data-av-autocomplete="off">
+ </div>
+ </div>
+ <div class="UI-BasicField__field">
+ <label for="password" class="UI-BasicField__fieldLabel" data-error="false">Password<span class="UI-BasicField__fieldAsterisk">*</span></label>
+ <div class="UI-Input__inputContainer">
+ <div class="relative flex-1">
+ <input class="form-input UI-Input__root" data-disabled="false" data-readonly="false" aria-readonly="false" required="" placeholder="Enter your configuration password" id="password" autocapitalize="off" autocomplete="current-password" spellcheck="false" type="password" value="">
+ <button aria-controls="password" id="password" class="UI-ShowPassword" type="button" aria-label="Show password">eye</button>
+ </div>
+ </div>
+ </div>
+ <div class="flex justify-end gap-2">
+ <button type="button" class="UI-Button_root"><span>Cancel</span></button>
+ <button type="submit" class="UI-Button_root"><span>Load</span></button>
+ </div>
+ </form>
+ <button type="button" class="UI-Button_root UI-Modal__close"><span>x</span></button>
+</div>
+</body>
+</html>