Files
reverse-engineering-anything/tests/acceptance/applications/bundleResourceTargetIdentity.test.ts
T
8c7977f174 fix(native)!: require separate inspection for plists outside bundles (#9754)
* fix(native): record inspected plist bytes and refuse files outside the bundle

An open app session keeps the executable as the Evidence subject for
inspect_plist, same as the other bundle-resource tools, but the result had
no digest of the plist bytes and any absolute path was sealed under that
subject. Record source_sha256 for the bytes read, and refuse a selection
that resolves outside the opened bundle.

Fixes #9479

* fix(native)!: scope plist selection to the opened bundle

BREAKING CHANGE: To inspect a plist outside an opened app bundle or resource root, open the plist as a separate target.

* fix(native): report plist snapshot filesystem effects

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
2026-11-19 21:35:17 -05:00

120 lines
4.9 KiB
TypeScript

import { fileIdentity } from "../../fixtures/evidenceSubject.js";
import { createHash } from "node:crypto";
import { mkdir, readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect } from "vitest";
import { thinMach } from "../../../src/domain/binaryTarget.fixture.js";
import { interfaceBuilderAnalysisSchema } from "../../../src/domain/apple/interfaceBuilderGraph.js";
import { keyedArchiveResultSchema } from "../../../src/domain/apple/keyedArchive.js";
import { inspectPlistSchema } from "../../../src/domain/native/nativeInspection.js";
import { parseEvidence } from "../../../src/domain/evidence.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { connectLocalToolsMcp } from "../../fixtures/localToolsMcp.js";
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
import { cliTest } from "../../support/cli/cliFixture.js";
cliTest.for([
"decode_interface_builder",
"inspect_keyed_archive",
...(process.platform === "darwin"
? ["inspect_asset_catalog", "inspect_plist"]
: []),
] as const)(
"binds live %s Evidence to the open executable through stdio MCP",
async (operation) => {
const root = await createTestTempDirectory("rea-bundle-resource-identity-");
const app = join(root, "Probe.app");
const contents = join(app, "Contents");
const resources = join(contents, "Resources");
await mkdir(resources, { recursive: true });
await mkdir(join(contents, "MacOS"));
const executable = join(contents, "MacOS", "Probe");
const original = thinMach(0xfeedfacf, 0x0100000c);
await writeFile(executable, original);
await writeFile(
join(contents, "Info.plist"),
"<plist><dict><key>CFBundleExecutable</key><string>Probe</string></dict></plist>",
);
const nib = await readFile(
join(process.cwd(), "tests/fixtures/interface-builder/UIKitOutlet.xml"),
"utf8",
);
const nibPath = join(resources, "Main.nib");
await writeFile(nibPath, nib);
const { call } = await connectLocalToolsMcp();
const parameters =
operation === "inspect_keyed_archive"
? { path: "Contents/Resources/Main.nib" }
: {};
expect((await call("open_binary", { path: app })).isError).not.toBe(true);
const before = await call(operation, parameters);
expect(before.isError).not.toBe(true);
const initial = parseEvidence(before.structuredContent);
expect(fileIdentity(initial.subject).sha256).toBe(
createHash("sha256").update(original).digest("hex"),
);
const changed = Buffer.from(original);
changed[31] = 1;
await writeFile(executable, changed);
const changedNib = nib.replaceAll("UIViewController", "ChangedController");
expect(changedNib).not.toBe(nib);
await writeFile(nibPath, changedNib);
const changedPlist =
"<plist><dict><key>CFBundleExecutable</key><string>Probe</string><key>Marker</key><string>ChangedController</string></dict></plist>";
if (operation === "inspect_plist")
await writeFile(join(contents, "Info.plist"), changedPlist);
const stale = await call(operation, parameters);
expect(parseMcpToolError(stale).error).toMatchObject({
code:
operation === "inspect_plist"
? "artifact_changed"
: "artifact_operation_failed",
category: "integrity_mismatch",
});
expect((await call("open_binary", { path: app })).isError).not.toBe(true);
const after = await call(operation, parameters);
expect(after.isError).not.toBe(true);
const refreshed = parseEvidence(after.structuredContent);
expect(fileIdentity(refreshed.subject).sha256).toBe(
createHash("sha256").update(changed).digest("hex"),
);
const nibHash = createHash("sha256").update(changedNib).digest("hex");
if (operation === "inspect_plist") {
const inspected = inspectPlistSchema.parse(refreshed.normalized_result);
expect(inspected.value).toMatchObject({ Marker: "ChangedController" });
expect(inspected.source_sha256).toBe(
createHash("sha256").update(changedPlist).digest("hex"),
);
}
if (operation === "decode_interface_builder") {
const report = interfaceBuilderAnalysisSchema.parse(
refreshed.normalized_result,
);
expect(report.documents).toContainEqual(
expect.objectContaining({
relative_path: "Contents/Resources/Main.nib",
archive_sha256: nibHash,
}),
);
expect(report.graph.nodes).toContainEqual(
expect.objectContaining({
attributes: expect.objectContaining({
class_name: "ChangedController",
}),
}),
);
}
if (operation === "inspect_keyed_archive") {
const report = keyedArchiveResultSchema.parse(
refreshed.normalized_result,
);
expect(report.archive_sha256).toBe(nibHash);
expect(report.objects).toContainEqual(
expect.objectContaining({ class_name: "ChangedController" }),
);
}
},
);