From 4a9183adc51ea7535a4c870c60590f9197b293c2 Mon Sep 17 00:00:00 2001 From: Jeffrey Holland <124393578+jholland-livefront@users.noreply.github.com> Date: Fri, 26 Sep 2025 10:21:28 +0200 Subject: [PATCH] Allow autofilling iframes like samsclub.com (#16560) * Allow autofilling iframes like samsclub.com * Add back original checks * Remove unused mock --- .../insert-autofill-content.service.spec.ts | 4 +++- apps/browser/src/autofill/utils/index.ts | 23 +++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/apps/browser/src/autofill/services/insert-autofill-content.service.spec.ts b/apps/browser/src/autofill/services/insert-autofill-content.service.spec.ts index e36d6811ecb..9edcdbb3a95 100644 --- a/apps/browser/src/autofill/services/insert-autofill-content.service.spec.ts +++ b/apps/browser/src/autofill/services/insert-autofill-content.service.spec.ts @@ -153,7 +153,9 @@ describe("InsertAutofillContentService", () => { it("returns early if the script is filling within a sand boxed iframe", async () => { Object.defineProperty(globalThis, "frameElement", { - value: { hasAttribute: jest.fn(() => true) }, + value: { + getAttribute: jest.fn(() => ""), + }, writable: true, }); jest.spyOn(insertAutofillContentService as any, "userCancelledInsecureUrlAutofill"); diff --git a/apps/browser/src/autofill/utils/index.ts b/apps/browser/src/autofill/utils/index.ts index 0e102dcfd99..a3d61c7f0b2 100644 --- a/apps/browser/src/autofill/utils/index.ts +++ b/apps/browser/src/autofill/utils/index.ts @@ -499,11 +499,24 @@ export function isInvalidResponseStatusCode(statusCode: number) { * Determines if the current context is within a sandboxed iframe. */ export function currentlyInSandboxedIframe(): boolean { - return ( - String(self.origin).toLowerCase() === "null" || - globalThis.frameElement?.hasAttribute("sandbox") || - globalThis.location.hostname === "" - ); + if (String(self.origin).toLowerCase() === "null" || globalThis.location.hostname === "") { + return true; + } + + const sandbox = globalThis.frameElement?.getAttribute?.("sandbox"); + + // No frameElement or sandbox attribute means not sandboxed + if (sandbox === null || sandbox === undefined) { + return false; + } + + // An empty string means fully sandboxed + if (sandbox === "") { + return true; + } + + const tokens = new Set(sandbox.toLowerCase().split(" ")); + return !["allow-scripts", "allow-same-origin"].every((token) => tokens.has(token)); } /**