From 42193aecb83c11eaddad7c25c5739f964febb255 Mon Sep 17 00:00:00 2001 From: Jonathan Prusik Date: Tue, 29 Aug 2023 09:10:16 -0400 Subject: [PATCH] [PM-1407] Improve iframe sandbox detection (#5976) * improve iframe sandbox detection * code cleanup Co-authored-by: Cesar Gonzalez * update autofill v1 logic as well --------- Co-authored-by: Cesar Gonzalez --- apps/browser/src/autofill/content/autofill.js | 12 ++++++++++-- apps/browser/src/autofill/content/autofillv2.ts | 10 +++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/apps/browser/src/autofill/content/autofill.js b/apps/browser/src/autofill/content/autofill.js index f6db33af97..1833c09e15 100644 --- a/apps/browser/src/autofill/content/autofill.js +++ b/apps/browser/src/autofill/content/autofill.js @@ -768,8 +768,16 @@ // Detect if within an iframe, and the iframe is sandboxed function isSandboxed() { - // self.origin is 'null' if inside a frame with sandboxed csp or iframe tag - return self.origin == null || self.origin === 'null'; + // self.origin is 'null' if inside a frame with sandboxed csp or iframe tag + if (String(self.origin).toLowerCase() === "null") { + return true; + } + + if (window.frameElement?.hasAttribute("sandbox")) { + return true; + } + + return location.hostname === ""; } function doFill(fillScript) { diff --git a/apps/browser/src/autofill/content/autofillv2.ts b/apps/browser/src/autofill/content/autofillv2.ts index 8bf16ff879..65813b3afe 100644 --- a/apps/browser/src/autofill/content/autofillv2.ts +++ b/apps/browser/src/autofill/content/autofillv2.ts @@ -849,7 +849,15 @@ function fill(document: Document, fillScript: AutofillScript) { // Detect if within an iframe, and the iframe is sandboxed function isSandboxed() { // self.origin is 'null' if inside a frame with sandboxed csp or iframe tag - return self.origin == null || self.origin === "null"; + if (String(self.origin).toLowerCase() === "null") { + return true; + } + + if (window.frameElement?.hasAttribute("sandbox")) { + return true; + } + + return location.hostname === ""; } function doFill(fillScript: AutofillScript) {