From 57c7b70d2ea5f1fb07a1bb6bc10351dd32cada2c Mon Sep 17 00:00:00 2001 From: Luke Parker <10430890+Hona@users.noreply.github.com> Date: Fri, 30 Oct 2026 14:06:15 +1000 Subject: [PATCH] fix(cli): allow blob frames and objects in web UI CSP (#60453) --- packages/cli/src/services/web-ui.ts | 4 +++- packages/cli/test/web-ui.test.ts | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/services/web-ui.ts b/packages/cli/src/services/web-ui.ts index edda5d733db..38e59839b27 100644 --- a/packages/cli/src/services/web-ui.ts +++ b/packages/cli/src/services/web-ui.ts @@ -80,8 +80,10 @@ function isRouteNotFound(error: unknown) { // qr-scanner decodes in a worker it creates from a blob: URL whenever the browser has no BarcodeDetector (Safari, desktop // Chrome on Windows and Linux). Without worker-src that worker falls under script-src 'self' and never starts. +// Artifact previews render HTML and PDF files from blob: URLs; without frame-src and object-src they fall back to +// default-src 'self' and are blocked. function csp(hash = "") { - return `default-src 'self'; script-src 'self' 'wasm-unsafe-eval'${hash ? ` 'sha256-${hash}'` : ""}; style-src 'self' 'unsafe-inline'; img-src 'self' data: https: blob:; font-src 'self' data:; media-src 'self' data:; connect-src * data: blob:; worker-src 'self' blob:` + return `default-src 'self'; script-src 'self' 'wasm-unsafe-eval'${hash ? ` 'sha256-${hash}'` : ""}; style-src 'self' 'unsafe-inline'; img-src 'self' data: https: blob:; font-src 'self' data:; media-src 'self' data:; connect-src * data: blob:; worker-src 'self' blob:; frame-src 'self' blob:; object-src 'self' blob:` } function cspForHtml(body: string) { diff --git a/packages/cli/test/web-ui.test.ts b/packages/cli/test/web-ui.test.ts index 081516d3a89..14aa95b0059 100644 --- a/packages/cli/test/web-ui.test.ts +++ b/packages/cli/test/web-ui.test.ts @@ -217,6 +217,8 @@ describe("web UI", () => { expect(fallback.headers.get("content-security-policy")).toContain("default-src 'self'") expect(fallback.headers.get("content-security-policy")).toContain("connect-src * data: blob:") expect(fallback.headers.get("content-security-policy")).toContain("worker-src 'self' blob:") + expect(fallback.headers.get("content-security-policy")).toContain("frame-src 'self' blob:") + expect(fallback.headers.get("content-security-policy")).toContain("object-src 'self' blob:") const dotted = yield* Effect.promise(() => fetch(`${origin}/workspace/example.js`)) expect(dotted.status).toBe(200)