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:
co-authored by
Claude Opus 5.5
parent
0804722cdf
commit
69af884666
@@ -21,15 +21,19 @@ import {
|
||||
type ArtifactGraphManifest,
|
||||
type ArtifactNode,
|
||||
type ArtifactOccurrence,
|
||||
type IntegrityContradiction,
|
||||
} from "../domain/artifactGraph.js";
|
||||
import type { BinaryTarget } from "../domain/binaryTarget.js";
|
||||
import { scanArtifactInventory } from "./ArtifactInventory.js";
|
||||
import type { ArtifactIntegrityPolicy } from "./ArtifactInventory/types.js";
|
||||
|
||||
/** Local extraction input with the output root chosen by the adapter. */
|
||||
export interface ArtifactExtractionInput {
|
||||
readonly inputPath: string;
|
||||
readonly inputFormat: BinaryTarget["format"];
|
||||
readonly outputRoot: string;
|
||||
/** Integrity mismatches fail unless the caller records and continues. */
|
||||
readonly integrity?: ArtifactIntegrityPolicy;
|
||||
}
|
||||
|
||||
/** Extract every regular inventory occurrence into an exclusively owned absent root. */
|
||||
@@ -40,6 +44,7 @@ export const extractArtifact = async (
|
||||
const sourcePath = await realpath(input.inputPath);
|
||||
const snapshot = await scanArtifactInventory(sourcePath, {
|
||||
signal,
|
||||
integrity: input.integrity,
|
||||
});
|
||||
const selectedOccurrences = snapshot.occurrences.filter(
|
||||
(occurrence) =>
|
||||
@@ -63,6 +68,7 @@ export const extractArtifact = async (
|
||||
manifest: snapshot.manifest,
|
||||
occurrences,
|
||||
nodes,
|
||||
integrityContradictions: snapshot.integrity_contradictions,
|
||||
};
|
||||
const selected = selectedOccurrences.map((occurrence) => {
|
||||
if (
|
||||
@@ -206,8 +212,14 @@ const createExtractionResult = (
|
||||
containment_verified: true,
|
||||
cleanup: { attempted: false, verified: true, residual_paths: [] },
|
||||
provenance: [],
|
||||
integrity_contradictions: inventory.integrityContradictions,
|
||||
limitations: [
|
||||
"All regular files in the active artifact were materialized; nested archive contents remain represented by their containing file.",
|
||||
...(inventory.integrityContradictions.length === 0
|
||||
? []
|
||||
: [
|
||||
`${String(inventory.integrityContradictions.length)} extracted file(s) contradict declared integrity; their observed bytes were written and are untrusted.`,
|
||||
]),
|
||||
],
|
||||
});
|
||||
};
|
||||
@@ -216,6 +228,7 @@ interface LoadedInventory {
|
||||
readonly manifest: ArtifactGraphManifest;
|
||||
readonly occurrences: ReadonlyMap<string, ArtifactOccurrence>;
|
||||
readonly nodes: ReadonlyMap<string, ArtifactNode>;
|
||||
readonly integrityContradictions: readonly IntegrityContradiction[];
|
||||
}
|
||||
|
||||
const collectOccurrences = (
|
||||
|
||||
@@ -40,4 +40,5 @@ const parameters = (
|
||||
input: AnalyzeJavaScriptApplicationInput,
|
||||
): EvidenceObservation["parameters"] => ({
|
||||
format: input.format,
|
||||
integrity_policy: input.integrity_policy,
|
||||
});
|
||||
|
||||
@@ -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.",
|
||||
]),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -55,14 +55,23 @@ export const analyzeJavaScriptApplicationValidated = async (
|
||||
{
|
||||
input_path: input.input_path,
|
||||
format: input.format,
|
||||
integrity_policy: input.integrity_policy,
|
||||
},
|
||||
options.signal,
|
||||
);
|
||||
const { electron_summary: summary, ...application } = reconstructed;
|
||||
const contradictions = reconstructed.integrity_contradictions.length;
|
||||
const result = javascriptApplicationAnalysisResultSchema.parse({
|
||||
...application,
|
||||
summary,
|
||||
limitations: reconstructed.graph.limitations,
|
||||
limitations: [
|
||||
...reconstructed.graph.limitations,
|
||||
...(contradictions === 0
|
||||
? []
|
||||
: [
|
||||
`${String(contradictions)} artifact file(s) contradict declared integrity; their observed bytes are untrusted, and contradicted nested archives were not expanded.`,
|
||||
]),
|
||||
],
|
||||
});
|
||||
await options.progress?.report({
|
||||
phase: "analyze_javascript_application",
|
||||
|
||||
@@ -9,6 +9,7 @@ import { DirectoryArtifactReader } from "../../artifacts/DirectoryArtifactReader
|
||||
import type { JavaScriptApplicationGraph } from "../../domain/javascriptApplicationGraph.js";
|
||||
import type { JavaScriptSemanticGraph } from "../../domain/javascriptSemanticGraph.js";
|
||||
import type { ElectronBoundarySummary } from "../../domain/javascriptApplicationAnalysis.js";
|
||||
import type { IntegrityContradiction } from "../../domain/artifactGraph.js";
|
||||
import { analyzeJavaScriptArtifactFiles } from "./JavaScriptArtifactAnalysis.js";
|
||||
import { readJavaScriptArtifactFiles } from "./JavaScriptArtifactFiles.js";
|
||||
import { buildJavaScriptArtifactGraph } from "./JavaScriptArtifactGraphBuilder.js";
|
||||
@@ -30,6 +31,7 @@ export interface JavaScriptArtifactReconstructionResult {
|
||||
readonly graph: JavaScriptApplicationGraph;
|
||||
readonly semantic_graph: JavaScriptSemanticGraph;
|
||||
readonly electron_summary: ElectronBoundarySummary;
|
||||
readonly integrity_contradictions: readonly IntegrityContradiction[];
|
||||
readonly statistics: {
|
||||
readonly relevant_files: number;
|
||||
readonly nested_asar_containers: number;
|
||||
@@ -54,7 +56,10 @@ export const reconstructJavaScriptArtifact = async (
|
||||
abortIfNeeded(signal);
|
||||
const path = await realpath(input.input_path);
|
||||
const format = await resolveFormat(path, input);
|
||||
const snapshot = await scanCanonicalArtifactInventory(path, { signal });
|
||||
const snapshot = await scanCanonicalArtifactInventory(path, {
|
||||
signal,
|
||||
integrity: { mode: input.integrity_policy },
|
||||
});
|
||||
if (snapshot.manifest.root_format !== format)
|
||||
throw new ArtifactReaderFailure(
|
||||
"format",
|
||||
@@ -80,6 +85,7 @@ export const reconstructJavaScriptArtifact = async (
|
||||
graph,
|
||||
semantic_graph: semanticGraph,
|
||||
electron_summary: summarizeElectronBoundaries(analysis),
|
||||
integrity_contradictions: snapshot.integrity_contradictions,
|
||||
statistics: {
|
||||
relevant_files: files.files.length,
|
||||
nested_asar_containers: files.containers.length,
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { artifactIntegrityPolicySchema } from "../../domain/artifactGraph.js";
|
||||
|
||||
/** Local ASAR/directory reconstruction request. */
|
||||
export const javascriptArtifactReconstructionInputSchema = z.strictObject({
|
||||
input_path: z.string().min(1),
|
||||
format: z.enum(["auto", "asar", "directory"]).default("auto"),
|
||||
integrity_policy: artifactIntegrityPolicySchema,
|
||||
});
|
||||
|
||||
/** Parsed local reconstruction request. */
|
||||
|
||||
Reference in New Issue
Block a user