fix(evidence): enforce managed identity and cancel bundle reads

Validate managed reconstruction through the shared artifact and MVID scope boundary, including known/unknown identity contradictions. Forward MCP comparison cancellation into both bundle reads and consolidate pre-cancel coverage.

Verified managed graph/reconstruction and filesystem/MCP cancellation workflows. A controlled missing-signal mutation reads 130 chunks instead of the expected one; cancellation leaves the session unchanged and retry succeeds.
This commit is contained in:
morluto
2026-10-12 13:06:30 +08:00
parent 83a4445f44
commit 3bcc68c037
8 changed files with 329 additions and 38 deletions
@@ -43,15 +43,14 @@ export const parseManagedInspectionEvidence = <
throw new TypeError(
`Managed Evidence ${operation} (${evidence.evidence_id}) token scope SHA-256 ${scope.requires_artifact_sha256} does not match normalized artifact SHA-256 ${artifactSha256}`,
);
const moduleMvid = result.module?.mvid ?? null;
const scopedMvid = scope?.requires_mvid;
if (
scope?.requires_mvid !== undefined &&
scope.requires_mvid !== null &&
result.module?.mvid !== undefined &&
result.module.mvid !== null &&
scope.requires_mvid.toLowerCase() !== result.module.mvid.toLowerCase()
scopedMvid !== undefined &&
scopedMvid?.toLowerCase() !== moduleMvid?.toLowerCase()
)
throw new TypeError(
`Managed Evidence ${operation} (${evidence.evidence_id}) token scope MVID ${scope.requires_mvid} does not match module MVID ${result.module.mvid}`,
`Managed Evidence ${operation} (${evidence.evidence_id}) token scope MVID ${String(scopedMvid)} does not match module MVID ${String(moduleMvid)}`,
);
return { evidence, result };
};
+11 -11
View File
@@ -3,15 +3,15 @@ import { createHash } from "node:crypto";
import canonicalize from "canonicalize";
import { z } from "zod";
import { evidenceSchema, parseEvidence } from "../evidence.js";
import { evidenceSchema, type Evidence } from "../evidence.js";
import {
cliMetadataGuidSchema,
managedMemberInspectionSchema,
type ManagedMemberInspection,
} from "./managedArtifact.js";
import type { JsonValue } from "../jsonValue.js";
import { digestSchema } from "../digests.js";
import { prefixedDigestSchema } from "../digests.js";
import { digestSchema, prefixedDigestSchema } from "../digests.js";
import { parseManagedInspectionEvidence } from "./managedInspectionEvidence.js";
const evidenceIdSchema = prefixedDigestSchema("ev");
const tokenSchema = z.string().regex(/^0x[0-9a-f]{8}$/u);
@@ -210,7 +210,7 @@ const buildReconstructionSummary = (
});
const buildStaticObservation = (
staticEvidence: ReturnType<typeof parseEvidence>,
staticEvidence: Evidence,
members: ManagedMemberInspection,
): StaticObservation => ({
evidence_id: staticEvidence.evidence_id,
@@ -238,7 +238,7 @@ const RECONSTRUCTION_LIMITATIONS = [
const buildReconstructionWithoutId = (
input: ManagedReconstructionImportInput,
staticEvidence: ReturnType<typeof parseEvidence>,
staticEvidence: Evidence,
members: ManagedMemberInspection,
methods: readonly ImportedMethod[],
): Omit<ManagedReconstructionImportResult, "reconstruction_id"> => ({
@@ -257,12 +257,12 @@ const buildReconstructionWithoutId = (
export const importManagedReconstruction = (
input: ManagedReconstructionImportInput,
): ManagedReconstructionImportResult => {
const staticEvidence = parseEvidence(input.static_members);
if (staticEvidence.operation !== "inspect_managed_members")
throw new TypeError("Evidence operation is not inspect_managed_members");
const members = managedMemberInspectionSchema.parse(
staticEvidence.normalized_result,
);
const { evidence: staticEvidence, result: members } =
parseManagedInspectionEvidence(
input.static_members,
"inspect_managed_members",
managedMemberInspectionSchema,
);
const methods = input.methods.map((candidate) => {
const observed = findObservedMethod(members, candidate);
if (observed === undefined)