fix(native): keep path bytes out of signing reason classification
This commit is contained in:
@@ -50,6 +50,23 @@ describe("CodeDirectory flags", () => {
|
||||
});
|
||||
|
||||
describe("derived security facets", () => {
|
||||
it("does not apply platform policy for a reported zero platform byte", () => {
|
||||
expect(
|
||||
states(
|
||||
derive({
|
||||
signed: true,
|
||||
codeDirectory: directory(0x2, 0),
|
||||
entitlements: null,
|
||||
entitlementsKnown: true,
|
||||
appleOrigin: true,
|
||||
}),
|
||||
),
|
||||
).toMatchObject({
|
||||
"library-validation": "not-enforced",
|
||||
"dyld-environment-variables": "honored",
|
||||
"debugger-attach": "allowed",
|
||||
});
|
||||
});
|
||||
it("treats unsigned and plain ad hoc code as unrestricted", () => {
|
||||
for (const signed of [false, true])
|
||||
expect(
|
||||
|
||||
@@ -69,7 +69,7 @@ interface PostureInput {
|
||||
const platformBinary = (
|
||||
input: PostureInput,
|
||||
): "apple" | "unverified" | "none" =>
|
||||
(input.codeDirectory?.platform_identifier ?? null) === null
|
||||
(input.codeDirectory?.platform_identifier ?? 0) === 0
|
||||
? "none"
|
||||
: input.appleOrigin
|
||||
? "apple"
|
||||
|
||||
@@ -11,6 +11,20 @@ export const codesignReason = (line: string, path: string): string => {
|
||||
return line;
|
||||
};
|
||||
|
||||
/** Remove the complete selected path before splitting lines, including embedded LF bytes. */
|
||||
export const codesignReasons = (
|
||||
capture: NativeCommandCapture,
|
||||
path: string,
|
||||
): string[] => {
|
||||
const observed = `${capture.stderr}\n${capture.stdout}`;
|
||||
const text =
|
||||
path.length === 0 ? observed : observed.split(path).join("$SELECTED_PATH");
|
||||
return text
|
||||
.split("\n")
|
||||
.filter((line) => !/^--(?:prepared|validated):/u.test(line))
|
||||
.map((line) => codesignReason(line, "$SELECTED_PATH"));
|
||||
};
|
||||
|
||||
/** Classify only explicit diagnostic reasons; nonzero exit alone proves no invalidity. */
|
||||
const verificationStatus = (
|
||||
capture: NativeCommandCapture,
|
||||
@@ -59,7 +73,7 @@ export const signatureVerification = (
|
||||
path,
|
||||
status: verificationStatus(
|
||||
capture,
|
||||
diagnostics.map((line) => codesignReason(line, path)),
|
||||
codesignReasons(capture, path),
|
||||
unsigned,
|
||||
),
|
||||
exit_code: capture.exitCode,
|
||||
|
||||
@@ -116,10 +116,7 @@ export const inspectNativeSignature = async (options: {
|
||||
if (!verified.ok) return verified;
|
||||
const captures = [display, requirements, entitlements, verified.value];
|
||||
let appleOrigin = false;
|
||||
if (
|
||||
!unsigned &&
|
||||
(parsed.code_directory?.platform_identifier ?? null) !== null
|
||||
) {
|
||||
if (!unsigned && (parsed.code_directory?.platform_identifier ?? 0) !== 0) {
|
||||
const anchor = await capture(["--verify", "-R=anchor apple", code], signal);
|
||||
if (!anchor.ok) return anchor;
|
||||
captures.push(anchor.value);
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import { canonicalJson } from "../domain/comparisonSemantics.js";
|
||||
import { ok, type Result } from "../domain/result.js";
|
||||
import type { NativeCommandCapture } from "./CommandRunner.js";
|
||||
import { codesignReason } from "./CodesignVerification.js";
|
||||
import { codesignReasons } from "./CodesignVerification.js";
|
||||
import { parseCodeSignature } from "./parsers/codesign.js";
|
||||
import { parseSignatureEntitlements } from "./NativeSignatureEntitlements.js";
|
||||
import {
|
||||
@@ -24,13 +24,11 @@ export const unsignedSignatureCapture = (
|
||||
): boolean =>
|
||||
capture.exitCode !== null &&
|
||||
capture.exitCode !== 0 &&
|
||||
`${capture.stderr}\n${capture.stdout}`
|
||||
.split("\n")
|
||||
.some((line) =>
|
||||
/^(?:code object is not signed at all|code object is not signed|not signed at all)/iu.test(
|
||||
codesignReason(line, path),
|
||||
),
|
||||
);
|
||||
codesignReasons(capture, path).some((reason) =>
|
||||
/^(?:code object is not signed at all|code object is not signed|not signed at all)/iu.test(
|
||||
reason,
|
||||
),
|
||||
);
|
||||
|
||||
/** Slice observations and aggregate knowledge, with every contributing capture retained. */
|
||||
export interface SignatureSliceObservation {
|
||||
|
||||
@@ -47,3 +47,20 @@ it("keeps operational, unsigned, definite invalid and unrecognized failures dist
|
||||
expect(status("code object is not signed at all")).toBe("invalid");
|
||||
expect(status("unrecognized failure")).toBe("unknown");
|
||||
});
|
||||
|
||||
it("excludes complete selected paths with embedded newlines before classifying reasons", async () => {
|
||||
const path =
|
||||
"/Applications/permission denied\ncode object is not signed at all\nFixture.app";
|
||||
const capture = await new NativeFixtureRunner().run("codesign", [
|
||||
"--verify",
|
||||
path,
|
||||
]);
|
||||
if (!capture.ok) throw capture.error;
|
||||
const result = signatureVerification(
|
||||
{ ...capture.value, exitCode: 1, stderr: `${path}: invalid signature\n` },
|
||||
path,
|
||||
false,
|
||||
);
|
||||
expect(result.status).toBe("invalid");
|
||||
expect(result.diagnostics.join("\n")).toContain(path);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user