fix(evidence): reject unsupported metadata before authentication
Close persisted Evidence, bundle, profile and unknown record shapes so parsing cannot silently remove caller metadata before checking semantic identity. Keep constructor provider projection explicit and JSON payload fields open. Exercise actual MCP export/import with independent record and manifest mutations, unchanged state after rejection, and a valid round trip. Prune duplicate source assertions. Validation: focused domain/CLI/MCP/filesystem checks, converted JSON Schemas, docs and typecheck/lint.
This commit is contained in:
@@ -65,4 +65,11 @@ describe("analysis profile commitments", () => {
|
||||
analysisProfileSchema.parse({ ...profile, digest: "0".repeat(64) }),
|
||||
).toThrow(/digest/u);
|
||||
});
|
||||
|
||||
it("projects known provider identity fields at construction", () => {
|
||||
const liveProvider = { ...PROVIDER, transient_status: "starting" };
|
||||
const profile = createAnalysisProfile(liveProvider, { loader: "default" });
|
||||
expect(profile.provider).toEqual(PROVIDER);
|
||||
expect(analysisProfileSchema.parse(profile)).toEqual(profile);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,13 +7,13 @@ import { jsonObjectSchema, type JsonValue } from "./jsonValue.js";
|
||||
import { digestSchema } from "./../domain/digests.js";
|
||||
|
||||
/** Concrete provider identity committed by an analysis profile. */
|
||||
export const committedProviderSchema = z.object({
|
||||
export const committedProviderSchema = z.strictObject({
|
||||
id: z.string().min(1),
|
||||
name: z.string().min(1),
|
||||
version: z.string().min(1),
|
||||
});
|
||||
|
||||
const unsignedAnalysisProfileSchema = z.object({
|
||||
const unsignedAnalysisProfileSchema = z.strictObject({
|
||||
provider: committedProviderSchema,
|
||||
parameters: jsonObjectSchema,
|
||||
});
|
||||
@@ -40,7 +40,11 @@ export const createAnalysisProfile = (
|
||||
parameters: Readonly<Record<string, JsonValue>>,
|
||||
): AnalysisProfileCommitment => {
|
||||
const unsigned = unsignedAnalysisProfileSchema.parse({
|
||||
provider,
|
||||
provider: {
|
||||
id: provider.id,
|
||||
name: provider.name,
|
||||
version: provider.version,
|
||||
},
|
||||
parameters,
|
||||
});
|
||||
return analysisProfileSchema.parse({
|
||||
|
||||
@@ -52,6 +52,30 @@ it("preserves omitted relationship diagnostics and authenticates reported diagno
|
||||
).toThrow("semantic identifier");
|
||||
});
|
||||
|
||||
it("projects known provider fields and preserves open JSON payloads", () => {
|
||||
const liveProvider = { ...PROVIDER, transient_status: "starting" };
|
||||
const evidence = createEvidence(TARGET, liveProvider, {
|
||||
operation: "inspect",
|
||||
parameters: { caller_metadata: { note: "kept" } },
|
||||
result: { producer_extension: { value: "kept" } },
|
||||
analysisProfile: PROFILE,
|
||||
environment: {
|
||||
id: "fixture",
|
||||
platform: "linux",
|
||||
architecture: "x86_64",
|
||||
isolation: "process",
|
||||
},
|
||||
locations: [{ kind: "address", address: "0x1000" }],
|
||||
});
|
||||
|
||||
expect(evidence.provider).toEqual(PROVIDER);
|
||||
expect(evidence.parameters).toEqual({ caller_metadata: { note: "kept" } });
|
||||
expect(evidence.normalized_result).toEqual({
|
||||
producer_extension: { value: "kept" },
|
||||
});
|
||||
expect(parseEvidence(evidence)).toEqual(evidence);
|
||||
});
|
||||
|
||||
it("preserves identity and bytes when reusing an owned immutable result", () => {
|
||||
const value = { nested: { values: ["observed", 1] } };
|
||||
const mutable = createEvidence(TARGET, PROVIDER, {
|
||||
|
||||
+12
-9
@@ -33,14 +33,14 @@ import {
|
||||
} from "./relationshipCoverage.js";
|
||||
|
||||
/** Provider identity schema shared by evidence-bearing persistence formats. */
|
||||
export const providerSchema = z.object({
|
||||
export const providerSchema = z.strictObject({
|
||||
id: z.string().min(1),
|
||||
name: z.string().min(1),
|
||||
version: z.string().nullable(),
|
||||
});
|
||||
const subjectSchema = z.object({
|
||||
const subjectSchema = z.strictObject({
|
||||
name: z.string().min(1),
|
||||
digest: z.object({ sha256: digestSchema }),
|
||||
digest: z.strictObject({ sha256: digestSchema }),
|
||||
format: z.enum([
|
||||
"hopper",
|
||||
"analysis-database",
|
||||
@@ -77,15 +77,18 @@ const subjectSchema = z.object({
|
||||
/** Source location attached to an evidence observation. */
|
||||
/** Source-location schema shared by evidence-bearing persistence formats. */
|
||||
export const evidenceLocationSchema = z.discriminatedUnion("kind", [
|
||||
z.object({ kind: z.literal("address"), address: z.string().min(1) }),
|
||||
z.object({
|
||||
z.strictObject({ kind: z.literal("address"), address: z.string().min(1) }),
|
||||
z.strictObject({
|
||||
kind: z.literal("address-range"),
|
||||
start: z.string().min(1),
|
||||
end: z.string().min(1),
|
||||
}),
|
||||
z.object({ kind: z.literal("artifact-path"), path: z.string().min(1) }),
|
||||
z.object({ kind: z.literal("file-offset"), offset: z.number().int().min(0) }),
|
||||
z.object({
|
||||
z.strictObject({ kind: z.literal("artifact-path"), path: z.string().min(1) }),
|
||||
z.strictObject({
|
||||
kind: z.literal("file-offset"),
|
||||
offset: z.number().int().min(0),
|
||||
}),
|
||||
z.strictObject({
|
||||
kind: z.literal("file-offset-range"),
|
||||
start: z.number().int().min(0),
|
||||
end: z.number().int().min(0),
|
||||
@@ -100,7 +103,7 @@ const evidenceAuthoritySchema = z.enum([
|
||||
"analyst-inference",
|
||||
]);
|
||||
|
||||
const executionEnvironmentSchema = z.object({
|
||||
const executionEnvironmentSchema = z.strictObject({
|
||||
id: z.string().min(1),
|
||||
platform: z.string().min(1),
|
||||
architecture: z.string().min(1),
|
||||
|
||||
@@ -16,24 +16,27 @@ import {
|
||||
} from "./residualUnknown.js";
|
||||
import { freezeJsonSnapshot } from "./immutableJson.js";
|
||||
|
||||
const artifactManifestSchema = evidenceSchema.shape.subject.unwrap().pick({
|
||||
digest: true,
|
||||
format: true,
|
||||
architecture: true,
|
||||
});
|
||||
const artifactManifestSchema = evidenceSchema.shape.subject
|
||||
.unwrap()
|
||||
.pick({
|
||||
digest: true,
|
||||
format: true,
|
||||
architecture: true,
|
||||
})
|
||||
.strict();
|
||||
const providerManifestSchema = providerSchema;
|
||||
const environmentManifestSchema = evidenceSchema.shape.environment.unwrap();
|
||||
const scenarioManifestSchema = z.object({
|
||||
const scenarioManifestSchema = z.strictObject({
|
||||
evidence_id: evidenceSchema.shape.evidence_id,
|
||||
operation: z.string().min(1),
|
||||
authority: z.literal("controlled-replay"),
|
||||
});
|
||||
const captureManifestSchema = z.object({
|
||||
const captureManifestSchema = z.strictObject({
|
||||
evidence_id: evidenceSchema.shape.evidence_id,
|
||||
predicate_type: z.string().min(1),
|
||||
});
|
||||
|
||||
export const evidenceBundleSchema = z.object({
|
||||
export const evidenceBundleSchema = z.strictObject({
|
||||
artifacts: z.array(artifactManifestSchema),
|
||||
providers: z.array(providerManifestSchema),
|
||||
environments: z.array(environmentManifestSchema),
|
||||
|
||||
@@ -12,7 +12,7 @@ import { functionComparisonDimensionNameSchema } from "./functionComparisonSchem
|
||||
const evidenceIdSchema = prefixedDigestSchema("ev");
|
||||
const unknownIdSchema = prefixedDigestSchema("unk");
|
||||
const text = z.string().trim().min(1);
|
||||
const environmentRequirementSchema = z.object({
|
||||
const environmentRequirementSchema = z.strictObject({
|
||||
id: z.string().min(1).nullable(),
|
||||
platform: z.string().min(1).nullable(),
|
||||
architecture: z.string().min(1).nullable(),
|
||||
@@ -39,7 +39,7 @@ const stableUnknownId = (
|
||||
)
|
||||
.digest("hex")}`;
|
||||
|
||||
const probeSchema = z.object({
|
||||
const probeSchema = z.strictObject({
|
||||
operation: z.string().min(1),
|
||||
rationale: text,
|
||||
});
|
||||
@@ -60,17 +60,17 @@ const comparisonConclusionScopeSchema = z
|
||||
message: "Comparison dimensions must be sorted and unique",
|
||||
});
|
||||
});
|
||||
const relationshipSchema = z.object({
|
||||
const relationshipSchema = z.strictObject({
|
||||
type: z.enum(["depends-on", "related-to", "contradicts"]),
|
||||
unknown_id: unknownIdSchema,
|
||||
});
|
||||
const resolutionSchema = z.discriminatedUnion("disposition", [
|
||||
z.object({
|
||||
z.strictObject({
|
||||
disposition: z.literal("verified"),
|
||||
rationale: text,
|
||||
evidence_ids: z.array(evidenceIdSchema).min(1),
|
||||
}),
|
||||
z.object({
|
||||
z.strictObject({
|
||||
disposition: z.enum(["withdrawn", "out-of-scope"]),
|
||||
rationale: text,
|
||||
evidence_ids: z.array(evidenceIdSchema),
|
||||
@@ -78,7 +78,7 @@ const resolutionSchema = z.discriminatedUnion("disposition", [
|
||||
]);
|
||||
|
||||
/** Strict durable record for one unresolved or evidence-qualified question. */
|
||||
const residualUnknownObjectSchema = z.object({
|
||||
const residualUnknownObjectSchema = z.strictObject({
|
||||
unknown_id: unknownIdSchema,
|
||||
revision: z.number().int().min(1),
|
||||
previous_revision_digest: z
|
||||
|
||||
Reference in New Issue
Block a user