fix(artifacts): authenticate file subjects across provider and view boundaries
Narrow WASM and EVM execution ports to file subjects and preserve supplied subject types at the shared execution factory. Authenticate format with path and digest before recording or projecting Evidence, using the existing WASM identity owner in both consumers. Validation: focused WASM/EVM service and public MCP workflows passed, including malformed provider subjects and self-contained retained Evidence with contradictory format. Global typecheck/lint and documentation checks passed. Real WABT/Evmole execution and the full suite were not run.
This commit is contained in:
@@ -54,6 +54,15 @@ export interface AnalysisExecution {
|
||||
readonly subject: EvidenceSubjectTarget | null;
|
||||
}
|
||||
|
||||
interface CreateAnalysisExecutionOptions {
|
||||
readonly rawResult?: unknown;
|
||||
readonly analysisProfile?: AnalysisProfileCommitment;
|
||||
readonly limitations?: readonly string[];
|
||||
readonly relationshipCoverage?: RelationshipCoverage;
|
||||
readonly locations?: readonly EvidenceLocation[];
|
||||
readonly subject?: EvidenceSubjectTarget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a validated atomic provider observation at an adapter boundary.
|
||||
*
|
||||
@@ -61,38 +70,43 @@ export interface AnalysisExecution {
|
||||
* `result`. Omitting it records `null` rather than a second complete copy of
|
||||
* the normalized result in every Evidence record and tool response.
|
||||
*/
|
||||
export const createAnalysisExecution = (
|
||||
export function createAnalysisExecution<Subject extends EvidenceSubjectTarget>(
|
||||
result: unknown,
|
||||
provider: ProviderIdentity,
|
||||
options: {
|
||||
readonly rawResult?: unknown;
|
||||
readonly analysisProfile?: AnalysisProfileCommitment;
|
||||
readonly limitations?: readonly string[];
|
||||
readonly relationshipCoverage?: RelationshipCoverage;
|
||||
readonly locations?: readonly EvidenceLocation[];
|
||||
readonly subject?: EvidenceSubjectTarget;
|
||||
} = {},
|
||||
): AnalysisExecution => ({
|
||||
result: jsonValueSchema.parse(result),
|
||||
rawResult:
|
||||
options.rawResult === undefined
|
||||
? null
|
||||
: jsonValueSchema.parse(options.rawResult),
|
||||
provider,
|
||||
...(options.analysisProfile === undefined
|
||||
? {}
|
||||
: { analysisProfile: structuredClone(options.analysisProfile) }),
|
||||
limitations: [...(options.limitations ?? [])],
|
||||
...(options.relationshipCoverage === undefined
|
||||
? {}
|
||||
: {
|
||||
relationshipCoverage: relationshipCoverageSchema.parse(
|
||||
options.relationshipCoverage,
|
||||
),
|
||||
}),
|
||||
locations: [...(options.locations ?? [])],
|
||||
subject: options.subject ?? null,
|
||||
});
|
||||
options: CreateAnalysisExecutionOptions & { readonly subject: Subject },
|
||||
): Omit<AnalysisExecution, "subject"> & { readonly subject: Subject };
|
||||
export function createAnalysisExecution(
|
||||
result: unknown,
|
||||
provider: ProviderIdentity,
|
||||
options?: CreateAnalysisExecutionOptions,
|
||||
): AnalysisExecution;
|
||||
export function createAnalysisExecution(
|
||||
result: unknown,
|
||||
provider: ProviderIdentity,
|
||||
options: CreateAnalysisExecutionOptions = {},
|
||||
): AnalysisExecution {
|
||||
return {
|
||||
result: jsonValueSchema.parse(result),
|
||||
rawResult:
|
||||
options.rawResult === undefined
|
||||
? null
|
||||
: jsonValueSchema.parse(options.rawResult),
|
||||
provider,
|
||||
...(options.analysisProfile === undefined
|
||||
? {}
|
||||
: { analysisProfile: structuredClone(options.analysisProfile) }),
|
||||
limitations: [...(options.limitations ?? [])],
|
||||
...(options.relationshipCoverage === undefined
|
||||
? {}
|
||||
: {
|
||||
relationshipCoverage: relationshipCoverageSchema.parse(
|
||||
options.relationshipCoverage,
|
||||
),
|
||||
}),
|
||||
locations: [...(options.locations ?? [])],
|
||||
subject: options.subject ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
/** Provider-neutral application capability for one analysis operation. */
|
||||
export interface AnalysisOperationPort {
|
||||
|
||||
@@ -4,13 +4,19 @@ import type {
|
||||
} from "../AnalysisProvider.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import type { InspectEvmInterfaceInput } from "../../domain/evm/evmInterface.js";
|
||||
import type { EvidenceSubjectTarget } from "../../domain/evidence.js";
|
||||
import type { Result } from "../../domain/result.js";
|
||||
|
||||
/** Successful EVM interface recovery must identify the selected local file. */
|
||||
export type EvmInterfaceExecution = Omit<AnalysisExecution, "subject"> & {
|
||||
readonly subject: EvidenceSubjectTarget & { readonly format: "file" };
|
||||
};
|
||||
|
||||
/** Replaceable offline interface-recovery engine, independent of wallets and chain clients. */
|
||||
export interface EvmInterfacePort {
|
||||
close?(): Promise<void>;
|
||||
inspect(
|
||||
input: InspectEvmInterfaceInput,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<AnalysisExecution, AnalysisError>>;
|
||||
): Promise<Result<EvmInterfaceExecution, AnalysisError>>;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { EvmInterfaceService } from "./EvmInterfaceService.js";
|
||||
import type { EvmInterfaceExecution } from "./EvmInterfacePort.js";
|
||||
import {
|
||||
evmInterfaceExecution,
|
||||
evmInterfaceFixture,
|
||||
@@ -43,7 +44,8 @@ it.each(["carrier", "encoding", "digest", "no-subject"])(
|
||||
},
|
||||
};
|
||||
const service = new EvmInterfaceService({
|
||||
inspect: () => Promise.resolve(ok(execution)),
|
||||
inspect: () =>
|
||||
Promise.resolve(ok(execution as unknown as EvmInterfaceExecution)),
|
||||
});
|
||||
expect(
|
||||
await service.inspect({
|
||||
|
||||
@@ -67,6 +67,7 @@ export class EvmInterfaceService {
|
||||
!report.success ||
|
||||
report.data.artifact.path !== input.data.path ||
|
||||
report.data.artifact.encoding !== input.data.encoding ||
|
||||
execution.subject?.format !== "file" ||
|
||||
execution.subject?.path !== input.data.path ||
|
||||
execution.subject.sha256 !== report.data.artifact.sha256
|
||||
)
|
||||
|
||||
@@ -4,8 +4,14 @@ import type {
|
||||
} from "../AnalysisProvider.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import type { InspectWasmArtifactInput } from "../../domain/wasm/wasmArtifact.js";
|
||||
import type { EvidenceSubjectTarget } from "../../domain/evidence.js";
|
||||
import type { Result } from "../../domain/result.js";
|
||||
|
||||
/** Successful WASM inspection must identify the selected local file. */
|
||||
export type WasmArtifactExecution = Omit<AnalysisExecution, "subject"> & {
|
||||
readonly subject: EvidenceSubjectTarget & { readonly format: "file" };
|
||||
};
|
||||
|
||||
/** Replaceable offline WASM inspection engine, independent of target execution and network clients. */
|
||||
export interface WasmArtifactPort {
|
||||
/** Retry removal of retained workspaces; failures preserve ownership for another attempt. */
|
||||
@@ -13,5 +19,5 @@ export interface WasmArtifactPort {
|
||||
inspect(
|
||||
input: InspectWasmArtifactInput,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<AnalysisExecution, AnalysisError>>;
|
||||
): Promise<Result<WasmArtifactExecution, AnalysisError>>;
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ export const projectEvmInterfaceView = (
|
||||
const report = parsed.data;
|
||||
if (
|
||||
parent.subject == null ||
|
||||
parent.subject.format !== "file" ||
|
||||
parent.subject.local_path !== report.artifact.path ||
|
||||
parent.subject.digest.sha256 !== report.artifact.sha256
|
||||
)
|
||||
|
||||
@@ -103,6 +103,7 @@ export const projectWasmArtifactView = (
|
||||
: {
|
||||
path: parent.subject.local_path,
|
||||
sha256: parent.subject.digest.sha256,
|
||||
format: parent.subject.format,
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { z } from "zod";
|
||||
import { createHash } from "node:crypto";
|
||||
import type { EvidenceSubjectTarget } from "../evidence.js";
|
||||
|
||||
import { localPathStringSchema } from "../localPath.js";
|
||||
|
||||
@@ -137,11 +138,20 @@ export type InspectWasmArtifactInput = z.infer<
|
||||
>;
|
||||
export type WasmArtifact = z.infer<typeof wasmArtifactSchema>;
|
||||
|
||||
/** A WASM observation must identify the exact selected path and byte digest. */
|
||||
/** A WASM observation must identify the selected file path and byte digest. */
|
||||
export type WasmArtifactSubject = Pick<
|
||||
EvidenceSubjectTarget,
|
||||
"path" | "sha256" | "format"
|
||||
>;
|
||||
type WasmArtifactFileSubject = WasmArtifactSubject & {
|
||||
readonly format: "file";
|
||||
};
|
||||
|
||||
export const wasmArtifactMatchesSubject = (
|
||||
artifact: WasmArtifact["artifact"],
|
||||
subject: Pick<WasmArtifact["artifact"], "path" | "sha256"> | null | undefined,
|
||||
): subject is Pick<WasmArtifact["artifact"], "path" | "sha256"> =>
|
||||
subject: WasmArtifactSubject | null | undefined,
|
||||
): subject is WasmArtifactFileSubject =>
|
||||
subject != null &&
|
||||
subject.path === artifact.path &&
|
||||
subject.sha256 === artifact.sha256;
|
||||
subject.sha256 === artifact.sha256 &&
|
||||
subject.format === "file";
|
||||
|
||||
@@ -6,10 +6,12 @@ import { fileURLToPath } from "node:url";
|
||||
import { z } from "zod";
|
||||
import {
|
||||
createAnalysisExecution,
|
||||
type AnalysisExecution,
|
||||
type ExecutionOptions,
|
||||
} from "../application/AnalysisProvider.js";
|
||||
import type { EvmInterfacePort } from "../application/evm/EvmInterfacePort.js";
|
||||
import type {
|
||||
EvmInterfaceExecution,
|
||||
EvmInterfacePort,
|
||||
} from "../application/evm/EvmInterfacePort.js";
|
||||
import { readStableArtifact } from "../artifacts/readStableArtifact.js";
|
||||
import { OwnedCommandFailure } from "../process/OwnedCommand.js";
|
||||
import type {
|
||||
@@ -98,7 +100,7 @@ export class EvmoleInterfaceProvider implements EvmInterfacePort {
|
||||
inspect(
|
||||
input: InspectEvmInterfaceInput,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<AnalysisExecution, AnalysisError>> {
|
||||
): Promise<Result<EvmInterfaceExecution, AnalysisError>> {
|
||||
if (this.#closing) return Promise.resolve(err(this.#closedError()));
|
||||
const operation = this.#tail.then(() =>
|
||||
this.#closing ? err(this.#closedError()) : this.#inspect(input, options),
|
||||
@@ -113,7 +115,7 @@ export class EvmoleInterfaceProvider implements EvmInterfacePort {
|
||||
async #inspect(
|
||||
input: InspectEvmInterfaceInput,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<AnalysisExecution, AnalysisError>> {
|
||||
): Promise<Result<EvmInterfaceExecution, AnalysisError>> {
|
||||
const pending = await this.#retire();
|
||||
if (pending !== undefined) return err(pending);
|
||||
let root: Pick<PrivateRuntimeRoot, "path" | "close"> | undefined;
|
||||
@@ -123,7 +125,7 @@ export class EvmoleInterfaceProvider implements EvmInterfacePort {
|
||||
let workerLimits: EvmWorkerLimits | undefined;
|
||||
const limiter =
|
||||
this.environment.REA_EVM_PRLIMIT_COMMAND ?? "/usr/bin/prlimit";
|
||||
let result: Result<AnalysisExecution, AnalysisError>;
|
||||
let result: Result<EvmInterfaceExecution, AnalysisError>;
|
||||
try {
|
||||
if (options?.signal?.aborted) throw new AnalysisCancelledError(OPERATION);
|
||||
if (process.platform !== "linux" || process.arch !== "x64")
|
||||
|
||||
@@ -2,12 +2,12 @@ import { randomUUID, createHash } from "node:crypto";
|
||||
import { access, realpath, writeFile } from "node:fs/promises";
|
||||
import { constants } from "node:fs";
|
||||
import { isAbsolute, join } from "node:path";
|
||||
import type {
|
||||
AnalysisExecution,
|
||||
ExecutionOptions,
|
||||
} from "../application/AnalysisProvider.js";
|
||||
import type { ExecutionOptions } from "../application/AnalysisProvider.js";
|
||||
import { createAnalysisExecution } from "../application/AnalysisProvider.js";
|
||||
import type { WasmArtifactPort } from "../application/wasm/WasmArtifactPort.js";
|
||||
import type {
|
||||
WasmArtifactExecution,
|
||||
WasmArtifactPort,
|
||||
} from "../application/wasm/WasmArtifactPort.js";
|
||||
import { readStableArtifact } from "../artifacts/readStableArtifact.js";
|
||||
import type {
|
||||
AnalysisError,
|
||||
@@ -76,10 +76,10 @@ export class WabtArtifactProvider implements WasmArtifactPort {
|
||||
async inspect(
|
||||
input: InspectWasmArtifactInput,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<AnalysisExecution, AnalysisError>> {
|
||||
): Promise<Result<WasmArtifactExecution, AnalysisError>> {
|
||||
let root: Pick<PrivateRuntimeRoot, "path" | "close"> | undefined;
|
||||
let phase: "configuration" | "artifact" | "producer" = "configuration";
|
||||
let result: Result<AnalysisExecution, AnalysisError>;
|
||||
let result: Result<WasmArtifactExecution, AnalysisError>;
|
||||
let capturedOutput: AnalysisCapturedOutput | undefined;
|
||||
try {
|
||||
if (options?.signal?.aborted) throw new AnalysisCancelledError(OPERATION);
|
||||
|
||||
@@ -39,6 +39,8 @@ import {
|
||||
} from "../../fixtures/analysisView.js";
|
||||
import { createTestBinarySession } from "../../fixtures/binarySession.js";
|
||||
import { BINARY_LAYOUT_TEST_PROVIDER } from "../../fixtures/binaryDiagnostics/layout.js";
|
||||
import { wasmArtifactFixture } from "../../fixtures/wasm/artifact.js";
|
||||
import { evmInterfaceFixture } from "../../fixtures/evm/interface.js";
|
||||
|
||||
const connect = async (
|
||||
binaryLayout?: BinaryLayoutService,
|
||||
@@ -310,6 +312,65 @@ it("reports a tampered inline Evidence ID at its full MCP source path", async ()
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects self-contained WASM and EVM Evidence views when the subject format differs", async () => {
|
||||
const { client } = await connect();
|
||||
const wasm = wasmArtifactFixture();
|
||||
const evm = evmInterfaceFixture();
|
||||
const cases = [
|
||||
{
|
||||
evidence: createEvidence(
|
||||
{
|
||||
path: wasm.artifact.path,
|
||||
format: "elf",
|
||||
sha256: wasm.artifact.sha256,
|
||||
},
|
||||
{ id: "fixture-wabt", name: "WABT", version: "1" },
|
||||
{
|
||||
operation: "inspect_wasm_artifact",
|
||||
parameters: { path: wasm.artifact.path },
|
||||
result: wasm,
|
||||
},
|
||||
),
|
||||
},
|
||||
{
|
||||
evidence: createEvidence(
|
||||
{
|
||||
path: evm.artifact.path,
|
||||
format: "elf",
|
||||
sha256: evm.artifact.sha256,
|
||||
},
|
||||
{ id: "fixture-evm", name: "EVMole", version: "1" },
|
||||
{
|
||||
operation: "inspect_evm_interface",
|
||||
parameters: { path: evm.artifact.path, encoding: "hex" },
|
||||
result: evm,
|
||||
},
|
||||
),
|
||||
},
|
||||
] as const;
|
||||
|
||||
for (const { evidence } of cases) {
|
||||
const response = await client.callTool({
|
||||
name: "inspect_analysis_view",
|
||||
arguments: {
|
||||
source: { kind: "inline", evidence },
|
||||
view: { kind: "summary" },
|
||||
},
|
||||
});
|
||||
expect(parseMcpToolError(response).error).toMatchObject({
|
||||
code: "invalid_request",
|
||||
details: {
|
||||
issues: [
|
||||
expect.objectContaining({
|
||||
path: ["source", "subject"],
|
||||
reason: "invalid_value",
|
||||
}),
|
||||
],
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it("admits portable captures before SDK Evidence parsing and preserves capture caveats", async () => {
|
||||
const { client } = await connect();
|
||||
const dense = analysisViewCaptureEvidence(analysisViewObjectDenseCapture());
|
||||
|
||||
@@ -107,6 +107,30 @@ it("advertises exact valid schemas and records inline EVM interface evidence wit
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects an EVM provider response with a non-file subject before recording Evidence", async () => {
|
||||
const value = evmInterfaceFixture();
|
||||
const execution = evmInterfaceExecution(value);
|
||||
const malformed = {
|
||||
...execution,
|
||||
subject: { ...execution.subject, format: "elf" },
|
||||
} as unknown as typeof execution;
|
||||
const harness = await createApplicationMcpHarness({
|
||||
serverOptions: {
|
||||
evmInterface: new EvmInterfaceService({
|
||||
inspect: () => Promise.resolve(ok(malformed)),
|
||||
}),
|
||||
},
|
||||
});
|
||||
onTestFinished(harness.close);
|
||||
const before = harness.session.exportEvidenceBundle().records.length;
|
||||
const response = await harness.client.callTool({
|
||||
name: "inspect_evm_interface",
|
||||
arguments: { path: value.artifact.path, encoding: "hex" },
|
||||
});
|
||||
expect(parseMcpToolError(response).error.code).toBe("unreadable_output");
|
||||
expect(harness.session.exportEvidenceBundle().records).toHaveLength(before);
|
||||
});
|
||||
|
||||
it.each(["unavailable", "incompatible-output"])(
|
||||
"preserves a healthy WASM peer and explicit EVM failure: %s",
|
||||
async (scenario) => {
|
||||
|
||||
@@ -213,6 +213,31 @@ it("advertises exact valid schemas and records inline WASM interface evidence wi
|
||||
expect(close).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("rejects a WASM provider response with a non-file subject before recording Evidence", async () => {
|
||||
const value = wasmArtifactFixture();
|
||||
const execution = wasmArtifactExecution(value);
|
||||
const malformed = {
|
||||
...execution,
|
||||
subject: { ...execution.subject, format: "elf" },
|
||||
} as unknown as typeof execution;
|
||||
const harness = await createApplicationMcpHarness({
|
||||
serverOptions: {
|
||||
wasmArtifact: new WasmArtifactService({
|
||||
close: () => Promise.resolve(),
|
||||
inspect: () => Promise.resolve(ok(malformed)),
|
||||
}),
|
||||
},
|
||||
});
|
||||
onTestFinished(harness.close);
|
||||
const before = harness.session.exportEvidenceBundle().records.length;
|
||||
const response = await harness.client.callTool({
|
||||
name: "inspect_wasm_artifact",
|
||||
arguments: { path: value.artifact.path },
|
||||
});
|
||||
expect(parseMcpToolError(response).error.code).toBe("unreadable_output");
|
||||
expect(harness.session.exportEvidenceBundle().records).toHaveLength(before);
|
||||
});
|
||||
|
||||
it("reads an oversized completed WASM result through its reported retained reference", async () => {
|
||||
const text = "(module)\n" + ";;😀\n" + " ".repeat(6 * 1024 * 1024);
|
||||
const value = {
|
||||
|
||||
Vendored
+6
-2
@@ -1,5 +1,6 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { createAnalysisExecution } from "../../../src/application/AnalysisProvider.js";
|
||||
import type { EvmInterfaceExecution } from "../../../src/application/evm/EvmInterfacePort.js";
|
||||
import type { EvmInterface } from "../../../src/domain/evm/evmInterface.js";
|
||||
|
||||
/** Source-owned transport seam, independent of real engine verification. */
|
||||
@@ -27,8 +28,10 @@ export const evmInterfaceFixture = (
|
||||
});
|
||||
|
||||
/** Bind a fixture to its explicit producing seam and carrier identity. */
|
||||
export const evmInterfaceExecution = (value = evmInterfaceFixture()) =>
|
||||
createAnalysisExecution(
|
||||
export const evmInterfaceExecution = (
|
||||
value = evmInterfaceFixture(),
|
||||
): EvmInterfaceExecution => {
|
||||
return createAnalysisExecution(
|
||||
value,
|
||||
{ id: "fixture-evm", name: "Source-owned EVM seam", version: "1" },
|
||||
{
|
||||
@@ -42,3 +45,4 @@ export const evmInterfaceExecution = (value = evmInterfaceFixture()) =>
|
||||
locations: [{ kind: "artifact-path", path: value.artifact.path }],
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
Vendored
+6
-2
@@ -1,5 +1,6 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { createAnalysisExecution } from "../../../src/application/AnalysisProvider.js";
|
||||
import type { WasmArtifactExecution } from "../../../src/application/wasm/WasmArtifactPort.js";
|
||||
import type { WasmArtifact } from "../../../src/domain/wasm/wasmArtifact.js";
|
||||
/** Source-owned transport seam; upstream binaries are verified in a separate lane. */
|
||||
export const wasmArtifactFixture = (
|
||||
@@ -42,8 +43,10 @@ export const wasmArtifactFixture = (
|
||||
network_fetch: "not-performed" as const,
|
||||
limitations: ["Source-owned transport seam."],
|
||||
});
|
||||
export const wasmArtifactExecution = (value = wasmArtifactFixture()) =>
|
||||
createAnalysisExecution(
|
||||
export const wasmArtifactExecution = (
|
||||
value = wasmArtifactFixture(),
|
||||
): WasmArtifactExecution => {
|
||||
return createAnalysisExecution(
|
||||
value,
|
||||
{ id: "fixture-wabt", name: "Source-owned WABT seam", version: "1" },
|
||||
{
|
||||
@@ -55,3 +58,4 @@ export const wasmArtifactExecution = (value = wasmArtifactFixture()) =>
|
||||
limitations: value.limitations,
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user