From 6a6dbfa16555b2916db49db351bf276c4409159b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Wed, 21 Oct 2026 13:39:36 +0200 Subject: [PATCH 1/6] [Website] Keep database tools in the app browser partition --- .../remote/src/lib/wordpress-popup.ts | 14 ++++++ packages/playground/remote/vite.config.ts | 1 + .../playground/remote/wordpress-popup.html | 28 ++++++++++++ .../tools/src/phpmyadmin/config.inc.php | 5 +++ .../website/playwright/e2e/website-ui.spec.ts | 45 ++++++++++++------- .../site-database-panel/adminer-button.tsx | 5 ++- .../site-database-panel/phpmyadmin-button.tsx | 7 ++- .../website/src/lib/wordpress-popup.spec.ts | 30 +++++++++++++ .../website/src/lib/wordpress-popup.ts | 14 ++++++ 9 files changed, 132 insertions(+), 17 deletions(-) create mode 100644 packages/playground/remote/src/lib/wordpress-popup.ts create mode 100644 packages/playground/remote/wordpress-popup.html create mode 100644 packages/playground/website/src/lib/wordpress-popup.spec.ts create mode 100644 packages/playground/website/src/lib/wordpress-popup.ts diff --git a/packages/playground/remote/src/lib/wordpress-popup.ts b/packages/playground/remote/src/lib/wordpress-popup.ts new file mode 100644 index 00000000000..cbfde99539c --- /dev/null +++ b/packages/playground/remote/src/lib/wordpress-popup.ts @@ -0,0 +1,14 @@ +import { getURLScope } from '@php-wasm/scopes'; +import { wordPressSiteUrl } from './config'; + +/** Keep popup WordPress in the app's service-worker partition without exposing app documents. */ +function bootWordPressPopup() { + const target = new URL(location.hash.substring(1), wordPressSiteUrl); + if (target.origin !== wordPressSiteUrl || !getURLScope(target)) { + throw new Error('The popup URL must name a scoped WordPress page.'); + } + const frame = document.querySelector('#wp') as HTMLIFrameElement; + frame.src = target.href; +} + +bootWordPressPopup(); diff --git a/packages/playground/remote/vite.config.ts b/packages/playground/remote/vite.config.ts index acea589ba49..b0055a7f49a 100644 --- a/packages/playground/remote/vite.config.ts +++ b/packages/playground/remote/vite.config.ts @@ -195,6 +195,7 @@ export default defineConfig(({ mode }) => { rollupOptions: { input: { wordpress: path('/remote.html'), + 'wordpress-popup': path('/wordpress-popup.html'), }, output: { assetFileNames: (chunkInfo) => { diff --git a/packages/playground/remote/wordpress-popup.html b/packages/playground/remote/wordpress-popup.html new file mode 100644 index 00000000000..546a666d93b --- /dev/null +++ b/packages/playground/remote/wordpress-popup.html @@ -0,0 +1,28 @@ + + + + WordPress Playground + + + + + + + diff --git a/packages/playground/tools/src/phpmyadmin/config.inc.php b/packages/playground/tools/src/phpmyadmin/config.inc.php index 60888b99aa3..268c0e23dfc 100644 --- a/packages/playground/tools/src/phpmyadmin/config.inc.php +++ b/packages/playground/tools/src/phpmyadmin/config.inc.php @@ -16,6 +16,11 @@ $cfg['ShowCreateDb'] = false; $cfg['ShowChgPassword'] = false; +// Split-origin popups keep phpMyAdmin in a WordPress iframe. Its frame-busting +// script must not try to replace the app-origin wrapper; the iframe's sandbox +// and the browser's origin checks still prevent access to app documents/storage. +$cfg['AllowThirdPartyFraming'] = defined('PLAYGROUND_PARENT_ORIGIN'); + // Cookie authentication secret. $cfg['blowfish_secret'] = 'r/g+J#&)L2&p!z5gUS)d(vEU#KAynq#g'; diff --git a/packages/playground/website/playwright/e2e/website-ui.spec.ts b/packages/playground/website/playwright/e2e/website-ui.spec.ts index 868ffbf6c43..145d6e72ea9 100644 --- a/packages/playground/website/playwright/e2e/website-ui.spec.ts +++ b/packages/playground/website/playwright/e2e/website-ui.spec.ts @@ -1,6 +1,6 @@ import { test, expect } from '../playground-fixtures.ts'; import type { Blueprint } from '@wp-playground/blueprints'; -import type { Page } from '@playwright/test'; +import type { Frame, Page } from '@playwright/test'; import { getDirectoryNameForSlug } from '../../src/lib/state/opfs/opfs-site-path'; // We can't import the SupportedPHPVersions versions directly from the remote package @@ -1224,8 +1224,8 @@ echo $wp_env['db']['path']; await adminerButton.click(); // Verify Adminer opened in new tab - const newPage = await pagePromise; - await newPage.waitForLoadState(); + const popup = await pagePromise; + const newPage = await getWordPressPopupDocument(popup); expect(newPage.url()).toContain('/adminer/'); await expect(newPage.locator('body')).toContainText('Adminer'); await expect(newPage.locator('body')).toContainText('wp_posts'); @@ -1271,7 +1271,10 @@ echo $wp_env['db']['path']; ).toContainText('Updated post content.'); // Go to SQL tab and execute "SHOW TABLES" - await newPage.getByRole('link', { name: 'SQL command' }).click(); + await newPage + .locator('#menu') + .getByRole('link', { name: 'SQL command' }) + .click(); await newPage.waitForLoadState(); const sqlTextarea = newPage.locator('textarea[name="query"]'); await sqlTextarea.fill('SHOW TABLES', { force: true }); @@ -1279,7 +1282,7 @@ echo $wp_env['db']['path']; await newPage.waitForLoadState(); await expect(newPage.locator('body')).toContainText('wp_posts'); - await newPage.close(); + await popup.close(); }); test('should load and open phpMyAdmin', async ({ website }) => { @@ -1296,8 +1299,8 @@ echo $wp_env['db']['path']; await phpMyAdminButton.click(); // Verify phpMyAdmin opened in new tab - const newPage = await pagePromise; - await newPage.waitForLoadState(); + const popup = await pagePromise; + const newPage = await getWordPressPopupDocument(popup); expect(newPage.url()).toContain('/phpmyadmin'); await expect(newPage.locator('body')).toContainText('phpMyAdmin'); await expect(newPage.locator('body')).toContainText('wp_posts'); @@ -1361,12 +1364,12 @@ echo $wp_env['db']['path']; .click(); await newPage.waitForLoadState(); await newPage.locator('.CodeMirror.cm-s-default').click(); - await newPage.keyboard.type('SHOW TABLES'); + await popup.keyboard.type('SHOW TABLES'); await newPage.getByRole('button', { name: 'Go' }).click(); await newPage.waitForLoadState(); await expect(newPage.locator('body')).toContainText('wp_posts'); - await newPage.close(); + await popup.close(); }); /* @@ -1379,8 +1382,8 @@ echo $wp_env['db']['path']; await website.page .getByRole('button', { name: 'Open Adminer' }) .click(); - const adminerPage = await adminerPagePromise; - await adminerPage.waitForLoadState(); + const adminerPopup = await adminerPagePromise; + const adminerPage = await getWordPressPopupDocument(adminerPopup); await expect(adminerPage.locator('body')).toContainText('Adminer'); await expect(adminerPage.locator('body')).toContainText('wp_posts'); @@ -1388,18 +1391,30 @@ echo $wp_env['db']['path']; await website.page .getByRole('button', { name: 'Open phpMyAdmin' }) .click(); - const phpMyAdminPage = await phpMyAdminPagePromise; - await phpMyAdminPage.waitForLoadState(); + const phpMyAdminPopup = await phpMyAdminPagePromise; + const phpMyAdminPage = await getWordPressPopupDocument(phpMyAdminPopup); await expect(phpMyAdminPage.locator('body')).toContainText( 'phpMyAdmin' ); await expect(phpMyAdminPage.locator('body')).toContainText('wp_posts'); - await adminerPage.close(); - await phpMyAdminPage.close(); + await adminerPopup.close(); + await phpMyAdminPopup.close(); }); }); +/** Follow the isolated WordPress iframe when the database tool needs an app-origin popup. */ +async function getWordPressPopupDocument(popup: Page): Promise { + await popup.waitForLoadState(); + const frame = popup.frame({ name: 'wordpress-popup' }); + if (!frame) { + return popup; + } + // WebKit can finish loading the wrapper before its iframe leaves about:blank. + await frame.waitForURL((url) => url.pathname.startsWith('/scope:')); + return frame; +} + // Test browser-saved Playgrounds by default and explicit temporary opt-outs. // The `@storage` tag routes this group to the one-worker CI storage lane. test.describe('Default Playground storage', { tag: '@storage' }, () => { diff --git a/packages/playground/website/src/components/site-manager/site-database-panel/adminer-button.tsx b/packages/playground/website/src/components/site-manager/site-database-panel/adminer-button.tsx index 5c153201a03..ae031cf87e2 100644 --- a/packages/playground/website/src/components/site-manager/site-database-panel/adminer-button.tsx +++ b/packages/playground/website/src/components/site-manager/site-database-panel/adminer-button.tsx @@ -3,6 +3,7 @@ import { logger } from '@php-wasm/logger'; import { external } from '@wordpress/icons'; import { useEffect, useState } from 'react'; import css from './style.module.css'; +import { getWordPressPopupUrl } from '../../../lib/wordpress-popup'; import { type PlaygroundClient, type StepDefinition, @@ -53,6 +54,7 @@ async function installAdminer(playground: PlaygroundClient) { await runBlueprintV1Steps(blueprint, playground as UniversalPHP); } +/** Install and open Adminer without moving WordPress into another storage partition. */ export function AdminerButton({ playground, }: { @@ -91,6 +93,7 @@ export function AdminerButton({ }; }, [playground]); + /** Open the installed tool through the matching WordPress browsing context. */ const handleOpenAdminer = async () => { if (!playground) { return; @@ -117,7 +120,7 @@ export function AdminerButton({ const playgroundUrl = await playground.absoluteUrl; if (playgroundUrl) { window.open( - `${playgroundUrl}/adminer/`, + getWordPressPopupUrl(`${playgroundUrl}/adminer/`), '_blank', 'noopener,noreferrer' ); diff --git a/packages/playground/website/src/components/site-manager/site-database-panel/phpmyadmin-button.tsx b/packages/playground/website/src/components/site-manager/site-database-panel/phpmyadmin-button.tsx index 1db78cd5146..d671086d7d9 100644 --- a/packages/playground/website/src/components/site-manager/site-database-panel/phpmyadmin-button.tsx +++ b/packages/playground/website/src/components/site-manager/site-database-panel/phpmyadmin-button.tsx @@ -3,6 +3,7 @@ import { logger } from '@php-wasm/logger'; import { Button, Icon, Flex, FlexItem } from '@wordpress/components'; import { external } from '@wordpress/icons'; import css from './style.module.css'; +import { getWordPressPopupUrl } from '../../../lib/wordpress-popup'; import { type PlaygroundClient, type UniversalPHP, @@ -27,6 +28,7 @@ async function installPhpMyAdmin(playground: PlaygroundClient) { await runBlueprintV1Steps(blueprint, playground as UniversalPHP); } +/** Install and open phpMyAdmin without moving WordPress into another storage partition. */ export function PhpMyAdminButton({ playground, }: { @@ -65,6 +67,7 @@ export function PhpMyAdminButton({ }; }, [playground]); + /** Open the installed tool through the matching WordPress browsing context. */ const handleOpenPhpMyAdmin = async () => { if (!playground) { return; @@ -91,7 +94,9 @@ export function PhpMyAdminButton({ const playgroundUrl = await playground.absoluteUrl; if (playgroundUrl) { window.open( - `${playgroundUrl}${PHPMYADMIN_URL_PATH}${PHPMYADMIN_ENTRY_PATH}`, + getWordPressPopupUrl( + `${playgroundUrl}${PHPMYADMIN_URL_PATH}${PHPMYADMIN_ENTRY_PATH}` + ), '_blank', 'noopener,noreferrer' ); diff --git a/packages/playground/website/src/lib/wordpress-popup.spec.ts b/packages/playground/website/src/lib/wordpress-popup.spec.ts new file mode 100644 index 00000000000..80a918a6189 --- /dev/null +++ b/packages/playground/website/src/lib/wordpress-popup.spec.ts @@ -0,0 +1,30 @@ +import { getWordPressPopupUrl } from './wordpress-popup'; + +vi.mock('virtual:website-config', () => ({ buildVersion: 'test' })); + +describe('WordPress popup URLs', () => { + beforeEach(() => { + vi.stubGlobal('window', { + location: { origin: 'http://playground.localhost:9500' }, + }); + }); + afterEach(() => vi.unstubAllGlobals()); + + it('keeps same-origin popup URLs unchanged', () => { + const url = + 'http://playground.localhost:9500/scope:site/adminer/?select=wp_posts'; + expect(getWordPressPopupUrl(url)).toBe(url); + }); + + it('preserves the scoped path, query and fragment inside the app-origin popup', () => { + const popup = new URL( + getWordPressPopupUrl( + 'http://wp.playground.localhost:9500/scope:site/adminer/?select=wp_posts#result' + ) + ); + expect(popup.origin).toBe('http://playground.localhost:9500'); + expect(popup.pathname).toBe('/wordpress-popup.html'); + expect(popup.search).toBe(''); + expect(popup.hash).toBe('#/scope:site/adminer/?select=wp_posts#result'); + }); +}); diff --git a/packages/playground/website/src/lib/wordpress-popup.ts b/packages/playground/website/src/lib/wordpress-popup.ts new file mode 100644 index 00000000000..ecacbc93923 --- /dev/null +++ b/packages/playground/website/src/lib/wordpress-popup.ts @@ -0,0 +1,14 @@ +import { getRemoteUrl } from './config'; + +/** Keep a split-origin popup in the same service-worker partition as the running site. */ +export function getWordPressPopupUrl(url: string): string { + const target = new URL(url); + const remote = getRemoteUrl(); + if (target.origin === remote.origin) { + return target.href; + } + remote.pathname = '/wordpress-popup.html'; + remote.search = ''; + remote.hash = target.pathname + target.search + target.hash; + return remote.href; +} From 8a9458f67014215005dbb51e79c27786294b8787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Wed, 21 Oct 2026 16:12:04 +0200 Subject: [PATCH 2/6] [Website] Explain how popup frames reuse the running service worker --- .../playground/remote/src/lib/wordpress-popup.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/playground/remote/src/lib/wordpress-popup.ts b/packages/playground/remote/src/lib/wordpress-popup.ts index cbfde99539c..2ad85164c16 100644 --- a/packages/playground/remote/src/lib/wordpress-popup.ts +++ b/packages/playground/remote/src/lib/wordpress-popup.ts @@ -1,7 +1,18 @@ import { getURLScope } from '@php-wasm/scopes'; import { wordPressSiteUrl } from './config'; -/** Keep popup WordPress in the app's service-worker partition without exposing app documents. */ +/** + * Opens a WordPress tool in a popup with the same frame layout as the main app: + * an app-origin top-level page containing a WordPress-origin iframe. + * + * Browsers can select service-worker registrations using both the WordPress + * origin and the top-level site. Opening WordPress directly can then miss the + * worker serving it inside the main app. This app-origin wrapper preserves + * that top-level site, so #wp can use the existing worker and PHP instance. + * + * The hash supplies the destination. Accept only scoped WordPress URLs so this + * wrapper cannot be used to load trusted app documents into the iframe. + */ function bootWordPressPopup() { const target = new URL(location.hash.substring(1), wordPressSiteUrl); if (target.origin !== wordPressSiteUrl || !getURLScope(target)) { From 91e999251b9d0c220ca4f62e4da2bf3c26fa7bec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Wed, 21 Oct 2026 13:39:40 +0200 Subject: [PATCH 3/6] [Website] Carry external embed origins into framing policies --- packages/playground/client/src/index.spec.ts | 38 +++++++++++++ packages/playground/client/src/index.ts | 25 ++++++++- .../remote/src/lib/frame-ancestors.spec.ts | 55 +++++++++++++++++++ .../remote/src/lib/frame-ancestors.ts | 36 ++++++++++++ 4 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 packages/playground/remote/src/lib/frame-ancestors.spec.ts create mode 100644 packages/playground/remote/src/lib/frame-ancestors.ts diff --git a/packages/playground/client/src/index.spec.ts b/packages/playground/client/src/index.spec.ts index 141ff24e47d..abf579bb8f5 100644 --- a/packages/playground/client/src/index.spec.ts +++ b/packages/playground/client/src/index.spec.ts @@ -119,6 +119,42 @@ describe('startPlaygroundWeb', () => { expect(mocks.BlueprintsV1Handler).not.toHaveBeenCalled(); expect(iframe.src).not.toContain('blueprints-runner'); }); + it('carries external ancestors through a referrer-free inner frame', async () => { + mocks.BlueprintsV1Handler.mockImplementation(() => ({ + bootPlayground: mocks.bootPlaygroundV1, + })); + const iframe = createIframe(); + Object.assign(iframe.ownerDocument, { + URL: 'http://localhost/?embedder-origin=https%3A%2F%2Fouter.example', + referrer: 'https://inner.example/article', + }); + await startPlaygroundWeb({ + iframe, + remoteUrl: 'http://localhost/remote.html', + progressTracker: createProgressTracker(), + }); + expect( + new URL(iframe.src).searchParams.getAll('embedder-origin') + ).toEqual(['https://outer.example', 'https://inner.example']); + }); + it('declares the actual origin of an about:blank SDK caller', async () => { + mocks.BlueprintsV1Handler.mockImplementation(() => ({ + bootPlayground: mocks.bootPlaygroundV1, + })); + const iframe = createIframe(); + Object.assign(iframe.ownerDocument, { + URL: 'about:blank', + defaultView: { origin: 'https://embedder.example' }, + }); + await startPlaygroundWeb({ + iframe, + remoteUrl: 'http://localhost/remote.html', + progressTracker: createProgressTracker(), + }); + expect( + new URL(iframe.src).searchParams.getAll('embedder-origin') + ).toEqual(['https://embedder.example']); + }); }); describe('startPlaygroundAPI', () => { @@ -135,9 +171,11 @@ describe('startPlaygroundAPI', () => { }); }); +/** Supply the SDK caller document without booting a browser runtime. */ function createIframe() { return { src: '', + ownerDocument: { URL: 'http://localhost/', referrer: '' }, addEventListener: vi.fn((_event, callback: () => void) => { callback(); }), diff --git a/packages/playground/client/src/index.ts b/packages/playground/client/src/index.ts index 22536815560..85fb08c71f6 100644 --- a/packages/playground/client/src/index.ts +++ b/packages/playground/client/src/index.ts @@ -292,10 +292,33 @@ export async function startPlaygroundAPI( return api; } +/** + * Carry the embedding chain into trusted inner documents, even with no referrer. + * These are declarations, not permission grants: the server excludes WordPress + * and the browser checks the actual ancestor chain against its response policy. + */ function loadIframe(iframe: HTMLIFrameElement, url: string): Promise { + const target = new URL(url); + const document = iframe.ownerDocument; + const parent = new URL(document.URL); + const origins = new Set([ + ...target.searchParams.getAll('embedder-origin'), + ...parent.searchParams.getAll('embedder-origin'), + // about:blank/srcdoc documents can inherit an origin despite their opaque URL. + document.defaultView?.origin ?? parent.origin, + ]); + if (document.referrer) { + origins.add(new URL(document.referrer).origin); + } + target.searchParams.delete('embedder-origin'); + for (const origin of origins) { + if (origin !== target.origin && origin !== 'null') { + target.searchParams.append('embedder-origin', origin); + } + } return new Promise((resolve) => { iframe.addEventListener('load', () => resolve(), { once: true }); - iframe.src = url; + iframe.src = target.href; }); } diff --git a/packages/playground/remote/src/lib/frame-ancestors.spec.ts b/packages/playground/remote/src/lib/frame-ancestors.spec.ts new file mode 100644 index 00000000000..3226023aedf --- /dev/null +++ b/packages/playground/remote/src/lib/frame-ancestors.spec.ts @@ -0,0 +1,55 @@ +import { describe, expect, it } from 'vitest'; +import { getFrameAncestors } from './frame-ancestors'; + +const root = 'https://playground.example'; +const wordpress = 'https://wp.playground.example'; + +describe('trusted document framing policy', () => { + it('allows normal referrers and explicit origins for all external ancestors', () => { + const url = new URL('/remote.html', root); + url.searchParams.append('embedder-origin', 'https://outer.example'); + url.searchParams.append('embedder-origin', 'https://inner.example'); + expect( + getFrameAncestors(url, 'https://inner.example/article', wordpress) + ).toBe( + "frame-ancestors 'self' https://outer.example https://inner.example" + ); + }); + + it.each([ + wordpress, + wordpress + '/scope:example/', + 'http://wp.playground.example', + 'http://wp.playground.example:443', + 'https://wp.playground.example:9443', + 'https://user:password@wp.playground.example', + 'data:text/html,test', + 'null', + 'https://*.example', + 'https://example.com;frame-ancestors', + "https://example.com'", + 'https://example.com,https:', + "'none'; frame-ancestors *", + ])('never grants framing permission for %s', (value) => { + const url = new URL('/api.html', root); + url.searchParams.append('embedder-origin', value); + expect(getFrameAncestors(url, value, wordpress)).toBe( + "frame-ancestors 'self'" + ); + }); + + it('keeps WordPress excluded when an external origin is declared alongside it', () => { + const url = new URL('/api.html', root); + url.searchParams.append('embedder-origin', wordpress); + url.searchParams.append('embedder-origin', 'https://external.example'); + expect(getFrameAncestors(url, wordpress, wordpress)).toBe( + "frame-ancestors 'self' https://external.example" + ); + }); + + it('fails closed without either an explicit origin or a referrer', () => { + expect( + getFrameAncestors(new URL('/api.html', root), '', wordpress) + ).toBe("frame-ancestors 'self'"); + }); +}); diff --git a/packages/playground/remote/src/lib/frame-ancestors.ts b/packages/playground/remote/src/lib/frame-ancestors.ts new file mode 100644 index 00000000000..5fe8874de3e --- /dev/null +++ b/packages/playground/remote/src/lib/frame-ancestors.ts @@ -0,0 +1,36 @@ +/** + * Allow declared external embedders, never the untrusted WordPress origin. + * CSP checks every ancestor, so an external intermediary cannot hide WordPress. + * Referrer-free plain iframes must declare their embedder-origin in the URL. + */ +export function getFrameAncestors( + url: URL, + referrer: string, + wordPressOrigin: string +): string { + const wordPressHostname = new URL(wordPressOrigin).hostname; + const origins = new Set(); + for (const value of [ + ...url.searchParams.getAll('embedder-origin'), + referrer, + ]) { + try { + const candidate = new URL(value); + const origin = candidate.origin; + if ( + !/^https?:\/\//.test(origin) || + /[\s,;'*]/.test(origin) || + // CSP permits HTTP sources to match HTTPS. Exclude the WordPress host + // on every scheme and port rather than checking exact origin strings. + candidate.hostname === wordPressHostname || + origin === url.origin + ) { + continue; + } + origins.add(origin); + } catch { + // Invalid and opaque origins cannot grant permission to frame root documents. + } + } + return ["frame-ancestors 'self'", ...origins].join(' '); +} From 2d38668108779e68cebb90b7f8a520857ee68fe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Wed, 21 Oct 2026 20:26:36 +0200 Subject: [PATCH 4/6] [Web] Limit declared referrers to enclosing frames --- packages/playground/client/src/index.spec.ts | 29 +++++++++++++++++++- packages/playground/client/src/index.ts | 7 +++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/packages/playground/client/src/index.spec.ts b/packages/playground/client/src/index.spec.ts index abf579bb8f5..5d7da1b1044 100644 --- a/packages/playground/client/src/index.spec.ts +++ b/packages/playground/client/src/index.spec.ts @@ -119,6 +119,29 @@ describe('startPlaygroundWeb', () => { expect(mocks.BlueprintsV1Handler).not.toHaveBeenCalled(); expect(iframe.src).not.toContain('blueprints-runner'); }); + it('does not disclose a top-level caller’s previous page as an embedder', async () => { + mocks.BlueprintsV1Handler.mockImplementation(() => ({ + bootPlayground: mocks.bootPlaygroundV1, + })); + const iframe = createIframe(); + const view = { origin: 'https://sdk.example' }; + Object.assign(view, { parent: view }); + Object.assign(iframe.ownerDocument, { + URL: 'https://sdk.example/', + referrer: 'https://previous.example/article', + defaultView: view, + }); + + await startPlaygroundWeb({ + iframe, + remoteUrl: 'http://localhost/remote.html', + progressTracker: createProgressTracker(), + }); + + expect( + new URL(iframe.src).searchParams.getAll('embedder-origin') + ).toEqual(['https://sdk.example']); + }); it('carries external ancestors through a referrer-free inner frame', async () => { mocks.BlueprintsV1Handler.mockImplementation(() => ({ bootPlayground: mocks.bootPlaygroundV1, @@ -175,7 +198,11 @@ describe('startPlaygroundAPI', () => { function createIframe() { return { src: '', - ownerDocument: { URL: 'http://localhost/', referrer: '' }, + ownerDocument: { + URL: 'http://localhost/', + referrer: '', + defaultView: { parent: {} }, + }, addEventListener: vi.fn((_event, callback: () => void) => { callback(); }), diff --git a/packages/playground/client/src/index.ts b/packages/playground/client/src/index.ts index 85fb08c71f6..7d78eea9dba 100644 --- a/packages/playground/client/src/index.ts +++ b/packages/playground/client/src/index.ts @@ -300,14 +300,17 @@ export async function startPlaygroundAPI( function loadIframe(iframe: HTMLIFrameElement, url: string): Promise { const target = new URL(url); const document = iframe.ownerDocument; + const view = document.defaultView; const parent = new URL(document.URL); const origins = new Set([ ...target.searchParams.getAll('embedder-origin'), ...parent.searchParams.getAll('embedder-origin'), // about:blank/srcdoc documents can inherit an origin despite their opaque URL. - document.defaultView?.origin ?? parent.origin, + view?.origin ?? parent.origin, ]); - if (document.referrer) { + // An embedded caller's referrer can name a frame above it. At the top level, + // it names the previous page, which must not be copied into this iframe URL. + if (document.referrer && view && view.parent !== view) { origins.add(new URL(document.referrer).origin); } target.searchParams.delete('embedder-origin'); From 724a6a297c709947b6dab6ff41b1cd25985eb8a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Wed, 21 Oct 2026 20:26:36 +0200 Subject: [PATCH 5/6] [Website] Serve the app shell on My WordPress directory reloads --- .../playwright/e2e/shared-runtime.spec.ts | 6 ++++++ packages/playground/personal-wp/vite.config.ts | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/packages/playground/personal-wp/playwright/e2e/shared-runtime.spec.ts b/packages/playground/personal-wp/playwright/e2e/shared-runtime.spec.ts index 8ed878e3aa3..06b4abad7f7 100644 --- a/packages/playground/personal-wp/playwright/e2e/shared-runtime.spec.ts +++ b/packages/playground/personal-wp/playwright/e2e/shared-runtime.spec.ts @@ -143,7 +143,13 @@ test('boots a replacement runtime without reloading the new tab after retirement async () => (await fetch('/scope:default/wp-json/')).status ) ).toBe(503); + const reloadedDocument = page.waitForResponse( + (response) => + response.request().isNavigationRequest() && + response.request().frame() === page.mainFrame() + ); await page.getByRole('button', { name: 'Reload this tab' }).click(); + expect((await reloadedDocument).ok()).toBe(true); await page.waitForFunction(() => !!(window as any).playground); await page.evaluate(() => (window as any).playground.isReady()); expect( diff --git a/packages/playground/personal-wp/vite.config.ts b/packages/playground/personal-wp/vite.config.ts index 9122077b9eb..430d093b54b 100644 --- a/packages/playground/personal-wp/vite.config.ts +++ b/packages/playground/personal-wp/vite.config.ts @@ -110,6 +110,23 @@ export default defineConfig(({ command, mode }) => { }, '^[/]((?!website-server).)': { target: `http://${remoteDevServerHost}:${remoteDevServerPort}`, + /** + * Reload WordPress directory URLs through the app shell, not the remote server. + * The service worker forwards reloads with destination "empty", so check Accept. + * Scoped WordPress documents and runtime files must still use the proxy. + */ + bypass(request) { + const pathname = new URL( + request.url!, + 'http://localhost' + ).pathname; + if ( + request.headers.accept?.includes('text/html') && + pathname.endsWith('/') && + !pathname.startsWith('/scope:') + ) + return '/website-server/index.html'; + }, }, }, fs: { From e423a27812cd361354b578f2c09184781c3db64f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Wed, 21 Oct 2026 20:39:32 +0200 Subject: [PATCH 6/6] [Personal WP] Check the final document response after reload redirects --- .../personal-wp/playwright/e2e/shared-runtime.spec.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/playground/personal-wp/playwright/e2e/shared-runtime.spec.ts b/packages/playground/personal-wp/playwright/e2e/shared-runtime.spec.ts index 06b4abad7f7..c93ceeaad57 100644 --- a/packages/playground/personal-wp/playwright/e2e/shared-runtime.spec.ts +++ b/packages/playground/personal-wp/playwright/e2e/shared-runtime.spec.ts @@ -143,10 +143,13 @@ test('boots a replacement runtime without reloading the new tab after retirement async () => (await fetch('/scope:default/wp-json/')).status ) ).toBe(503); + // Vite redirects / to /website-server/. Check the final document response, + // not that redirect, while still reporting an error response immediately. const reloadedDocument = page.waitForResponse( (response) => response.request().isNavigationRequest() && - response.request().frame() === page.mainFrame() + response.request().frame() === page.mainFrame() && + (response.status() < 300 || response.status() >= 400) ); await page.getByRole('button', { name: 'Reload this tab' }).click(); expect((await reloadedDocument).ok()).toBe(true);