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);
|
||||
|
||||
Reference in New Issue
Block a user