The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(release): refuse archives in the macOS module bundle, verify signatures, test staging and signing end to end
M3gA-Mind788af759c526
diff --git a/scripts/__tests__/macos-bundled-modules.test.mjs b/scripts/__tests__/macos-bundled-modules.test.mjsnew file mode 100644index 0000000000..6d4cc03baf--- /dev/null+++ b/scripts/__tests__/macos-bundled-modules.test.mjs@@ -0,0 +1,123 @@+// The macOS bundled-module signer and its check, end to end on a staged+// marker-layout bundle. Ad-hoc signing (`-`) needs no certificate, so this runs+// on any Mac. An ad-hoc signature has no Developer ID and no secure timestamp,+// so `check` reports exactly those two; every other problem it can report is+// asserted absent, or present after tampering, by name.+import assert from "node:assert/strict";+import { spawnSync } from "node:child_process";+import { createHash } from "node:crypto";+import {+ copyFileSync,+ mkdirSync,+ mkdtempSync,+ readFileSync,+ writeFileSync,+} from "node:fs";+import { tmpdir } from "node:os";+import { dirname, join, resolve } from "node:path";+import { test } from "node:test";+import { fileURLToPath } from "node:url";++const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..", "..");+const SCRIPT = join(ROOT, "scripts/release/macos-bundled-modules.sh");+const ENTITLEMENTS = join(+ ROOT,+ "crates/openhuman-app/entitlements.sidecar.plist",+);+const sha = (path) =>+ createHash("sha256").update(readFileSync(path)).digest("hex");+const run = (...args) =>+ spawnSync("bash", [SCRIPT, ...args], { encoding: "utf8" });++/** An app whose bundle holds one module in the macOS layout: library, allowlist, marker. */+function stagedApp() {+ const app = join(+ mkdtempSync(join(tmpdir(), "openhuman-sign-")),+ "OpenHuman.app",+ );+ const modules = join(app, "Contents/Resources/bundled-modules");+ const dir = join(modules, "demo/1.0.0/macos-15-arm64");+ mkdirSync(dir, { recursive: true });+ const library = join(dir, "libdemo.dylib");+ copyFileSync("/usr/bin/true", library); // any Mach-O will do+ writeFileSync(+ join(dir, "modules.toml"),+ `"libdemo.dylib" = "${sha(library)}"\n`,+ );+ writeFileSync(+ join(dir, "demo-1.0.0-macos-15-arm64.tar.gz.sha256"),+ `${"a".repeat(64)}\n`,+ );+ return { app, modules, dir, library };+}++test(+ "signing re-pins modules.toml, and check verifies both",+ {+ skip: process.platform !== "darwin",+ },+ () => {+ const { app, modules, dir, library } = stagedApp();+ const unsigned = sha(library);+ const marker = readFileSync(+ join(dir, "demo-1.0.0-macos-15-arm64.tar.gz.sha256"),+ "utf8",+ );++ const signed = run("sign", app, ENTITLEMENTS, "-");+ assert.equal(signed.status, 0, signed.stderr);+ assert.notEqual(sha(library), unsigned, "codesign rewrites the library");+ assert.equal(+ readFileSync(join(dir, "modules.toml"), "utf8"),+ `"libdemo.dylib" = "${sha(library)}"\n`,+ "the allowlist names the signed file",+ );+ assert.equal(+ readFileSync(+ join(dir, "demo-1.0.0-macos-15-arm64.tar.gz.sha256"),+ "utf8",+ ),+ marker,+ );++ const clean = run("check", modules);+ assert.equal(clean.status, 1, "ad-hoc is not Developer ID");+ assert.equal(+ clean.stdout,+ "[sign-check] UNSIGNED for notarization: no-developer-id no-timestamp: demo/1.0.0/macos-15-arm64/libdemo.dylib\n",+ );++ // One changed byte inside the signed code pages (the tail is unhashed+ // padding): the signature no longer verifies and the pin no longer matches.+ const bytes = readFileSync(library);+ bytes[20000] ^= 0xff;+ writeFileSync(library, bytes);+ const tampered = run("check", modules);+ assert.equal(tampered.status, 1);+ assert.match(tampered.stdout, /invalid-signature/);+ assert.match(tampered.stdout, /modules\.toml does not match its file/);+ },+);++test(+ "signing refuses a bundle that still ships a module archive",+ {+ skip: process.platform !== "darwin",+ },+ () => {+ const { app, dir } = stagedApp();+ writeFileSync(+ join(dir, "demo-1.0.0-macos-15-arm64.tar.gz"),+ "pinned bytes",+ );+ const result = run("sign", app, ENTITLEMENTS, "-");+ assert.equal(result.status, 1);+ assert.match(result.stderr, /module archives in the macOS bundle/);+ },+);++test("check fails when the bundle has no modules directory", () => {+ const result = run("check", join(tmpdir(), "openhuman-no-such-bundle"));+ assert.equal(result.status, 1);+ assert.match(result.stderr, /no bundled modules/);+});diff --git a/scripts/__tests__/stage-modules.test.mjs b/scripts/__tests__/stage-modules.test.mjsindex 180414a0b9..71bd239dbd 100644--- a/scripts/__tests__/stage-modules.test.mjs+++ b/scripts/__tests__/stage-modules.test.mjs@@ -4,6 +4,7 @@ import { createHash } from "node:crypto";import { tmpdir } from "node:os";import { join } from "node:path";import { createServer } from "node:http";+import { execFileSync } from "node:child_process";import { gzipSync } from "node:zlib";import { test } from "node:test";@@ -17,6 +18,7 @@ import {extractWindowsZip,keepsArchive,replaceArchiveWithMarker,+ stageModules,} from "../release/stage-modules.mjs";const HOST_KEYS = [@@ -171,3 +173,37 @@ test("a stalled download times out instead of hanging", async () => {},);});++for (const hostKey of ["macos-15-arm64", "ubuntu-22.04-x86_64"]) {+ test(`stageModules on ${hostKey} ${keepsArchive(hostKey) ? "keeps the archive" : "replaces the archive with its verified digest"}`, async () => {+ const root = mkdtempSync(join(tmpdir(), "openhuman-stage-"));+ const source = join(root, "src");+ mkdirSync(source);+ const library = hostKey.startsWith("macos-") ? "libdemo.dylib" : "libdemo.so";+ writeFileSync(join(source, library), "library bytes");+ const archiveName = `demo-1.0.0-${hostKey}.tar.gz`;+ const built = join(root, archiveName);+ execFileSync("tar", ["-czf", built, "-C", source, library]);+ const bytes = readFileSync(built);+ const sha256 = createHash("sha256").update(bytes).digest("hex");+ const output = join(root, "out");++ await withServer((req, res) => res.end(bytes), async (url) => {+ await stageModules({+ hostKey,+ output,+ assets: [{ id: "demo", version: "1.0.0", hostKey, archive: archiveName, url, sha256 }],+ });+ });++ const dir = join(output, "demo", "1.0.0", hostKey);+ assert.equal(readFileSync(join(dir, library), "utf8"), "library bytes");+ if (keepsArchive(hostKey)) {+ assert.deepEqual(readFileSync(join(dir, archiveName)), bytes);+ assert.equal(existsSync(join(dir, `${archiveName}.sha256`)), false);+ } else {+ assert.equal(existsSync(join(dir, archiveName)), false, "the archive must not ship");+ assert.equal(readFileSync(join(dir, `${archiveName}.sha256`), "utf8"), `${sha256}\n`);+ }+ });+}diff --git a/scripts/release/macos-bundled-modules.sh b/scripts/release/macos-bundled-modules.shindex dd5cb1b1ab..85f14e6618 100755--- a/scripts/release/macos-bundled-modules.sh+++ b/scripts/release/macos-bundled-modules.sh@@ -19,7 +19,7 @@# the app's seal, as it does for the archive marker. Nothing else changes.## check: fail when any Mach-O under the directory — loose, or inside a shipped-# .tar.gz — lacks what notarization demands: a Developer ID signature,+# .tar.gz — lacks what notarization demands: a valid Developer ID signature,# hardened runtime and a secure timestamp. Apple's notary service unpacks# nested archives, so archive members count too. Also fail when a# modules.toml entry is not the sha256 of the file it names: a sign without@@ -49,6 +49,15 @@ case "$cmd" inAPP_PATH="${2:?sign needs <app_path>}"ENTITLEMENTS="${3:?sign needs <entitlements_plist>}"IDENTITY="${4:?sign needs <identity>}"+ # A pinned archive cannot be signed without changing the pinned bytes, and+ # notarization unpacks it; on macOS stage-modules.mjs replaces each one+ # with its `.sha256` marker. One here means staging went wrong.+ archives="$(find "$APP_PATH/Contents/Resources/bundled-modules" -name '*.tar.gz' -type f 2>/dev/null)"+ if [ -n "$archives" ]; then+ echo "[sign] ERROR: module archives in the macOS bundle (stage-modules.mjs should have replaced them):" >&2+ echo "$archives" >&2+ exit 1+ fiwhile IFS= read -r -d '' bin; dofile -b "$bin" | grep -q '^Mach-O' || continueecho "[sign] Signing bundled module: ${bin#"$APP_PATH/Contents/Resources/"}"@@ -73,6 +82,9 @@ case "$cmd" infile -b "$f" | grep -q '^Mach-O' || continueinfo="$(codesign -dvv "$f" 2>&1 || true)"problems=""+ # -dvv only reads the signature's metadata; this checks it still+ # matches the file.+ codesign --verify --strict "$f" >/dev/null 2>&1 || problems+=" invalid-signature"grep -q '^Authority=Developer ID Application' <<<"$info" || problems+=" no-developer-id"grep -q '^Timestamp=' <<<"$info" || problems+=" no-timestamp"grep -q '^CodeDirectory.*flags=.*runtime' <<<"$info" || problems+=" no-hardened-runtime"diff --git a/scripts/release/stage-modules.mjs b/scripts/release/stage-modules.mjsindex e49a5baa51..ac3a8457ef 100644--- a/scripts/release/stage-modules.mjs+++ b/scripts/release/stage-modules.mjs@@ -188,8 +188,11 @@ export async function download(url, destination, timeoutMs = DOWNLOAD_TIMEOUT_MSthrow new Error(`download of ${url} failed: ${lastError}`);}-export async function stageModules({ hostKey = defaultHostKey(), output = OUTPUT } = {}) {- const assets = bundledAssets(readRegistrySource(), hostKey);+export async function stageModules({+ hostKey = defaultHostKey(),+ output = OUTPUT,+ assets = bundledAssets(readRegistrySource(), hostKey),+} = {}) {rmSync(output, { recursive: true, force: true });mkdirSync(output, { recursive: true });writeFileSync(join(output, ".gitkeep"), "");