From e9800f38bf19e05116c68f32b2e77bbd5085fcdd Mon Sep 17 00:00:00 2001 From: velzie Date: Mon, 14 Oct 2024 10:48:25 -0400 Subject: [PATCH] window.frameElement trap --- src/client/dom/open.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/client/dom/open.ts b/src/client/dom/open.ts index ef6d3c2..4a4dd38 100644 --- a/src/client/dom/open.ts +++ b/src/client/dom/open.ts @@ -39,4 +39,20 @@ export default function (client: ScramjetClient) { } }, }); + + client.Trap("window.frameElement", { + get(ctx) { + const f = ctx.get() as HTMLIFrameElement | null; + if (!f) return f; + + const win = f.ownerDocument.defaultView; + if (win[SCRAMJETCLIENT]) { + // then this is a subframe in a scramjet context, and it's safe to pass back the real iframe + return f; + } else { + // no, the top frame is outside the sandbox + return null; + } + }, + }); }