Skip to content

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

fix(extension): tighten autofill frame

AmarBegocebcab123565
diff --git a/apps/browser-extension/src/entrypoints/contentScript/AutofillFrameUrl.ts b/apps/browser-extension/src/entrypoints/contentScript/AutofillFrameUrl.ts
new file mode 100644
index 000000000..6f78a4da3
--- /dev/null
+++ b/apps/browser-extension/src/entrypoints/contentScript/AutofillFrameUrl.ts
@@ -0,0 +1,16 @@
+export type AutofillFrameLocation = Pick<Location, 'protocol' | 'hostname' | 'href'>;
+
+/**
+ * Return the current frame URL only when it represents a real web origin.
+ * AliasVault must not title-match credentials inside about/srcdoc/blob frames.
+ */
+export function getCurrentAutofillFrameUrl(currentLocation: AutofillFrameLocation = window.location): string | null {
+ if (
+ (currentLocation.protocol !== 'https:' && currentLocation.protocol !== 'http:') ||
+ !currentLocation.hostname
+ ) {
+ return null;
+ }
+
+ return currentLocation.href;
+}
diff --git a/apps/browser-extension/src/entrypoints/contentScript/Popup.ts b/apps/browser-extension/src/entrypoints/contentScript/Popup.ts
index 943a60023..92de8f747 100644
--- a/apps/browser-extension/src/entrypoints/contentScript/Popup.ts
+++ b/apps/browser-extension/src/entrypoints/contentScript/Popup.ts
@@ -17,6 +17,8 @@ import { SqliteClient } from '@/utils/SqliteClient';
import { t } from '@/i18n/StandaloneI18n';
+import { getCurrentAutofillFrameUrl } from './AutofillFrameUrl';
+
/**
* WeakMap to store event listeners for popup containers
*/
@@ -126,11 +128,18 @@ export function openAutofillPopup(input: HTMLInputElement, container: HTMLElemen
document.addEventListener('keydown', handleEnterKey);
(async () : Promise<void> => {
+ const currentUrl = getCurrentAutofillFrameUrl();
+ if (!currentUrl) {
+ removeExistingPopup(container);
+ document.removeEventListener('keydown', handleEnterKey);
+ return;
+ }
+
// Load autofill matching mode setting to send to background for filtering
const matchingMode = await LocalPreferencesService.getAutofillMatchingMode();
const response = await sendMessage('GET_FILTERED_ITEMS', {
- currentUrl: window.location.href,
+ currentUrl,
pageTitle: document.title,
matchingMode: matchingMode,
includeRecentlySelected: true // Enable for multi-step login autofill
@@ -177,10 +186,17 @@ export function openTotpPopup(input: HTMLInputElement, container: HTMLElement, f
document.addEventListener('keydown', handleEnterKey);
(async () : Promise<void> => {
+ const currentUrl = getCurrentAutofillFrameUrl();
+ if (!currentUrl) {
+ removeExistingPopup(container);
+ document.removeEventListener('keydown', handleEnterKey);
+ return;
+ }
+
const matchingMode = await LocalPreferencesService.getAutofillMatchingMode();
const response = await sendMessage('GET_ITEMS_WITH_TOTP', {
- currentUrl: window.location.href,
+ currentUrl,
pageTitle: document.title,
matchingMode: matchingMode
});
diff --git a/apps/browser-extension/src/entrypoints/contentScript/WebAuthnInterceptor.ts b/apps/browser-extension/src/entrypoints/contentScript/WebAuthnInterceptor.ts
index e94210059..14a55d9be 100644
--- a/apps/browser-extension/src/entrypoints/contentScript/WebAuthnInterceptor.ts
+++ b/apps/browser-extension/src/entrypoints/contentScript/WebAuthnInterceptor.ts
@@ -57,6 +57,29 @@ function isPageReadyForWebAuthn(): boolean {
return true;
}
+/**
+ * Check whether a frame has the same origin as every ancestor frame.
+ * Cross-origin iframe WebAuthn requires browser-level Permissions Policy checks,
+ * so AliasVault must fall back to native WebAuthn when any ancestor differs.
+ */
+export function isSameOriginWithAncestors(currentWindow: Window = window): boolean {
+ let frame: Window = currentWindow;
+ const expectedOrigin = currentWindow.location.origin;
+
+ while (frame !== frame.parent) {
+ try {
+ if (frame.parent.location.origin !== expectedOrigin) {
+ return false;
+ }
+ frame = frame.parent;
+ } catch {
+ return false;
+ }
+ }
+
+ return true;
+}
+
/**
* Initialize the WebAuthn interceptor
*/
@@ -99,6 +122,14 @@ export async function initializeWebAuthnInterceptor(_ctx: any): Promise<void> {
};
try {
+ if (!isSameOriginWithAncestors()) {
+ dispatchResponse({
+ requestId,
+ fallback: true
+ });
+ return;
+ }
+
if (!validateWebAuthnEventDetail('create', detail, window.location.origin, window.location.hostname)) {
dispatchResponse({
requestId,
@@ -191,6 +222,14 @@ export async function initializeWebAuthnInterceptor(_ctx: any): Promise<void> {
};
try {
+ if (!isSameOriginWithAncestors()) {
+ dispatchResponse({
+ requestId,
+ fallback: true
+ });
+ return;
+ }
+
if (!validateWebAuthnEventDetail('get', detail, window.location.origin, window.location.hostname)) {
dispatchResponse({
requestId,
diff --git a/apps/browser-extension/src/entrypoints/contentScript/__tests__/AutofillFrameUrl.test.ts b/apps/browser-extension/src/entrypoints/contentScript/__tests__/AutofillFrameUrl.test.ts
new file mode 100644
index 000000000..a4d36fe0f
--- /dev/null
+++ b/apps/browser-extension/src/entrypoints/contentScript/__tests__/AutofillFrameUrl.test.ts
@@ -0,0 +1,42 @@
+import { describe, expect, it } from 'vitest';
+
+import {
+ type AutofillFrameLocation,
+ getCurrentAutofillFrameUrl
+} from '../AutofillFrameUrl';
+
+/**
+ * Build the minimal Location shape used by the autofill frame URL guard.
+ */
+const frameLocation = (protocol: string, hostname: string, href: string): AutofillFrameLocation => ({
+ protocol,
+ hostname,
+ href,
+});
+
+describe('AutofillFrameUrl', () => {
+ it('allows http and https frame URLs with a hostname', () => {
+ expect(getCurrentAutofillFrameUrl(frameLocation(
+ 'https:',
+ 'login.example.com',
+ 'https://login.example.com/sign-in',
+ ))).toBe('https://login.example.com/sign-in');
+
+ expect(getCurrentAutofillFrameUrl(frameLocation(
+ 'http:',
+ 'localhost',
+ 'http://localhost:3000/login',
+ ))).toBe('http://localhost:3000/login');
+ });
+
+ it('rejects inherited or opaque non-web frame URLs', () => {
+ expect(getCurrentAutofillFrameUrl(frameLocation('about:', '', 'about:blank'))).toBeNull();
+ expect(getCurrentAutofillFrameUrl(frameLocation('about:', '', 'about:srcdoc'))).toBeNull();
+ expect(getCurrentAutofillFrameUrl(frameLocation('blob:', '', 'blob:https://attacker.example/id'))).toBeNull();
+ expect(getCurrentAutofillFrameUrl(frameLocation('data:', '', 'data:text/html,<input>'))).toBeNull();
+ });
+
+ it('rejects web protocols without a hostname', () => {
+ expect(getCurrentAutofillFrameUrl(frameLocation('https:', '', 'https://'))).toBeNull();
+ });
+});
diff --git a/apps/browser-extension/src/entrypoints/contentScript/__tests__/WebAuthnInterceptor.test.ts b/apps/browser-extension/src/entrypoints/contentScript/__tests__/WebAuthnInterceptor.test.ts
index ca680dde9..93846448b 100644
--- a/apps/browser-extension/src/entrypoints/contentScript/__tests__/WebAuthnInterceptor.test.ts
+++ b/apps/browser-extension/src/entrypoints/contentScript/__tests__/WebAuthnInterceptor.test.ts
@@ -8,7 +8,87 @@ import {
validateWebAuthnRequest
} from '@/utils/passkey/WebAuthnRequestValidation';
+import { isSameOriginWithAncestors } from '../WebAuthnInterceptor';
+
+type TestFrame = {
+ location: {
+ origin: string;
+ };
+ parent: TestFrame;
+};
+
+/**
+ * Create a minimal same-window/cross-window parent chain for ancestor checks.
+ */
+const createFrameChain = (origins: string[]): Window => {
+ const topFrame: TestFrame = {
+ location: {
+ origin: origins[origins.length - 1],
+ },
+ parent: undefined as unknown as TestFrame,
+ };
+ topFrame.parent = topFrame;
+
+ let frame = topFrame;
+ for (let index = origins.length - 2; index >= 0; index--) {
+ frame = {
+ location: {
+ origin: origins[index],
+ },
+ parent: frame,
+ };
+ }
+
+ return frame as unknown as Window;
+};
+
+/**
+ * Create a frame whose parent behaves like a browser cross-origin ancestor.
+ */
+const createFrameWithInaccessibleParent = (): Window => {
+ const inaccessibleParent: TestFrame = {
+ /**
+ * Simulate the DOMException thrown when reading a cross-origin location.
+ */
+ get location(): { origin: string } {
+ throw new Error('Permission denied');
+ },
+ parent: undefined as unknown as TestFrame,
+ };
+ inaccessibleParent.parent = inaccessibleParent;
+
+ return {
+ location: {
+ origin: 'https://login.example.com',
+ },
+ parent: inaccessibleParent,
+ } as unknown as Window;
+};
+
describe('WebAuthnInterceptor request validation', () => {
+ it('allows WebAuthn interception in a top-level frame', () => {
+ expect(isSameOriginWithAncestors(createFrameChain(['https://login.example.com']))).toBe(true);
+ });
+
+ it('allows WebAuthn interception in same-origin nested frames', () => {
+ expect(isSameOriginWithAncestors(createFrameChain([
+ 'https://login.example.com',
+ 'https://login.example.com',
+ 'https://login.example.com',
+ ]))).toBe(true);
+ });
+
+ it('rejects WebAuthn interception in cross-origin ancestor frames', () => {
+ expect(isSameOriginWithAncestors(createFrameChain([
+ 'https://login.example.com',
+ 'https://attacker.example.com',
+ ]))).toBe(false);
+ });
+
+ it('rejects WebAuthn interception when an ancestor origin cannot be read', () => {
+ expect(isSameOriginWithAncestors(createFrameWithInaccessibleParent())).toBe(false);
+ });
+
it('allows exact RP ID matches', () => {
expect(isRpIdAllowedForHost('example.com', 'example.com')).toBe(true);
});