Skip to content

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

Update formdetector logic for 2FA entra ID fields (#1756)

Leendert de Borst3f961f26af99
diff --git a/apps/browser-extension/src/utils/formDetector/FormDetector.ts b/apps/browser-extension/src/utils/formDetector/FormDetector.ts
index 583064df7..ffe0ace35 100644
--- a/apps/browser-extension/src/utils/formDetector/FormDetector.ts
+++ b/apps/browser-extension/src/utils/formDetector/FormDetector.ts
@@ -977,6 +977,12 @@ export class FormDetector {
return input;
}
+ // Check for type="tel" with maxLength=6 (common for 2FA codes like Entra ID)
+ const inputType = input.type?.toLowerCase();
+ if (inputType === 'tel' && maxLength === 6) {
+ return input;
+ }
+
// Check for numeric pattern attribute with length constraint
const pattern = input.getAttribute('pattern');
if (pattern && /^\[0-9\]/.test(pattern) && maxLength === 6) {
diff --git a/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.entra-id-2fa.test.ts b/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.entra-id-2fa.test.ts
new file mode 100644
index 000000000..a11c48e12
--- /dev/null
+++ b/apps/browser-extension/src/utils/formDetector/__tests__/FormDetector.entra-id-2fa.test.ts
@@ -0,0 +1,88 @@
+import { beforeEach, describe, expect, it } from 'vitest';
+
+import { FormDetector } from '../FormDetector';
+import { DetectedFieldType } from '../types/FormFields';
+
+import { createTestDom } from './TestUtils';
+
+describe('FormDetector - Microsoft Entra ID 2FA', () => {
+ const htmlFile = 'entra-id-2fa.html';
+ let document: Document;
+ let formDetector: FormDetector;
+
+ beforeEach(() => {
+ const dom = createTestDom(htmlFile);
+ document = dom.window.document;
+ });
+
+ describe('TOTP field detection', () => {
+ it('should detect the 2FA code input field as TOTP', () => {
+ const totpInput = document.getElementById('idTxtBx_SAOTCC_OTC') as HTMLInputElement;
+ expect(totpInput).toBeTruthy();
+
+ formDetector = new FormDetector(document, totpInput);
+
+ const detectedType = formDetector.getDetectedFieldType();
+ expect(detectedType).toBe(DetectedFieldType.Totp);
+ });
+
+ it('should find the TOTP field when searching from form', () => {
+ formDetector = new FormDetector(document, document.body);
+
+ const totpField = formDetector.findTotpField();
+ expect(totpField).toBeTruthy();
+ expect(totpField?.id).toBe('idTxtBx_SAOTCC_OTC');
+ });
+
+ it('should detect TOTP field with maxlength=6', () => {
+ const totpInput = document.getElementById('idTxtBx_SAOTCC_OTC') as HTMLInputElement;
+ expect(totpInput.maxLength).toBe(6);
+ expect(totpInput.type).toBe('tel');
+ });
+
+ it('should recognize form contains login fields for TOTP', () => {
+ formDetector = new FormDetector(document, document.body);
+
+ const containsLogin = formDetector.containsLoginForm();
+ expect(containsLogin).toBe(true);
+ });
+ });
+
+ describe('Form structure', () => {
+ it('should find hidden mfaAuthMethod input', () => {
+ const mfaMethod = document.querySelector('input[name="mfaAuthMethod"]') as HTMLInputElement;
+ expect(mfaMethod).toBeTruthy();
+ expect(mfaMethod.value).toBe('PhoneAppOTP');
+ });
+
+ it('should find the submit button', () => {
+ const submitBtn = document.getElementById('idSubmit_SAOTCC_Continue') as HTMLInputElement;
+ expect(submitBtn).toBeTruthy();
+ expect(submitBtn.type).toBe('submit');
+ expect(submitBtn.value).toBe('Verify');
+ });
+
+ it('should detect aria-label for accessibility', () => {
+ const totpInput = document.getElementById('idTxtBx_SAOTCC_OTC') as HTMLInputElement;
+ expect(totpInput.getAttribute('aria-label')).toBe('Code');
+ });
+ });
+
+ describe('TOTP field attributes', () => {
+ it('should have autocomplete disabled', () => {
+ const totpInput = document.getElementById('idTxtBx_SAOTCC_OTC') as HTMLInputElement;
+ expect(totpInput.autocomplete).toBe('off');
+ });
+
+ it('should be marked as required', () => {
+ const totpInput = document.getElementById('idTxtBx_SAOTCC_OTC') as HTMLInputElement;
+ expect(totpInput.getAttribute('aria-required')).toBe('true');
+ });
+
+ it('should have proper ARIA descriptions', () => {
+ const totpInput = document.getElementById('idTxtBx_SAOTCC_OTC') as HTMLInputElement;
+ const describedBy = totpInput.getAttribute('aria-describedby');
+ expect(describedBy).toContain('idDiv_SAOTCC_Description');
+ });
+ });
+});
diff --git a/apps/browser-extension/src/utils/formDetector/__tests__/test-forms/entra-id-2fa.html b/apps/browser-extension/src/utils/formDetector/__tests__/test-forms/entra-id-2fa.html
new file mode 100644
index 000000000..73f6b97eb
--- /dev/null
+++ b/apps/browser-extension/src/utils/formDetector/__tests__/test-forms/entra-id-2fa.html
@@ -0,0 +1,76 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Microsoft Entra ID - 2FA Code Entry</title>
+</head>
+<body>
+ <div id="lightbox" class="sign-in-box">
+ <div class="lightbox-cover"></div>
+
+ <div>
+ <div class="identityBanner">
+ <div id="displayName" class="identity" title="[email protected]">[email protected]</div>
+ </div>
+
+ <div class="pagination-view animate has-identity-banner">
+ <div data-viewid="1">
+ <input type="hidden" name="type" value="19">
+ <input type="hidden" name="GeneralVerify" value="false">
+ <input type="hidden" name="request" value="[redacted]">
+ <input type="hidden" name="mfaLastPollStart" value="1771596350142">
+ <input type="hidden" name="mfaLastPollEnd" value="1771596350326">
+ <input type="hidden" name="mfaAuthMethod" value="PhoneAppOTP">
+
+ <div id="idDiv_SAOTCC_Title" class="row text-title" role="heading" aria-level="1">Enter code</div>
+
+ <div class="row text-body">
+ <div id="idDiv_SAOTCC_Description" class="text-block-body overflow-hidden">
+ Enter the code displayed in the authenticator app on your mobile device
+ </div>
+ </div>
+
+ <div class="text-block-body">
+ <div id="idDiv_SAOTCC_OTCRow" class="form-group">
+ <div role="alert" aria-live="assertive"></div>
+ <div id="idDiv_SAOTCC_Success_OTC" class="errorDiv" style="display: none;">
+ <span id="idSpan_SAOTCC_Success_OTC" class="success"></span>
+ </div>
+
+ <div id="idDiv_SAOTCC_OTC" class="textbox form-group">
+ <div class="placeholderContainer">
+ <input
+ id="idTxtBx_SAOTCC_OTC"
+ name="otc"
+ class="form-control"
+ type="tel"
+ autocomplete="off"
+ aria-required="true"
+ maxlength="6"
+ aria-labelledby="idDiv_SAOTCC_Title"
+ aria-describedby="idDiv_SAOTCS_Title idDiv_SAOTCC_Description idSpan_SAOTCC_Error_OTC"
+ aria-label="Code"
+ placeholder="Code">
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <div class="win-button-pin-bottom">
+ <div class="row">
+ <div class="button-container">
+ <input type="button" id="idBtn_Back" class="win-button button-secondary" value="Cancel">
+ <input type="submit" id="idSubmit_SAOTCC_Continue" class="win-button button_primary" value="Verify">
+ </div>
+ </div>
+ </div>
+
+ <input type="hidden" name="login" value="[email protected]">
+ <input type="hidden" name="flowToken" value="[redacted]">
+ <input type="hidden" name="hpgrequestid" value="[redacted]">
+ <input type="hidden" name="canary" value="[redacted]">
+ </div>
+ </div>
+ </div>
+ </div>
+</body>
+</html>