File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,6 +20,8 @@ if (!document.referrer.match(ALLOWED_REFERRER_PATTERN)) {
2020// This is the origin we expect all parent messages to come from.
2121const EXPECTED_HOST_ORIGIN = new URL ( document . referrer ) . origin ;
2222
23+ const OWN_ORIGIN = new URL ( window . location . href ) . origin ;
24+
2325// Security self-test: verify iframe isolation is working correctly.
2426// This MUST throw a SecurityError -- if `window.top` is accessible, the sandbox
2527// configuration is dangerously broken and untrusted content could escape.
@@ -126,6 +128,15 @@ window.addEventListener("message", async (event) => {
126128 }
127129 }
128130 } else if ( event . source === inner . contentWindow ) {
131+ if ( event . origin !== OWN_ORIGIN ) {
132+ console . error (
133+ "[Sandbox] Rejecting message from inner iframe with unexpected origin:" ,
134+ event . origin ,
135+ "expected:" ,
136+ OWN_ORIGIN
137+ ) ;
138+ return ;
139+ }
129140 // Relay messages from inner frame to parent window.
130141 // Use specific origin instead of "*" to prevent message interception.
131142 window . parent . postMessage ( event . data , EXPECTED_HOST_ORIGIN ) ;
You can’t perform that action at this time.
0 commit comments