mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 05:01:03 +03:00
fix(cli): allow blob frames and objects in web UI CSP (#60453)
This commit is contained in:
committed by
GitHub
Unverified
parent
0bf67d5401
commit
57c7b70d2e
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user