fix(native): require Apple origin for platform facets and keep cancellation
- Treat a CodeDirectory platform identifier as a platform binary only when the signature satisfies `anchor apple`, checked with `codesign --verify -R="anchor apple"`; otherwise the dependent facets are unknown. Developer ID code chains to Apple Root CA but fails this check. - Report every security facet as unknown when architecture slices differ in signing state. - Map an aborted signal that escapes a native helper, such as ticket hashing, to AnalysisCancelledError instead of an output error. - Treat a target as an app bundle only when it was opened from a bundle directory, so a regular file named X.app is verified as a bare Mach-O. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
73eb20a4b9
commit
ce8e969112
@@ -5,6 +5,7 @@ import { join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { NativeMacOSProvider } from "../../../../src/native/NativeMacOSProvider.js";
|
||||
import { AnalysisCancelledError } from "../../../../src/domain/analysisErrorCore.js";
|
||||
import { ok } from "../../../../src/domain/result.js";
|
||||
import { inspectSignatureSchema } from "../../../../src/domain/nativeInspection.js";
|
||||
import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js";
|
||||
@@ -177,6 +178,68 @@ describe("native signature posture", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("native signature posture boundaries", () => {
|
||||
it("treats a regular file named .app as a bare Mach-O", async () => {
|
||||
const directory = await createTestTempDirectory("rea-signature-file-");
|
||||
const executable = join(directory, "Tool.app");
|
||||
await writeFile(executable, "fixture");
|
||||
const signature = await new NativeMacOSProvider(
|
||||
new FixtureRunner(),
|
||||
"darwin",
|
||||
)
|
||||
.createClient({ ...machoTarget(executable), sourcePath: executable })
|
||||
.execute("inspect_signature", {});
|
||||
expect(signature.ok && signature.value.result).toMatchObject({
|
||||
verification: { path: executable },
|
||||
stapled_ticket: { status: "not-applicable" },
|
||||
});
|
||||
});
|
||||
|
||||
it("applies platform policy only after the signature satisfies anchor apple", async () => {
|
||||
const { app, executable } = await fixtureApp(undefined);
|
||||
const facets = async (anchorExit: number) => {
|
||||
const signature = await new NativeMacOSProvider(
|
||||
new PlatformRunner(anchorExit),
|
||||
"darwin",
|
||||
)
|
||||
.createClient(machoTarget(executable, app))
|
||||
.execute("inspect_signature", {});
|
||||
if (!signature.ok) throw signature.error;
|
||||
const result = inspectSignatureSchema.parse(signature.value.result);
|
||||
expect(result.provenance.map(({ command }) => command.at(-2))).toContain(
|
||||
"-R=anchor apple",
|
||||
);
|
||||
return Object.fromEntries(
|
||||
result.security_facets.map(({ facet, state }) => [facet, state]),
|
||||
);
|
||||
};
|
||||
expect(await facets(0)).toMatchObject({
|
||||
"library-validation": "enforced",
|
||||
"dyld-environment-variables": "ignored",
|
||||
"debugger-attach": "blocked",
|
||||
});
|
||||
expect(await facets(3)).toMatchObject({
|
||||
"library-validation": "unknown",
|
||||
"dyld-environment-variables": "unknown",
|
||||
"debugger-attach": "unknown",
|
||||
});
|
||||
});
|
||||
|
||||
it("reports cancellation while hashing the stapled ticket", async () => {
|
||||
const { app, executable } = await fixtureApp("ticket");
|
||||
const controller = new AbortController();
|
||||
const signature = await new NativeMacOSProvider(
|
||||
new AbortAfterVerifyRunner(controller),
|
||||
"darwin",
|
||||
)
|
||||
.createClient(machoTarget(executable, app))
|
||||
.execute("inspect_signature", {}, { signal: controller.signal });
|
||||
expect(signature.ok).toBe(false);
|
||||
if (signature.ok) return;
|
||||
expect(signature.error).toBeInstanceOf(AnalysisCancelledError);
|
||||
});
|
||||
});
|
||||
|
||||
/** A signed bundle whose nested helper is unsigned. */
|
||||
class UnsignedNestedRunner extends FixtureRunner {
|
||||
override async run(tool: string, arguments_: readonly string[]) {
|
||||
@@ -194,3 +257,37 @@ class UnsignedNestedRunner extends FixtureRunner {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/** A platform binary whose `anchor apple` requirement check exits as given. */
|
||||
class PlatformRunner extends FixtureRunner {
|
||||
constructor(private readonly anchorExit: number) {
|
||||
super();
|
||||
}
|
||||
|
||||
override async run(tool: string, arguments_: readonly string[]) {
|
||||
const result = await super.run(tool, arguments_);
|
||||
if (!result.ok || tool !== "codesign") return result;
|
||||
if (arguments_.includes("-R=anchor apple"))
|
||||
return ok({ ...result.value, exitCode: this.anchorExit });
|
||||
if (!arguments_.includes("--verbose=4")) return result;
|
||||
const stderr = `${result.value.stderr}Platform identifier=26\n`;
|
||||
return ok({
|
||||
...result.value,
|
||||
stderr,
|
||||
stderrBytes: Buffer.byteLength(stderr),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/** Cancel the request once local verification has finished. */
|
||||
class AbortAfterVerifyRunner extends FixtureRunner {
|
||||
constructor(private readonly controller: AbortController) {
|
||||
super();
|
||||
}
|
||||
|
||||
override async run(tool: string, arguments_: readonly string[]) {
|
||||
const result = await super.run(tool, arguments_);
|
||||
if (arguments_[0] === "--verify") this.controller.abort();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+9
-2
@@ -1,4 +1,5 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import type { BinaryTarget } from "../../src/domain/binaryTarget.js";
|
||||
import { ok } from "../../src/domain/result.js";
|
||||
import type {
|
||||
@@ -95,10 +96,16 @@ const capture = (
|
||||
/** Build the Mach-O target identity used by native boundary fixtures. */
|
||||
export const nativeMachoTarget = (
|
||||
path: string,
|
||||
sourcePath?: string,
|
||||
/** The app bundle directory the target was opened from. */
|
||||
bundle?: string,
|
||||
): BinaryTarget => ({
|
||||
path,
|
||||
...(sourcePath === undefined ? {} : { sourcePath }),
|
||||
...(bundle === undefined
|
||||
? {}
|
||||
: {
|
||||
sourcePath: bundle,
|
||||
bundleInfoPlist: join(bundle, "Contents/Info.plist"),
|
||||
}),
|
||||
sha256: "0".repeat(64),
|
||||
kind: "executable",
|
||||
format: "mach-o",
|
||||
|
||||
Reference in New Issue
Block a user