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.
This commit is contained in:
Michael Wang
2026-11-17 02:37:32 +00:00
committed by GitHub
parent a6dd840eb1
commit 02c1fb48e7
2 changed files with 25 additions and 1 deletions
@@ -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");
});
});
+3 -1
View File
@@ -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 `<script>window.__HF_STUDIO_ENV__=${JSON.stringify(overrides)};</script>`;
}
// 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) {