Skip to content

Commit cbaf017

Browse files
committed
fix(opencode): allow blob frames and objects in embedded UI CSP
The embedded web UI CSP had no frame-src or object-src directive, so blob: iframes and objects fell back to default-src 'self' and were blocked. The icon renderer frames blob: URLs (icons showed the browser's blocked placeholder), and PDF previews are affected the same way. Add frame-src 'self' blob: and object-src 'self' blob:. Closes anomalyco#50828
1 parent 1ddb087 commit cbaf017

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎packages/opencode/src/server/shared/ui.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ let embeddedUIPromise: Promise<Record<string, string> | null> | undefined
99
export const UI_UPSTREAM = new URL("https://app.opencode.ai")
1010

1111
export const csp = (hash = "") =>
12-
`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:`
12+
`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:`
1313
export const DEFAULT_CSP = csp()
1414

1515
export function themePreloadHash(body: string) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { describe, expect, test } from "bun:test"
2+
import { DEFAULT_CSP, csp, cspForHtml } from "../../src/server/shared/ui"
3+
4+
describe("embedded UI CSP", () => {
5+
test("allows same-origin blob frames and objects", () => {
6+
expect(DEFAULT_CSP).toContain("frame-src 'self' blob:")
7+
expect(DEFAULT_CSP).toContain("object-src 'self' blob:")
8+
})
9+
10+
test("keeps the blob allowances when a theme preload hash is added", () => {
11+
const policy = csp("abc123")
12+
expect(policy).toContain("frame-src 'self' blob:")
13+
expect(policy).toContain("object-src 'self' blob:")
14+
expect(policy).toContain("'sha256-abc123'")
15+
})
16+
17+
test("cspForHtml keeps the blob allowances for documents with a theme preload script", () => {
18+
const body = '<script id="oc-theme-preload-script">document.title = "test"</script>'
19+
const policy = cspForHtml(body)
20+
expect(policy).toContain("frame-src 'self' blob:")
21+
expect(policy).toContain("object-src 'self' blob:")
22+
expect(policy).toContain("'sha256-")
23+
})
24+
})

0 commit comments

Comments
 (0)