fix(native): preserve verification captures and separate path fragments

This commit is contained in:
morluto
2026-10-08 20:35:31 +08:00
parent fa68ca054c
commit 1a5eec54e1
11 changed files with 108 additions and 31 deletions
+3
View File
@@ -33,6 +33,9 @@ export const signatureVerificationSchema = z.object({
exit_code: z.number().int().nullable(),
diagnostics: z.array(z.string()),
validated_nested_code: z.array(z.string()),
prepared_nested_code: z.array(z.string()).default([]),
raw_stdout: z.string().default(""),
raw_stderr: z.string().default(""),
});
/** Local ticket presence and content identity, without a remote notarization claim. */
+28 -4
View File
@@ -19,10 +19,23 @@ export const codesignReasons = (
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"));
const lines = text.split("\n");
const progress = lines.some((line) =>
/^--(?:prepared|validated):/u.test(line),
);
return (
lines
.filter((line) => !/^--(?:prepared|validated):/u.test(line))
// Unprefixed continuation text can belong to an unescaped nested filename.
// Keep it as raw evidence, but do not turn it into a verification reason.
.filter(
(line) =>
!progress ||
line.startsWith("$SELECTED_PATH: ") ||
line.startsWith("$SELECTED_PATH/"),
)
.map((line) => codesignReason(line, "$SELECTED_PATH"))
);
};
/** Classify only explicit diagnostic reasons; nonzero exit alone proves no invalidity. */
@@ -83,6 +96,17 @@ export const signatureVerification = (
),
exit_code: capture.exitCode,
diagnostics,
prepared_nested_code: [
...new Set(
lines.flatMap((line) =>
line.startsWith("--prepared:")
? [line.slice("--prepared:".length)]
: [],
),
),
].sort(),
raw_stdout: capture.stdout,
raw_stderr: capture.stderr,
validated_nested_code: [
...new Set(
lines.flatMap((line) =>
-4
View File
@@ -7,10 +7,6 @@ it("observes cancellation between nested filesystem lookups", async () => {
await expect(
unconfirmedNestedCode(
{
path: "/app",
status: "valid",
exit_code: 0,
diagnostics: [],
validated_nested_code: ["/app/first", "/app/second"],
},
controller.signal,
+1 -2
View File
@@ -1,6 +1,5 @@
import { lstat, readdir } from "node:fs/promises";
import { dirname } from "node:path";
import type { InspectSignature } from "../domain/native/nativeInspection.js";
/** Filesystem seam for path-completeness checks and cancellation regressions. */
export interface NativeNestedPathView {
@@ -20,7 +19,7 @@ const errorCode = (cause: unknown) =>
/** Preserve reported paths, but qualify missing, denied or newline-ambiguous records. */
export const unconfirmedNestedCode = async (
verification: NonNullable<InspectSignature["verification"]>,
verification: { readonly validated_nested_code: readonly string[] },
signal?: AbortSignal,
view: NativeNestedPathView = FILE_SYSTEM,
): Promise<string[]> => {
+11 -5
View File
@@ -1,5 +1,5 @@
import { createHash } from "node:crypto";
import { constants } from "node:fs";
import { constants, type Stats } from "node:fs";
import { lstat, open } from "node:fs/promises";
import { join } from "node:path";
@@ -56,6 +56,9 @@ const bundleDirFromPlist = (plist: string): string | undefined => {
export const stapledTicket = async (
target: { readonly sourcePath?: string; readonly bundleInfoPlist?: string },
signal?: AbortSignal,
pathProbe: (path: string, phase: "before" | "after") => Promise<Stats> = (
path,
) => lstat(path),
): Promise<InspectSignature["stapled_ticket"]> => {
signal?.throwIfAborted();
const bundle = appBundle(target);
@@ -73,7 +76,7 @@ export const stapledTicket = async (
const path = join(bundle, relative);
try {
signal?.throwIfAborted();
const metadata = await lstat(path);
const metadata = await pathProbe(path, "before");
if (!metadata.isFile()) {
signal?.throwIfAborted();
return absent;
@@ -147,7 +150,7 @@ export const stapledTicket = async (
// handle still describes the unlinked original: re-resolve the path and
// refuse a digest that no longer belongs to the bundle.
try {
const current = await lstat(path);
const current = await pathProbe(path, "after");
if (!sameTicketFile(current, opened))
return {
status: "unreadable",
@@ -156,7 +159,10 @@ export const stapledTicket = async (
size: null,
reason: "changed",
};
} catch {
} catch (cause: unknown) {
signal?.throwIfAborted();
const code = errorCode(cause);
if (code !== "ENOENT" && code !== "ENOTDIR") throw cause;
return {
status: "unreadable",
path: relative,
@@ -180,7 +186,7 @@ export const stapledTicket = async (
if (code === "ENOENT" || code === "ENOTDIR") return absent;
// A privacy or ACL denial leaves the ticket's presence unknown, not the
// whole signature inspection.
if (code === "EACCES" || code === "EPERM")
if (code === "EACCES" || code === "EPERM" || code === "EIO")
return {
status: "unreadable",
path: relative,