From f7b33cc553806f6704930064de31f58cf926e1fd Mon Sep 17 00:00:00 2001 From: Dotta Date: Mon, 28 Sep 2026 11:33:51 -0500 Subject: [PATCH] Verify Cursor package assets through an exact native profile factory Co-Authored-By: Paperclip --- .../drivers/acpx/cursor-installation.test.ts | 34 ++++++++++++++ .../src/drivers/acpx/cursor-installation.ts | 45 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 packages/paperclip-runner/src/drivers/acpx/cursor-installation.test.ts create mode 100644 packages/paperclip-runner/src/drivers/acpx/cursor-installation.ts diff --git a/packages/paperclip-runner/src/drivers/acpx/cursor-installation.test.ts b/packages/paperclip-runner/src/drivers/acpx/cursor-installation.test.ts new file mode 100644 index 00000000000..077c7460fc8 --- /dev/null +++ b/packages/paperclip-runner/src/drivers/acpx/cursor-installation.test.ts @@ -0,0 +1,34 @@ +import { readFile } from "node:fs/promises"; +import { join } from "node:path"; +import { expect, it } from "vitest"; +import { CURSOR_PINNED_VERSION, cursorNativeDistributionSpec, verifyCursorInstallation } from "./cursor-installation.js"; +import { QUALIFIED_ACPX_PROFILES } from "./qualified-profiles.js"; + +it("matches build materializer pins and launches only package-owned complete distributions", async () => { + const manifest = JSON.parse(await readFile(new URL("../../../cursor-distributions.json", import.meta.url), "utf8")); + expect(manifest.version).toBe(CURSOR_PINNED_VERSION); + for (const [platform, architecture] of [["darwin", "arm64"], ["darwin", "x64"], ["linux", "x64"]] as const) { + const spec = cursorNativeDistributionSpec(platform, architecture); + expect(spec.expectedClosureSha256).toBe(manifest.platforms[`${platform}-${architecture}`].closureSha256); + expect(spec.distributionRoot).toBe(new URL(`../../../provider-assets/cursor/${platform}-${architecture}`, import.meta.url).pathname); + expect(spec.manifestPath).toBe(join(spec.distributionRoot, ".paperclip-cursor-closure.json")); + expect(spec.executable).toBe("node"); + expect(spec.entrypoint).toBe("index.js"); + expect(spec.fixedArguments).toEqual(["--disable-project-configs", "--disable-auto-update", "acp"]); + (spec.fixedArguments as string[]).push("--force"); + expect(cursorNativeDistributionSpec(platform, architecture).fixedArguments).not.toContain("--force"); + } +}); + +it("rejects profile substitutions before reading any native distribution", async () => { + const base = { ...QUALIFIED_ACPX_PROFILES.cursor, qualificationModel: "explicit", reportedModelId: "explicit" }; + for (const profile of [QUALIFIED_ACPX_PROFILES.cursor, { ...base, agentServerVersion: "latest" }, { ...base, commandDigest: "forged" }, { ...base, reportedModelId: "different" }]) { + await expect(verifyCursorInstallation(profile)).rejects.toThrow("exact pinned profile"); + } +}); + +it("fails closed on unknown platforms instead of ambient executable discovery", () => { + expect(() => cursorNativeDistributionSpec("linux", "arm64")).toThrow("no pinned distribution"); + expect(() => cursorNativeDistributionSpec("win32", "x64")).toThrow("no pinned distribution"); + expect(() => cursorNativeDistributionSpec("darwin", "../../workspace")).toThrow("no pinned distribution"); +}); diff --git a/packages/paperclip-runner/src/drivers/acpx/cursor-installation.ts b/packages/paperclip-runner/src/drivers/acpx/cursor-installation.ts new file mode 100644 index 00000000000..edda80afbbc --- /dev/null +++ b/packages/paperclip-runner/src/drivers/acpx/cursor-installation.ts @@ -0,0 +1,45 @@ +import { join } from "node:path"; + +import { verifyNativeAcpxInstallation, type VerifiedAcpxInstallation } from "./installation-integrity.js"; +import type { NativeAcpxDistributionInput } from "./native-distribution-integrity.js"; +import { CURSOR_FIXED_ARGUMENTS } from "./cursor-launch-policy.js"; +import { QUALIFIED_ACPX_PROFILES, type QualifiedAcpxProfile } from "./qualified-profiles.js"; +import { resolveRunnerProviderAssetsRoot } from "./provider-assets-root.js"; + +export const CURSOR_PINNED_VERSION = "2026.09.26-dd393fe"; +const CLOSURE_PINS = Object.freeze({ + "darwin-arm64": "77394184a89b0e7384971181da19c3c82d83a399b04e7944b3f94fe3d7e62b25", + "darwin-x64": "7c8775160af74e5fb8d25a30e8412c1a6476b0661529078a686e5118fd1c5e5f", + "linux-x64": "bf04ef8ea6a63191067a6b3e15139aa2c793d8419daab246aa3f0a012e1bbcd9", +}); + +/** Trusted package assets only: no workspace, PATH, executable override or env root. */ +export function cursorNativeDistributionSpec( + platform: NodeJS.Platform = process.platform, + architecture: string = process.arch, +): NativeAcpxDistributionInput { + const key = `${platform}-${architecture}`; + if (!Object.hasOwn(CLOSURE_PINS, key)) throw new Error(`Cursor ${CURSOR_PINNED_VERSION} has no pinned distribution for ${key}`); + const distributionRoot = join(resolveRunnerProviderAssetsRoot(import.meta.url, "cursor"), key); + return { + distributionRoot, + manifestPath: join(distributionRoot, ".paperclip-cursor-closure.json"), + expectedClosureSha256: CLOSURE_PINS[key as keyof typeof CLOSURE_PINS], + executable: "node", + entrypoint: "index.js", + fixedArguments: [...CURSOR_FIXED_ARGUMENTS], + }; +} + +/** Verifies launch bytes, not qualification. Profile admission remains separate. */ +export async function verifyCursorInstallation(profile: QualifiedAcpxProfile): Promise { + const trusted = QUALIFIED_ACPX_PROFILES.cursor; + const modelFields = new Set(["qualificationModel", "reportedModelId"]); + if (Object.keys(profile).some(key => !Object.hasOwn(trusted, key)) + || Object.entries(trusted).some(([key, value]) => !modelFields.has(key) && profile[key as keyof QualifiedAcpxProfile] !== value) + || !profile.qualificationModel.trim() || profile.reportedModelId !== profile.qualificationModel) { + throw new Error("Cursor installation requires the exact pinned profile and an explicit model"); + } + const installation = await verifyNativeAcpxInstallation(cursorNativeDistributionSpec()); + return { ...installation, commandDigest: trusted.commandDigest }; +}