From a6ff5725cc94ed3b28cc98a674b821485a689532 Mon Sep 17 00:00:00 2001 From: Pixel Perfect Date: Wed, 8 Jul 2026 22:40:03 -0700 Subject: [PATCH] Allow WebAssembly in the desktop renderer CSP The desktop protocol's Content-Security-Policy blocked the ghostty-web terminal from initializing: script-src had no 'wasm-unsafe-eval', so WebAssembly compilation was rejected, and connect-src had no data:, so the library's embedded WASM payload fetch failed. Add both sources. --- apps/desktop/src/electron/ElectronProtocol.test.ts | 14 +++++++++++--- apps/desktop/src/electron/ElectronProtocol.ts | 5 ++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/apps/desktop/src/electron/ElectronProtocol.test.ts b/apps/desktop/src/electron/ElectronProtocol.test.ts index 92e3000042..df07459cd1 100644 --- a/apps/desktop/src/electron/ElectronProtocol.test.ts +++ b/apps/desktop/src/electron/ElectronProtocol.test.ts @@ -57,11 +57,11 @@ describe("ElectronProtocol", () => { assert.equal(yield* Effect.promise(() => response.text()), "ok"); assert.include( response.headers.get("content-security-policy") ?? "", - "script-src 'self' 'unsafe-inline' https://clerk.t3.codes https://challenges.cloudflare.com", + "script-src 'self' 'unsafe-inline' 'wasm-unsafe-eval' https://clerk.t3.codes https://challenges.cloudflare.com", ); assert.include( response.headers.get("content-security-policy") ?? "", - "connect-src 'self' http: https: ws: wss:", + "connect-src 'self' data: http: https: ws: wss:", ); assert.include( response.headers.get("content-security-policy") ?? "", @@ -212,10 +212,18 @@ describe("ElectronProtocol", () => { assert.deepEqual(directives["script-src"], [ "'self'", "'unsafe-inline'", + "'wasm-unsafe-eval'", "https://clerk.t3.codes", "https://challenges.cloudflare.com", ]); - assert.deepEqual(directives["connect-src"], ["'self'", "http:", "https:", "ws:", "wss:"]); + assert.deepEqual(directives["connect-src"], [ + "'self'", + "data:", + "http:", + "https:", + "ws:", + "wss:", + ]); assert.deepEqual(directives["img-src"], [ "'self'", "t3code:", diff --git a/apps/desktop/src/electron/ElectronProtocol.ts b/apps/desktop/src/electron/ElectronProtocol.ts index 03c7ef64fd..fedecbed12 100644 --- a/apps/desktop/src/electron/ElectronProtocol.ts +++ b/apps/desktop/src/electron/ElectronProtocol.ts @@ -71,6 +71,8 @@ export function makeDesktopContentSecurityPolicy(input: DesktopProtocolRegistrat const scriptSources = [ "'self'", "'unsafe-inline'", + // Required to compile the ghostty-web terminal's WebAssembly module. + "'wasm-unsafe-eval'", ...(clerkOrigin ? [clerkOrigin] : []), "https://challenges.cloudflare.com", ]; @@ -79,7 +81,8 @@ export function makeDesktopContentSecurityPolicy(input: DesktopProtocolRegistrat // the build-configured Clerk, relay, and OTLP endpoints. Those environment // origins are not known when this response policy is created, so restrict // connections by the network schemes the client supports instead of by host. - const connectSources = ["'self'", "http:", "https:", "ws:", "wss:"]; + // data: allows ghostty-web to fetch its embedded WebAssembly payload. + const connectSources = ["'self'", "data:", "http:", "https:", "ws:", "wss:"]; return [ "default-src 'self'",