Skip to content

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

Add more tests and update logic (#1788)

Leendert de Borst7fd33ac2f486
diff --git a/apps/browser-extension/src/entrypoints/contentScript/Form.ts b/apps/browser-extension/src/entrypoints/contentScript/Form.ts
index fbf60179d..04b3950cb 100644
--- a/apps/browser-extension/src/entrypoints/contentScript/Form.ts
+++ b/apps/browser-extension/src/entrypoints/contentScript/Form.ts
@@ -189,6 +189,21 @@ export function injectIcon(input: HTMLInputElement, container: HTMLElement): voi
// Find the actual input element to use for positioning
const actualInput = findActualInput(input);
+ /*
+ * Skip icon for split TOTP inputs (single-digit fields)
+ * These are too narrow to show the icon nicely
+ */
+ const inputMode = actualInput.getAttribute('inputmode');
+ const pattern = actualInput.getAttribute('pattern');
+ const isNumericSingleDigit = actualInput.maxLength === 1 &&
+ (inputMode === 'numeric' ||
+ pattern === '[0-9]*' ||
+ pattern === '\\d*');
+
+ if (isNumericSingleDigit) {
+ return;
+ }
+
const ICON_HTML = `
<div class="av-input-icon">
<img src="data:image/svg+xml;base64,${btoa(LOGO_MARK_SVG)}" style="width: 100%; height: 100%;" />
diff --git a/apps/browser-extension/src/utils/formDetector/FieldPatterns.ts b/apps/browser-extension/src/utils/formDetector/FieldPatterns.ts
index 3152690c5..2631feef3 100644
--- a/apps/browser-extension/src/utils/formDetector/FieldPatterns.ts
+++ b/apps/browser-extension/src/utils/formDetector/FieldPatterns.ts
@@ -37,14 +37,11 @@ export type DateOptionPatterns = {
/**
* Type for email verification context patterns. These patterns are used to detect if a form
* is for email verification (not TOTP/2FA). Each pattern should detect common phrases
- * found in email verification flows.
+ * found in email verification flows (specifically in links/buttons).
*/
export type EmailVerificationPatterns = {
- verifyEmail: RegExp[];
- emailVerification: RegExp[];
- sentCodeToEmail: RegExp[];
- checkEmail: RegExp[];
- confirmEmail: RegExp[];
+ resendCode: RegExp[];
+ changeEmail: RegExp[];
}
/**
@@ -86,34 +83,20 @@ export const EnglishDateOptionPatterns: DateOptionPatterns = {
/**
* English email verification patterns. These are used to detect email verification forms
- * (not TOTP/2FA forms) by analyzing page content.
+ * (not TOTP/2FA forms) by analyzing link/button text in the form context.
*/
export const EnglishEmailVerificationPatterns: EmailVerificationPatterns = {
- verifyEmail: [
- /verify\s+your\s+email/i,
- /verify\s+email\s+address/i,
- /email\s+needs\s+verification/i
+ resendCode: [
+ /resend/i,
+ /re-send/i,
+ /send\s+again/i,
+ /send\s+code\s+again/i
],
- emailVerification: [
- /email\s+verification/i,
- /verification\s+email/i
- ],
- sentCodeToEmail: [
- /we\s+sent\s+(a\s+)?code\s+to.*@/i,
- /sent\s+(a\s+)?(verification\s+)?code\s+to.*@/i,
- /enter\s+the\s+code\s+we\s+sent\s+to.*@/i,
- /code\s+has\s+been\s+sent\s+to.*@/i,
- /we've\s+sent\s+(a\s+)?code\s+to.*@/i
- ],
- checkEmail: [
- /check\s+your\s+email/i,
- /check\s+your\s+inbox/i,
- /please\s+check\s+your\s+email/i
- ],
- confirmEmail: [
- /confirm\s+your\s+email/i,
- /email\s+confirmation/i,
- /confirm\s+email\s+address/i
+ changeEmail: [
+ /different\s+email/i,
+ /change\s+email/i,
+ /update\s+email/i,
+ /use\s+another\s+email/i
]
};
@@ -195,33 +178,20 @@ export const DutchDateOptionPatterns: DateOptionPatterns = {
/**
* Dutch email verification patterns. These are used to detect email verification forms
- * (not TOTP/2FA forms) by analyzing page content.
+ * (not TOTP/2FA forms) by analyzing link/button text in the form context.
*/
export const DutchEmailVerificationPatterns: EmailVerificationPatterns = {
- verifyEmail: [
- /verifieer\s+je\s+e-?mail/i,
- /e-?mail\s+verifi[eë]ren/i,
- /controleer\s+je\s+e-?mail/i
- ],
- emailVerification: [
- /e-?mail\s+verificatie/i,
- /verificatie\s+e-?mail/i
- ],
- sentCodeToEmail: [
- /we\s+hebben\s+(een\s+)?code\s+gestuurd\s+naar.*@/i,
- /(een\s+)?code\s+verzonden\s+naar.*@/i,
- /voer\s+de\s+code\s+in\s+die\s+we\s+naar.*@\s+hebben\s+gestuurd/i,
- /code\s+is\s+verzonden\s+naar.*@/i
+ resendCode: [
+ /opnieuw\s+verzenden/i,
+ /verstuur\s+opnieuw/i,
+ /code\s+opnieuw/i,
+ /opnieuw\s+versturen/i
],
- checkEmail: [
- /controleer\s+je\s+e-?mail/i,
- /bekijk\s+je\s+inbox/i,
- /controleer\s+je\s+inbox/i
- ],
- confirmEmail: [
- /bevestig\s+je\s+e-?mail/i,
- /e-?mail\s+bevestiging/i,
- /bevestig\s+e-?mailadres/i
+ changeEmail: [
+ /ander\s+e-?mail/i,
+ /wijzig\s+e-?mail/i,
+ /e-?mail\s+wijzigen/i,
+ /ander\s+e-?mailadres/i
]
};
@@ -321,27 +291,15 @@ export const CombinedStopWords = new Set([
/**
* Combined email verification patterns from all supported languages. These are used to detect
- * email verification forms (not TOTP/2FA forms) by analyzing page content.
+ * email verification forms (not TOTP/2FA forms) by analyzing link/button text in the form context.
*/
export const CombinedEmailVerificationPatterns: EmailVerificationPatterns = {
- verifyEmail: [
- ...EnglishEmailVerificationPatterns.verifyEmail,
- ...DutchEmailVerificationPatterns.verifyEmail
- ],
- emailVerification: [
- ...EnglishEmailVerificationPatterns.emailVerification,
- ...DutchEmailVerificationPatterns.emailVerification
- ],
- sentCodeToEmail: [
- ...EnglishEmailVerificationPatterns.sentCodeToEmail,
- ...DutchEmailVerificationPatterns.sentCodeToEmail
- ],
- checkEmail: [
- ...EnglishEmailVerificationPatterns.checkEmail,
- ...DutchEmailVerificationPatterns.checkEmail
+ resendCode: [
+ ...EnglishEmailVerificationPatterns.resendCode,
+ ...DutchEmailVerificationPatterns.resendCode
],
- confirmEmail: [
- ...EnglishEmailVerificationPatterns.confirmEmail,
- ...DutchEmailVerificationPatterns.confirmEmail
+ changeEmail: [
+ ...EnglishEmailVerificationPatterns.changeEmail,
+ ...DutchEmailVerificationPatterns.changeEmail
]
};
diff --git a/apps/browser-extension/src/utils/formDetector/FormDetector.ts b/apps/browser-extension/src/utils/formDetector/FormDetector.ts
index 77ab24be3..114155917 100644
--- a/apps/browser-extension/src/utils/formDetector/FormDetector.ts
+++ b/apps/browser-extension/src/utils/formDetector/FormDetector.ts
@@ -1008,32 +1008,65 @@ export class FormDetector {
}
/**
- * Check if the page content indicates this is an email verification form.
+ * Check if the form context indicates this is an email verification form.
* Email verification forms should not be treated as TOTP/2FA forms.
- * Uses language-aware patterns to support multiple languages.
+ *
+ * This method uses localized heuristics to avoid false positives from unrelated page content.
+ * It looks for specific patterns that distinguish email verification from TOTP/2FA authentication.
*/
private isEmailVerificationForm(): boolean {
- // Get page text content for context analysis
- const bodyText = this.document.body?.textContent || '';
- const pageTitle = this.document.title || '';
-
- // Combine all language-aware email verification patterns
- const allPatterns = [
- ...CombinedEmailVerificationPatterns.verifyEmail,
- ...CombinedEmailVerificationPatterns.emailVerification,
- ...CombinedEmailVerificationPatterns.sentCodeToEmail,
- ...CombinedEmailVerificationPatterns.checkEmail,
- ...CombinedEmailVerificationPatterns.confirmEmail
- ];
-
- // Check if any email verification pattern matches
- for (const pattern of allPatterns) {
- if (pattern.test(bodyText) || pattern.test(pageTitle)) {
- return true;
+ if (!this.clickedElement) {
+ return false;
+ }
+
+ /*
+ * Search upward from the clicked element to find visible text and links
+ * This gives us a localized context without needing to scan the entire page
+ */
+ let searchRoot: HTMLElement = this.clickedElement;
+ let depth = 0;
+
+ // Go up to find a reasonable container (max 15 levels)
+ while (searchRoot.parentElement && depth < 15) {
+ searchRoot = searchRoot.parentElement;
+ depth++;
+
+ // Stop if we found a form, dialog, or main container
+ if (searchRoot.tagName === 'FORM' ||
+ searchRoot.getAttribute('role') === 'dialog' ||
+ searchRoot.tagName === 'MAIN' ||
+ searchRoot.id ||
+ searchRoot.className.includes('container')) {
+ break;
}
}
- return false;
+ // Get text content and links from this localized area
+ const contextText = searchRoot.textContent || '';
+ const links = Array.from(searchRoot.querySelectorAll('a, button'));
+ const linkTexts = links.map(link => link.textContent?.toLowerCase() || '');
+ const allLinkText = linkTexts.join(' ');
+
+ /*
+ * Check for email address pattern (including masked like "user@***.com")
+ * Email verification forms typically display the email address
+ * Pattern: something @ something . something (allows masked emails with asterisks)
+ */
+ const hasEmailPattern = /[a-z0-9*.\-_]+@[a-z0-9*.-]+\.[a-z*]{2,}/i.test(contextText);
+
+ if (!hasEmailPattern) {
+ // No email shown = not email verification
+ return false;
+ }
+
+ // Check for "resend code" links using language-aware patterns (common in email verification, rare in TOTP)
+ const hasResend = CombinedEmailVerificationPatterns.resendCode.some(pattern => pattern.test(allLinkText));
+
+ // Check for "change/update email" options using language-aware patterns
+ const hasChangeEmail = CombinedEmailVerificationPatterns.changeEmail.some(pattern => pattern.test(allLinkText));
+
+ // Email verification = shows email AND has resend OR change email option
+ return hasEmailPattern && (hasResend || hasChangeEmail);
}
/**
diff --git a/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.totp.test.ts b/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.totp.test.ts
index 9ce4039b5..0f2962f2f 100644
--- a/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.totp.test.ts
+++ b/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.totp.test.ts
@@ -1,9 +1,11 @@
-import { JSDOM } from 'jsdom';
-import { describe, expect, it } from 'vitest';
import { readFileSync } from 'fs';
import { join } from 'path';
+import { JSDOM } from 'jsdom';
+import { describe, expect, it } from 'vitest';
+
import { FormDetector } from '@/utils/formDetector/FormDetector';
+
import { FormField, testField } from './TestUtils';
describe('FormDetector TOTP tests', () => {
@@ -80,8 +82,10 @@ describe('FormDetector TOTP tests', () => {
const formDetector = new FormDetector(document, focusedElement);
const result = formDetector.getForm();
- // The form should NOT be detected at all (null) or at least totpField should be null
- // because this is an email verification form, not a TOTP/2FA form
+ /*
+ * The form should NOT be detected at all (null) or at least totpField should be null
+ * because this is an email verification form, not a TOTP/2FA form
+ */
expect(result?.totpField).toBeNull();
});
@@ -108,5 +112,33 @@ describe('FormDetector TOTP tests', () => {
// The form should NOT be detected as TOTP because it's a Dutch email verification form
expect(result?.totpField).toBeNull();
});
+
+ it('should NOT detect Riot Games email code form as TOTP', () => {
+ const htmlFile = 'en-email-verification-form2.html';
+ const html = readFileSync(join(__dirname, 'test-forms', htmlFile), 'utf-8');
+ const dom = new JSDOM(html, {
+ url: 'http://localhost',
+ runScripts: 'dangerously',
+ resources: 'usable'
+ });
+ const document = dom.window.document;
+
+ // Set focus on the first input
+ const focusedElement = document.getElementById('email-code-0');
+ if (!focusedElement) {
+ throw new Error('Focus element not found in test HTML');
+ }
+
+ // Create a new form detector with the focused element
+ const formDetector = new FormDetector(document, focusedElement);
+ const result = formDetector.getForm();
+
+ /*
+ * The form should NOT be detected as TOTP because it's an email code verification form
+ * Even though it says "Verification Required", the text "code we've emailed to" and
+ * "Resend code" link indicate it's email verification, not authenticator TOTP
+ */
+ expect(result?.totpField).toBeNull();
+ });
});
});
diff --git a/apps/browser-extension/src/utils/formDetector/__tests__/test-forms/en-email-verification-form2.html b/apps/browser-extension/src/utils/formDetector/__tests__/test-forms/en-email-verification-form2.html
new file mode 100644
index 000000000..98de4de05
--- /dev/null
+++ b/apps/browser-extension/src/utils/formDetector/__tests__/test-forms/en-email-verification-form2.html
@@ -0,0 +1,74 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Verification Required - Riot Games</title>
+</head>
+<body>
+ <div data-testid="multifactor">
+ <div class="sc-bYOEQd fZKKpq main-background theme-arcane">
+ <h5 class="sc-kFuwaP iNZiaL sc-eFqGBh iXlzYU" color="black" dir="ltr">Verification Required</h5>
+ <h6 data-testid="subtitle" class="sc-kFuwaP kPTutl sc-crPCXo lpqVFG" color="black" dir="ltr">Enter the code we've emailed to ma-**@****.net</h6>
+ <div class="sc-dExYQz eUYAKH">
+ <div class="sc-bOSxlg eRqoVn">
+ <div class="sc-fmSAUk dbLWZE">
+ <div class="sc-cbelXg gGiXFv">
+ <div class="sc-ktEKTO sc-jegxcv fApNkr dUizNf field">
+ <input minlength="1" maxlength="1" type="text" id="email-code-0" lang="en" autocomplete="off" pattern="\d*" inputmode="numeric" value="" data-av-autocomplete="off">
+ </div>
+ <div class="sc-ktEKTO sc-jegxcv fApNkr dUizNf field">
+ <input minlength="1" maxlength="1" type="text" id="email-code-1" lang="en" autocomplete="off" pattern="\d*" inputmode="numeric" value="">
+ </div>
+ <div class="sc-ktEKTO sc-jegxcv fApNkr dUizNf field">
+ <input minlength="1" maxlength="1" type="text" id="email-code-2" lang="en" autocomplete="off" pattern="\d*" inputmode="numeric" value="">
+ </div>
+ <div class="sc-ktEKTO sc-jegxcv fApNkr dUizNf field">
+ <input minlength="1" maxlength="1" type="text" id="email-code-3" lang="en" autocomplete="off" pattern="\d*" inputmode="numeric" value="">
+ </div>
+ <div class="sc-ktEKTO sc-jegxcv fApNkr dUizNf field">
+ <input minlength="1" maxlength="1" type="text" id="email-code-4" lang="en" autocomplete="off" pattern="\d*" inputmode="numeric" value="">
+ </div>
+ <div class="sc-ktEKTO sc-jegxcv fApNkr dUizNf field">
+ <input minlength="1" maxlength="1" type="text" id="email-code-5" lang="en" autocomplete="off" pattern="\d*" inputmode="numeric" value="">
+ </div>
+ </div>
+ </div>
+ </div>
+ <div method="email" data-testid="mfa-rememberme-checkbox" class="sc-dXoxLi yIfkA">
+ <div class="sc-blLsxD fZODXg">
+ <div class="sc-fmSAUk dBSvZD CheckboxField">
+ <div class="sc-ktEKTO jyJJXs field">
+ <input id="rememberme" type="checkbox">
+ <svg role="img" viewBox="0 0 19 19" xmlns="http://www.w3.org/2000/svg" aria-label="checkmark" class="sc-hLseeU eHCXYC sc-fGFwAa iUwPLm">
+ <path d="M1.84791 10.5854L8.17372 16.5999L17.2764 5.99613" stroke-linejoin="round"></path>
+ </svg>
+ <label></label>
+ <span dir="ltr"></span>
+ </div>
+ </div>
+ <h6 class="sc-kFuwaP kPTutl sc-ieZDjg gkdjQh" color="black" dir="ltr">
+ <label for="rememberme">Remember this browser for 30 days</label>
+ </h6>
+ </div>
+ </div>
+ <div class="sc-bqWVmG hsXpWG">
+ <button disabled="" data-testid="btn-mfa-submit" class="sc-eDDNvR joBTcU">
+ <div class="sc-gLDzan gohLCB">
+ <svg role="img" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg" aria-label="forward" class="sc-hLseeU idnFbI sc-iAEyYk kOjeBb">
+ <path d="M22.8011 14.75L14.2234 6.70971L16.0474 5L26.8695 15.1441C27.3732 15.6163 27.3732 16.3817 26.8695 16.8538L16.0474 26.998L14.2234 25.2883L22.7989 17.25H4.75V14.75H22.8011Z"></path>
+ </svg>
+ </div>
+ </button>
+ </div>
+ <div class="sc-jFJHMl ilTSQE">
+ <span color="gray.12-alpha.60" class="sc-kFuwaP jNFYyC" dir="ltr">
+ <a href="#" class="sc-qRumB fKscrR">Resend code</a>
+ </span>
+ <span color="black" class="sc-kFuwaP dYvDdY" dir="ltr">
+ <a data-testid="mfa-faq" href="https://support-wildrift.riotgames.com/hc/en/articles/4415717099027" target="_blank" rel="noreferrer noopener" class="sc-qRumB fKscrR">No longer have access to that email?</a>
+ </span>
+ </div>
+ </div>
+ </div>
+ </div>
+</body>
+</html>