Skip to content

Commit e5f06e2

Browse files
committed
fix(cli): allow blob frames and objects in web UI CSP
The web UI CSP has no frame-src or object-src directive, so blob: iframes and objects fall back to default-src 'self' and are blocked. Desktop is built from v2 and serves the CSP from this file, so blob: previews (icons, PDFs) stay blocked there. Add frame-src 'self' blob: and object-src 'self' blob: next to the existing worker-src, and assert both in the web UI test. Closes anomalyco#50828
1 parent 5cfe3b4 commit e5f06e2

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

‎packages/cli/src/services/web-ui.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function isRouteNotFound(error: unknown) {
8181
// qr-scanner decodes in a worker it creates from a blob: URL whenever the browser has no BarcodeDetector (Safari, desktop
8282
// Chrome on Windows and Linux). Without worker-src that worker falls under script-src 'self' and never starts.
8383
function csp(hash = "") {
84-
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:`
84+
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:; frame-src 'self' blob:; object-src 'self' blob:; connect-src * data: blob:; worker-src 'self' blob:`
8585
}
8686

8787
function cspForHtml(body: string) {

‎packages/cli/test/web-ui.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ describe("web UI", () => {
217217
expect(fallback.headers.get("content-security-policy")).toContain("default-src 'self'")
218218
expect(fallback.headers.get("content-security-policy")).toContain("connect-src * data: blob:")
219219
expect(fallback.headers.get("content-security-policy")).toContain("worker-src 'self' blob:")
220+
expect(fallback.headers.get("content-security-policy")).toContain("frame-src 'self' blob:")
221+
expect(fallback.headers.get("content-security-policy")).toContain("object-src 'self' blob:")
220222

221223
const dotted = yield* Effect.promise(() => fetch(`${origin}/workspace/example.js`))
222224
expect(dotted.status).toBe(200)

0 commit comments

Comments
 (0)