Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: signature check only for the bundled engine, cached; server check uses its own stamp

ogsamrat240f2b0cced5
diff --git a/apps/desktop/electron/build-variant.mjs b/apps/desktop/electron/build-variant.mjs
index 2b6b30fe..d6dcb509 100644
--- a/apps/desktop/electron/build-variant.mjs
+++ b/apps/desktop/electron/build-variant.mjs
@@ -13,7 +13,7 @@
// - runs only the engine binary it bundles, checked by its sha256.
import { spawnSync } from "node:child_process";
import { createHash } from "node:crypto";
-import { existsSync, readFileSync } from "node:fs";
+import { existsSync, readFileSync, statSync } from "node:fs";
import path from "node:path";
export const DESKTOP_BUILD_FILE = "omnirush-build.json";
@@ -74,14 +74,22 @@ export const ENGINE_SIGNING_REQUIREMENT = `anchor apple generic and certificate
* notarization rewrite the engine binary after packaging records its sha256, so on
* macOS the signature, not the raw hash, says it is the bundled engine.
*/
-export function engineSignedByTeam(file, { platform = process.platform, run = spawnSync } = {}) {
+const signedCache = new Map();
+export function engineSignedByTeam(file, { platform = process.platform, run = spawnSync, stat = statSync } = {}) {
if (platform !== "darwin") return false;
+ let key = null;
+ try { const info = stat(file); key = `${file}\0${info.size}\0${info.mtimeMs}`; } catch { return false; }
+ if (signedCache.has(key)) return signedCache.get(key);
+ let ok = false;
try {
const result = run("/usr/bin/codesign", ["--verify", "--strict", `-R=${ENGINE_SIGNING_REQUIREMENT}`, file], { stdio: "ignore", timeout: 20_000 });
- return result?.status === 0;
+ ok = result?.status === 0;
} catch {
- return false;
+ ok = false;
}
+ // Only a pass is kept (same path, size and modification time); a failure is asked again next time.
+ if (ok) signedCache.set(key, true);
+ return ok;
}
/**
diff --git a/apps/desktop/electron/build-variant.test.mjs b/apps/desktop/electron/build-variant.test.mjs
index 7fa1cea3..4e482ec5 100644
--- a/apps/desktop/electron/build-variant.test.mjs
+++ b/apps/desktop/electron/build-variant.test.mjs
@@ -119,12 +119,15 @@ test("macOS: signing changes the engine after its sha256 is recorded; this team'
// The signature check asks codesign for this team's Developer ID, and only on macOS.
const calls = [];
const run = (cmd, argv) => { calls.push([cmd, ...argv]); return { status: 0 }; };
- assert.equal(engineSignedByTeam("/x/opencode", { platform: "darwin", run }), true);
+ const stat = () => ({ size: 1, mtimeMs: 1 });
+ assert.equal(engineSignedByTeam("/x/opencode", { platform: "darwin", run, stat }), true);
assert.deepEqual(calls[0], ["/usr/bin/codesign", "--verify", "--strict", `-R=${ENGINE_SIGNING_REQUIREMENT}`, "/x/opencode"]);
assert.match(ENGINE_SIGNING_REQUIREMENT, /anchor apple generic and certificate leaf\[subject\.OU\] = "2KFG4BXC8K"/);
- assert.equal(engineSignedByTeam("/x/opencode", { platform: "darwin", run: () => ({ status: 1 }) }), false);
- assert.equal(engineSignedByTeam("/x/opencode", { platform: "linux", run }), false);
- assert.equal(engineSignedByTeam("/x/opencode", { platform: "win32", run }), false);
+ assert.equal(engineSignedByTeam("/x/other", { platform: "darwin", run: () => ({ status: 1 }), stat }), false);
+ // A pass is cached (same file, size, time): codesign is not asked again.
+ assert.equal(engineSignedByTeam("/x/opencode", { platform: "darwin", run, stat }), true);
+ assert.equal(engineSignedByTeam("/x/opencode", { platform: "linux", run, stat }), false);
+ assert.equal(engineSignedByTeam("/x/opencode", { platform: "win32", run, stat }), false);
assert.equal(calls.length, 1, "codesign is never run off macOS");
// Off macOS a changed engine is still refused (the default check is false there).
if (process.platform !== "darwin") assert.throws(() => releaseEngineBinary(args), /was changed/);
diff --git a/apps/desktop/scripts/check-packaged-engine.mjs b/apps/desktop/scripts/check-packaged-engine.mjs
index b800289c..6a57663a 100644
--- a/apps/desktop/scripts/check-packaged-engine.mjs
+++ b/apps/desktop/scripts/check-packaged-engine.mjs
@@ -29,7 +29,8 @@ for (const name of engines) {
fail(`Electron main refuses ${name}: ${error instanceof Error ? error.message : String(error)}`);
}
try {
- await guard.releaseEngineBinary(path.join(sidecars, name), { release: true, engineSha256: build.engineSha256 });
+ // Its own stamped build facts (server/dist/build-variant.js), not Electron main's.
+ await guard.releaseEngineBinary(path.join(sidecars, name));
} catch (error) {
fail(`the local server refuses ${name}: ${error instanceof Error ? error.message : String(error)}`);
}
diff --git a/apps/server/src/release-guard.test.ts b/apps/server/src/release-guard.test.ts
index 3acafde7..e172af95 100644
--- a/apps/server/src/release-guard.test.ts
+++ b/apps/server/src/release-guard.test.ts
@@ -54,6 +54,8 @@ describe("release build guard", () => {
expect(await releaseEngineBinary(other, release, async () => true)).toBe(other);
await expect(releaseEngineBinary(other, release, async () => false)).rejects.toThrow("is not the bundled one");
expect(await engineSignedByTeam(other, "linux")).toBe(false);
+ // On macOS only the bundled engine's folder is considered: any other path is refused without asking codesign.
+ expect(await engineSignedByTeam(other, "darwin")).toBe(false);
expect(await engineSignedByTeam(other, "win32")).toBe(false);
// One hash per bundled architecture (macOS arm64 + x64), comma-separated.
expect(await releaseEngineBinary(bin, { release: true, engineSha256: ["f".repeat(64), sha].join(",") })).toBe(bin);
diff --git a/apps/server/src/release-guard.ts b/apps/server/src/release-guard.ts
index 68735824..076660c0 100644
--- a/apps/server/src/release-guard.ts
+++ b/apps/server/src/release-guard.ts
@@ -10,8 +10,8 @@
*/
import { execFile } from "node:child_process";
import { createHash } from "node:crypto";
-import { createReadStream } from "node:fs";
-import { isAbsolute } from "node:path";
+import { createReadStream, statSync } from "node:fs";
+import { basename, dirname, isAbsolute } from "node:path";
import { BUILD_VARIANT, RELEASE_ENGINE_SHA256 } from "./build-variant.js";
@@ -88,11 +88,19 @@ export const ENGINE_SIGNING_REQUIREMENT = `anchor apple generic and certificate
* notarization rewrite the engine after packaging records its sha256, so on macOS
* the signature, not the raw hash, says it is the bundled engine.
*/
+const signedCache = new Set<string>();
export function engineSignedByTeam(file: string, platform: NodeJS.Platform = process.platform): Promise<boolean> {
- if (platform !== "darwin") return Promise.resolve(false);
+ // Only the app's own bundled engine (<resources>/sidecars/...), and only on macOS.
+ if (platform !== "darwin" || basename(dirname(file)) !== "sidecars") return Promise.resolve(false);
+ let key: string;
+ try { const info = statSync(file); key = `${file}\0${info.size}\0${info.mtimeMs}`; } catch { return Promise.resolve(false); }
+ if (signedCache.has(key)) return Promise.resolve(true);
return new Promise((resolve) => {
try {
- execFile("/usr/bin/codesign", ["--verify", "--strict", `-R=${ENGINE_SIGNING_REQUIREMENT}`, file], { timeout: 20_000 }, (error) => resolve(!error));
+ execFile("/usr/bin/codesign", ["--verify", "--strict", `-R=${ENGINE_SIGNING_REQUIREMENT}`, file], { timeout: 20_000 }, (error) => {
+ if (!error) signedCache.add(key);
+ resolve(!error);
+ });
} catch {
resolve(false);
}