From 02c1fb48e7d8d89efa3746e6f3b0ea16027753e0 Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Tue, 17 Nov 2026 02:37:32 +0000 Subject: [PATCH] fix(cli): only the Studio's own origin may frame the Studio page (#8000) The CLI Studio page now sends frame-ancestors 'self' and X-Frame-Options SAMEORIGIN, as present and the engine file servers already do. This covers the normal page and the missing-bundle page. --- .../server/studioServer.staticAssets.test.ts | 22 +++++++++++++++++++ packages/cli/src/server/studioServer.ts | 4 +++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/server/studioServer.staticAssets.test.ts b/packages/cli/src/server/studioServer.staticAssets.test.ts index 94a514d3ba..35ba808807 100644 --- a/packages/cli/src/server/studioServer.staticAssets.test.ts +++ b/packages/cli/src/server/studioServer.staticAssets.test.ts @@ -98,3 +98,25 @@ describe("studio bundle cache policy", () => { expect(await response.text()).toBe(BUNDLE_BYTES); }); }); + +describe("studio shell framing", () => { + it("lets only its own origin frame the shell, on any SPA route", async () => { + for (const route of ["/", "/projects/demo"]) { + const response = await server.app.request(route); + + expect(response.status).toBe(200); + expect(response.headers.get("Content-Security-Policy")).toBe("frame-ancestors 'self'"); + expect(response.headers.get("X-Frame-Options")).toBe("SAMEORIGIN"); + } + }); + + it("refuses other sites' framing of the missing-bundle page too", async () => { + fs.rmSync(path.join(hooks.studioDir, "index.html")); + + const response = await server.app.request("/"); + + expect(response.status).toBe(500); + expect(response.headers.get("Content-Security-Policy")).toBe("frame-ancestors 'self'"); + expect(response.headers.get("X-Frame-Options")).toBe("SAMEORIGIN"); + }); +}); diff --git a/packages/cli/src/server/studioServer.ts b/packages/cli/src/server/studioServer.ts index 210f3c76d9..8bf1b26563 100644 --- a/packages/cli/src/server/studioServer.ts +++ b/packages/cli/src/server/studioServer.ts @@ -90,6 +90,7 @@ import type { ScreenshotClip } from "@hyperframes/studio-server/screenshot-clip" import type { RenderJob } from "@hyperframes/producer"; import { isWithinProjectRoot } from "@hyperframes/parsers/asset-resolution"; import { seekCompositionTimeline } from "../capture/captureCompositionFrame.js"; +import { SAME_ORIGIN_FRAMING_HEADERS } from "@hyperframes/engine"; import { createThumbnailPages } from "./thumbnailPages.js"; import { assertWebGpuAdapterAvailable, @@ -1215,8 +1216,9 @@ export function createStudioServer(options: StudioServerOptions): StudioServer { return ``; } - // SPA fallback + // SPA fallback. The shell's own requests pass every same-origin check, so only its own pages may frame it. app.get("*", (c) => { + for (const [name, value] of Object.entries(SAME_ORIGIN_FRAMING_HEADERS)) c.header(name, value); const indexPath = resolve(studioDir, "index.html"); const indexContent = readBundleFile(indexPath); if (indexContent === null) {