feat(artifacts): let extraction and JavaScript analysis record integrity mismatches

macOS code signing rewrites unpacked native modules after electron-builder
records their ASAR integrity, so the declared and observed hashes of
those .node files differ in most signed Electron apps. Claude, ChatGPT,
Notion, Obsidian, and Tabby all failed inspect_artifact,
extract_artifact, and analyze_javascript_application by default. Only
inspect_artifact offered integrity_policy, so extraction and JavaScript
analysis of these apps was impossible.

extract_artifact and analyze_javascript_application now accept the same
integrity_policy (default fail). With record-and-continue, extraction
writes the observed bytes, and JavaScript analysis reads contradicted
files as observed. Contradicted nested archives stay unexpanded. Both
results return the recorded integrity_contradictions and a limitation.
The mismatch remediation now names this option instead of only advising a
fresh copy, which cannot help for a signed installation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kaoru0822
2026-10-07 08:28:44 +00:00
co-authored by Claude Opus 5.5
parent 0804722cdf
commit 69af884666
21 changed files with 239 additions and 25 deletions
@@ -1,6 +1,7 @@
import { writeFile } from "node:fs/promises";
import { mkdir, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { createPackageWithOptions } from "@electron/asar";
import { describe, expect, it } from "vitest";
import { z } from "zod";
@@ -120,3 +121,57 @@ describe("JavaScript application failure diagnostics", () => {
},
);
});
describe("JavaScript application artifact integrity", () => {
it("analyzes a signed-after-packaging native module only when the mismatch is recorded", async () => {
const root = await createTestTempDirectory("rea-js-integrity-");
const source = join(root, "source");
await mkdir(source);
await writeFile(
join(source, "package.json"),
'{"name":"signed","main":"main.js"}',
);
await writeFile(join(source, "main.js"), "require('./addon.node');\n");
await writeFile(join(source, "addon.node"), "packed native bytes");
const archive = join(root, "app.asar");
await createPackageWithOptions(source, archive, { unpack: "*.node" });
// macOS code signing rewrites unpacked binaries after the archive header
// has recorded their integrity.
await writeFile(
join(`${archive}.unpacked`, "addon.node"),
"signed native bytes",
);
const strict = await analyzeJavaScriptApplication({ input_path: archive });
expect(strict.ok).toBe(false);
if (strict.ok) throw new Error("Expected an integrity failure");
expect(projectAnalysisError(strict.error)).toMatchObject({
code: "artifact_integrity_mismatch",
details: { logical_path: "addon.node", unpacked: true },
});
const recorded = await analyzeJavaScriptApplication({
input_path: archive,
integrity_policy: "record-and-continue",
});
expect(recorded.ok).toBe(true);
if (!recorded.ok) throw new Error("Expected recorded analysis");
expect(recorded.value.parameters).toEqual({
format: "auto",
integrity_policy: "record-and-continue",
});
expect(recorded.value.normalized_result).toMatchObject({
format: "asar",
integrity_contradictions: [
{
logical_path: "addon.node",
unpacked: true,
trust: "observed-untrusted",
},
],
limitations: expect.arrayContaining([
"1 artifact file(s) contradict declared integrity; their observed bytes are untrusted, and contradicted nested archives were not expanded.",
]),
});
});
});