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
@@ -24,6 +24,13 @@ const directory = (
|
||||
executable_segment_flags: 1,
|
||||
});
|
||||
|
||||
type PostureInput = Parameters<typeof deriveSecurityFacets>[0];
|
||||
|
||||
const derive = (
|
||||
input: Omit<PostureInput, "mixedSlices" | "appleOrigin"> &
|
||||
Partial<PostureInput>,
|
||||
) => deriveSecurityFacets({ mixedSlices: false, appleOrigin: false, ...input });
|
||||
|
||||
const states = (facets: ReturnType<typeof deriveSecurityFacets>) =>
|
||||
Object.fromEntries(facets.map(({ facet, state }) => [facet, state]));
|
||||
|
||||
@@ -47,7 +54,7 @@ describe("derived security facets", () => {
|
||||
for (const signed of [false, true])
|
||||
expect(
|
||||
states(
|
||||
deriveSecurityFacets({
|
||||
derive({
|
||||
signed,
|
||||
codeDirectory: signed ? directory(0x2) : null,
|
||||
entitlements: null,
|
||||
@@ -66,7 +73,7 @@ describe("derived security facets", () => {
|
||||
it("restricts hardened-runtime code unless entitlements relax it", () => {
|
||||
expect(
|
||||
states(
|
||||
deriveSecurityFacets({
|
||||
derive({
|
||||
signed: true,
|
||||
codeDirectory: directory(RUNTIME),
|
||||
entitlements: { "com.apple.security.app-sandbox": true },
|
||||
@@ -80,7 +87,7 @@ describe("derived security facets", () => {
|
||||
"executable-memory": "restricted",
|
||||
"app-sandbox": "sandboxed",
|
||||
});
|
||||
const relaxed = deriveSecurityFacets({
|
||||
const relaxed = derive({
|
||||
signed: true,
|
||||
codeDirectory: directory(RUNTIME),
|
||||
entitlements: {
|
||||
@@ -104,7 +111,7 @@ describe("derived security facets", () => {
|
||||
});
|
||||
|
||||
it("lets explicit flags and platform identity override entitlements", () => {
|
||||
const flagged = deriveSecurityFacets({
|
||||
const flagged = derive({
|
||||
signed: true,
|
||||
codeDirectory: directory(0x2000 | 0x800 | RUNTIME),
|
||||
entitlements: {
|
||||
@@ -118,11 +125,12 @@ describe("derived security facets", () => {
|
||||
});
|
||||
expect(
|
||||
states(
|
||||
deriveSecurityFacets({
|
||||
derive({
|
||||
signed: true,
|
||||
codeDirectory: directory(RUNTIME, 26),
|
||||
entitlements: null,
|
||||
entitlementsKnown: true,
|
||||
appleOrigin: true,
|
||||
}),
|
||||
),
|
||||
).toMatchObject({
|
||||
@@ -131,11 +139,48 @@ describe("derived security facets", () => {
|
||||
"debugger-attach": "blocked",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("security facets that need more than one CodeDirectory", () => {
|
||||
it("applies platform policy only to Apple-signed platform identifiers", () => {
|
||||
const crafted = derive({
|
||||
signed: true,
|
||||
codeDirectory: directory(0, 26),
|
||||
entitlements: null,
|
||||
entitlementsKnown: true,
|
||||
});
|
||||
expect(states(crafted)).toMatchObject({
|
||||
"library-validation": "unknown",
|
||||
"dyld-environment-variables": "unknown",
|
||||
"debugger-attach": "unknown",
|
||||
});
|
||||
expect(crafted[0]?.evidence).toEqual([
|
||||
"platform identifier",
|
||||
"Apple origin not verified",
|
||||
]);
|
||||
});
|
||||
|
||||
it("leaves every facet unknown when slices differ in signing state", () => {
|
||||
const mixed = derive({
|
||||
signed: true,
|
||||
codeDirectory: directory(0x2000 | RUNTIME, 26),
|
||||
entitlements: null,
|
||||
entitlementsKnown: false,
|
||||
appleOrigin: true,
|
||||
mixedSlices: true,
|
||||
});
|
||||
expect(new Set(mixed.map(({ state }) => state))).toEqual(
|
||||
new Set(["unknown"]),
|
||||
);
|
||||
expect(mixed[0]?.evidence).toEqual([
|
||||
"architecture slices differ in signing state",
|
||||
]);
|
||||
});
|
||||
|
||||
it("keeps facets unknown when flags or entitlements are unavailable", () => {
|
||||
expect(
|
||||
states(
|
||||
deriveSecurityFacets({
|
||||
derive({
|
||||
signed: true,
|
||||
codeDirectory: directory(RUNTIME),
|
||||
entitlements: null,
|
||||
@@ -151,7 +196,7 @@ describe("derived security facets", () => {
|
||||
});
|
||||
expect(
|
||||
states(
|
||||
deriveSecurityFacets({
|
||||
derive({
|
||||
signed: true,
|
||||
codeDirectory: directory(null),
|
||||
entitlements: null,
|
||||
|
||||
@@ -146,8 +146,30 @@ interface PostureInput {
|
||||
readonly entitlements: JsonValue | null;
|
||||
/** False when mixed or unreadable signing states hide the aggregate entitlements. */
|
||||
readonly entitlementsKnown: boolean;
|
||||
/** Architecture slices differ in signing state, so no one CodeDirectory describes the process. */
|
||||
readonly mixedSlices: boolean;
|
||||
/**
|
||||
* The signature satisfies `anchor apple`. Only then does a CodeDirectory
|
||||
* platform identifier mean an Apple platform binary.
|
||||
*/
|
||||
readonly appleOrigin: boolean;
|
||||
}
|
||||
|
||||
/** Whether the CodeDirectory claims a platform binary, and whether Apple signed it. */
|
||||
const platformBinary = (
|
||||
input: PostureInput,
|
||||
): "apple" | "unverified" | "none" =>
|
||||
(input.codeDirectory?.platform_identifier ?? null) === null
|
||||
? "none"
|
||||
: input.appleOrigin
|
||||
? "apple"
|
||||
: "unverified";
|
||||
|
||||
const UNVERIFIED_PLATFORM = [
|
||||
"platform identifier",
|
||||
"Apple origin not verified",
|
||||
] as const;
|
||||
|
||||
const has = (input: PostureInput, flag: string): boolean =>
|
||||
input.codeDirectory?.flags?.names.includes(flag) === true;
|
||||
|
||||
@@ -169,13 +191,21 @@ const libraryValidation = (input: PostureInput): SecurityFacet => {
|
||||
evidence: ["CodeDirectory flags unavailable"],
|
||||
explanation,
|
||||
};
|
||||
if (input.codeDirectory.platform_identifier !== null)
|
||||
return {
|
||||
...base,
|
||||
state: "enforced",
|
||||
evidence: ["platform binary"],
|
||||
explanation,
|
||||
};
|
||||
const platform = platformBinary(input);
|
||||
if (platform !== "none")
|
||||
return platform === "apple"
|
||||
? {
|
||||
...base,
|
||||
state: "enforced",
|
||||
evidence: ["platform binary"],
|
||||
explanation,
|
||||
}
|
||||
: {
|
||||
...base,
|
||||
state: "unknown",
|
||||
evidence: [...UNVERIFIED_PLATFORM],
|
||||
explanation,
|
||||
};
|
||||
if (has(input, "library-validation"))
|
||||
return {
|
||||
...base,
|
||||
@@ -232,13 +262,21 @@ const dyldEnvironment = (input: PostureInput): SecurityFacet => {
|
||||
evidence: ["CodeDirectory flag restrict"],
|
||||
explanation,
|
||||
};
|
||||
if ((input.codeDirectory?.platform_identifier ?? null) !== null)
|
||||
return {
|
||||
...base,
|
||||
state: "ignored",
|
||||
evidence: ["platform binary"],
|
||||
explanation,
|
||||
};
|
||||
const platform = platformBinary(input);
|
||||
if (platform !== "none")
|
||||
return platform === "apple"
|
||||
? {
|
||||
...base,
|
||||
state: "ignored",
|
||||
evidence: ["platform binary"],
|
||||
explanation,
|
||||
}
|
||||
: {
|
||||
...base,
|
||||
state: "unknown",
|
||||
evidence: [...UNVERIFIED_PLATFORM],
|
||||
explanation,
|
||||
};
|
||||
if (!has(input, "runtime"))
|
||||
return input.signed && (input.codeDirectory?.flags ?? null) === null
|
||||
? {
|
||||
@@ -296,13 +334,21 @@ const debuggerAttach = (input: PostureInput): SecurityFacet => {
|
||||
evidence: ["com.apple.security.get-task-allow"],
|
||||
explanation,
|
||||
};
|
||||
if ((input.codeDirectory?.platform_identifier ?? null) !== null)
|
||||
return {
|
||||
...base,
|
||||
state: "blocked",
|
||||
evidence: ["platform binary"],
|
||||
explanation,
|
||||
};
|
||||
const platform = platformBinary(input);
|
||||
if (platform !== "none")
|
||||
return platform === "apple"
|
||||
? {
|
||||
...base,
|
||||
state: "blocked",
|
||||
evidence: ["platform binary"],
|
||||
explanation,
|
||||
}
|
||||
: {
|
||||
...base,
|
||||
state: "unknown",
|
||||
evidence: [...UNVERIFIED_PLATFORM],
|
||||
explanation,
|
||||
};
|
||||
if (has(input, "runtime"))
|
||||
return input.entitlementsKnown
|
||||
? {
|
||||
@@ -411,10 +457,21 @@ const appSandbox = (input: PostureInput): SecurityFacet => {
|
||||
};
|
||||
|
||||
/** Derive launch-time security facets from observed flags and entitlements. */
|
||||
export const deriveSecurityFacets = (input: PostureInput): SecurityFacet[] => [
|
||||
libraryValidation(input),
|
||||
dyldEnvironment(input),
|
||||
debuggerAttach(input),
|
||||
executableMemory(input),
|
||||
appSandbox(input),
|
||||
];
|
||||
export const deriveSecurityFacets = (input: PostureInput): SecurityFacet[] => {
|
||||
const facets = [
|
||||
libraryValidation(input),
|
||||
dyldEnvironment(input),
|
||||
debuggerAttach(input),
|
||||
executableMemory(input),
|
||||
appSandbox(input),
|
||||
];
|
||||
// Each slice runs under its own signature; the inspected one does not
|
||||
// describe an unsigned slice of the same file.
|
||||
return input.mixedSlices
|
||||
? facets.map((facet) => ({
|
||||
...facet,
|
||||
state: "unknown" as const,
|
||||
evidence: ["architecture slices differ in signing state"],
|
||||
}))
|
||||
: facets;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user