diff --git a/packages/opencode/src/server/shared/ui.ts b/packages/opencode/src/server/shared/ui.ts index c2fd3b86375..d3f2c451131 100644 --- a/packages/opencode/src/server/shared/ui.ts +++ b/packages/opencode/src/server/shared/ui.ts @@ -9,7 +9,7 @@ let embeddedUIPromise: Promise | null> | undefined export const UI_UPSTREAM = new URL("https://app.opencode.ai") export const csp = (hash = "") => - `default-src 'self'; script-src 'self' 'wasm-unsafe-eval'${hash ? ` 'sha256-${hash}'` : ""}; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self' data:; media-src 'self' data:; connect-src * data:` + `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:` export const DEFAULT_CSP = csp() export function themePreloadHash(body: string) { diff --git a/packages/opencode/test/server/httpapi-ui.test.ts b/packages/opencode/test/server/httpapi-ui.test.ts index 2f10193f3d4..1a7ccc60dab 100644 --- a/packages/opencode/test/server/httpapi-ui.test.ts +++ b/packages/opencode/test/server/httpapi-ui.test.ts @@ -326,7 +326,7 @@ describe("HttpApi UI fallback", () => { }), ) - it.live("allows embedded UI terminal wasm and theme preload CSP", () => + it.live("allows embedded UI terminal wasm, blob attachments, and theme preload CSP", () => Effect.gen(function* () { const script = 'document.documentElement.dataset.theme = "dark"' @@ -351,7 +351,8 @@ describe("HttpApi UI fallback", () => { const csp = response.headers.get("content-security-policy") ?? "" expect(csp).toContain("script-src 'self' 'wasm-unsafe-eval'") expect(csp).toContain(`'sha256-${createHash("sha256").update(script).digest("base64")}'`) - expect(csp).toContain("connect-src * data:") + expect(csp).toContain("img-src 'self' data: https: blob:") + expect(csp).toContain("connect-src * data: blob:") }), )