From 663c7ee04583c6cdecd0a64bfcfb2a66994e2701 Mon Sep 17 00:00:00 2001 From: Luke Parker <10430890+Hona@users.noreply.github.com> Date: Fri, 13 Nov 2026 12:45:55 +1000 Subject: [PATCH] fix(desktop): stop the packaged app from running as plain Node Cookie encryption keeps the key in the app's Keychain item, which macOS hands to the app's signed binary. With RunAsNode and the inspector fuses on, any local process could start that binary as Node (ELECTRON_RUN_AS_NODE=1) or with --inspect and read the key. Turn RunAsNode off everywhere and the inspector off outside Beta, which keeps it for the startup benchmark's Node timings like its on-request debugging port. NODE_OPTIONS stays on: packaged Electron already drops all but two harmless options, and the fuse would also strip NODE_EXTRA_CA_CERTS from the CLI's environment. --- packages/desktop/electron-builder.config.test.ts | 14 ++++++++++++++ packages/desktop/electron-builder.config.ts | 13 ++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/desktop/electron-builder.config.test.ts b/packages/desktop/electron-builder.config.test.ts index 3e29318dcac..f6c479a5bd4 100644 --- a/packages/desktop/electron-builder.config.test.ts +++ b/packages/desktop/electron-builder.config.test.ts @@ -80,6 +80,20 @@ test.each(channels)("channel identity for $channel", ({ channel, appId, feed }) expect(config.deb?.fpm).not.toContain("--rpm-rpmbuild-define=_build_id_links none") }) +test.each([ + { channel: "dev", inspect: false }, + { channel: "beta", inspect: true }, + { channel: "prod", inspect: false }, +])("Electron fuses for $channel", ({ channel, inspect }) => { + // Absent keys keep Electron's defaults: NODE_OPTIONS stays on, the asar and file: fuses stay as they are. + expect(load(channel).electronFuses).toEqual({ + enableCookieEncryption: true, + runAsNode: false, + enableNodeCliInspectArguments: inspect, + resetAdHocDarwinSignature: true, + }) +}) + test("legacy Linux launcher stays hidden", async () => { const desktop = await Bun.file(path.join(import.meta.dirname, "resources/linux/opencode-desktop.desktop")).text() expect(desktop).toContain("Exec=/opt/OpenCode/ai.opencode %U") diff --git a/packages/desktop/electron-builder.config.ts b/packages/desktop/electron-builder.config.ts index 2d4f6f7933a..e60d6270a0c 100644 --- a/packages/desktop/electron-builder.config.ts +++ b/packages/desktop/electron-builder.config.ts @@ -113,7 +113,18 @@ const getBase = (appId: string): Configuration => { // https://www.electronjs.org/docs/latest/tutorial/fuses#cookieencryption // Flipping a fuse breaks the macOS signature. A build without a signing identity is not signed again, so re-sign it // ad hoc or Apple Silicon refuses to launch it. A signed build is signed again after the fuses anyway. - electronFuses: { enableCookieEncryption: true, resetAdHocDarwinSignature: true }, + electronFuses: { + enableCookieEncryption: true, + // Started as plain Node (ELECTRON_RUN_AS_NODE) or with an inspector, the signed binary would run any code under + // the app's identity, which macOS lets read the app's Keychain key and so every cookie. Nothing runs the app as + // Node: the CLI is its own executable. Beta keeps --inspect, as it keeps its on-request debugging port, for the + // startup benchmark's Node timings (perf/startup.bench.ts). + runAsNode: false, + enableNodeCliInspectArguments: resolveChannel() === "beta", + // NODE_OPTIONS stays: a packaged app already ignores every option but --http-parser and --max-http-header-size, + // and turning the fuse off would also strip NODE_EXTRA_CA_CERTS from the environment the CLI and its terminals get. + resetAdHocDarwinSignature: true, + }, afterPack: async (context) => { const arch = Arch[context.arch]