mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 21:23:45 +00:00
* feat(evidence)!: name the Evidence subject by its target identity (format revision 2) The Evidence subject carries subject.identity (kind, sha256, format, architecture, selection) and the Evidence ID commits to it, so raw/DOL entry points and ESP flash offsets of the same bytes are different subjects. Every record declares evidence_format: 2; revision 1 bundles, standalone records and snapshots are refused with the recreate guidance. binaryTargetIdentity is the one projection of an open target, used by Evidence and snapshot comparison. BREAKING CHANGE: Evidence format revision 2. Evidence IDs commit to the subject's target identity (subject.identity, including the raw/DOL entry point or ESP flash offsets), and every record declares evidence_format: 2. Evidence bundles, records and analysis snapshots from earlier releases are refused; recreate the observations with this release. * refactor(analysis-view): read parent subjects through the Evidence identity accessors (#11423) Analysis views compare their parent's file identity (evidenceFileTarget) and take path and digest from evidenceSubjectTarget instead of reading the subject's digest, format and architecture members, which duplicate subject.identity until they are removed. A counted guard (evidence-subject-declaration-read) keeps new direct reads out and records the 20 remaining files. * fix(evidence): carry format refusals through Evidence readers and bind target selections - safeParseEvidence/safeParseImmutableEvidence return the format refusal as an expected failure; every consumer maps it to the one integrity refusal with the recreate guidance. An unmarked object is an earlier record only when it has every member records have always carried. - ArtifactProvider inventory roots and provider subjects that name the target's own bytes carry the target's selection (ESP flash offsets). - Snapshot rows bind only Evidence whose identity, selection included, matches the snapshot target. - Entry-point selections use the raw-binary entry point form. * fix(evidence): refuse unauthenticated or earlier-format records instead of reading them as absent - recognizeEvidence (evidenceValidation) replaces tryParseEvidence: input without an evidence_id is not Evidence (ok(undefined)); a record that names one but fails authentication or is from another format revision is an EvidenceIntegrityError carrying the recreate guidance, never undefined. - Direct analysis retains that refusal as a secondary failure instead of silently skipping source capture; cleanup projection, source-closure annotation and the flutter, debugger and release-exposure recoveries use the same owner (the last three previously read the unauthenticated schema). - A desktop capture.json from an earlier format is refused with the recreate guidance instead of "not desktop application capture Evidence". * fix(evidence): advertise revision 2 ledger examples and rank delivery omissions by serialized size - The obligation ledger and reconstruction coverage examples named evidence_format 1, which revision 2 refuses; they now use EVIDENCE_FORMAT_REVISION. - MCP delivery chose which unretained recovery to omit by a parsed-storage lower bound clipped at the response budget. Once revision 2 subjects made the source record's estimate cross the budget, both candidates tied at the clip and the smaller source was omitted ahead of the larger completed observation. Candidates are now ranked by serialized size, which is what the budget counts. * refactor(native): compare function snapshots by their Evidence target identity (#11450) Function snapshots carry the subject's file target identity instead of the duplicated subject declaration. Call paths and function comparisons compare targets through sameTargetIdentity, so the same bytes opened at a different raw entry point or ESP flash offset no longer count as one coordinate space: build_call_path refuses the mix, and compare_functions no longer matches entries by address across selections. Structural candidates and native function matching read the architecture and digest through evidenceFileTarget. Refs #11417 * refactor(artifacts): compare artifact and WASM summaries by their Evidence target identity (#11461) Artifact comparison authenticates a summary against its retained inventory through sameTargetIdentity and rebinds the alias with the whole target, selection included, so a flash-selected inventory summary taken under an alias path is no longer refused. WASM comparison, the analysis view artifact projection and the inventory root check read the digest, format and display path through the Evidence identity accessors. Refs #11417 * refactor(evidence): read record subjects through the identity accessors in JS, managed, ledger and bundle readers (#11470) JavaScript application graphs, runtime reconciliation, managed inspection and native verification sources, the record summary filter, the ledger's residual-unknown target and bundle scope selection read the subject digest, format and display path through evidenceFileTarget and evidenceSubjectDisplay. No comparison changes: each reader matches one record's facts against its own payload or a caller filter. Refs #11417 * refactor(evidence)!: name the Evidence subject only by its target identity (#11497) * refactor(evidence)!: name the Evidence subject only by its target identity The subject keeps `identity` and the display facts `name` and `local_path`. The duplicated `digest`, `format` and `architecture` members are removed; the format-owned declaration now validates the identity itself. Readers the type checker found move to the owner accessors; untyped reads in verify scripts, the efficiency harness and test matchers move to `subject.identity`. The `evidence-subject-declaration-read` text guard and its baseline are deleted. Fixes #11473 Refs #11417 BREAKING CHANGE: the Evidence subject no longer has `digest`, `format` or `architecture`; read `subject.identity.sha256`, `subject.identity.format` and `subject.identity.architecture`. A record that still carries them is refused. * test(evidence): give the Flutter verifier fixture the identity subject and check the DOL declaration without the ID * test(evidence): drop the removed subject members from the declaration matrix and tamper fixtures * feat(evidence)!: give every Evidence record an explicit subject identity (#11536) * feat(evidence)!: give every Evidence record an explicit subject identity A producer that cannot name a file passes an `unknown` target identity with a closed reason (derived-from-linked-evidence, not-observed, unsupported-subject) instead of no subject. The subject is non-null; unknown subjects have no display facts. The generic missing-subject limitation and `subjectUnavailableReason` are removed; producer-specific explanations are ordinary limitations. Comparison identity requires the derived unknown, and null-subject consumers ask the owner accessors. Refs #11417 BREAKING CHANGE: every Evidence record has a subject. A record without a file target names `subject.identity` `{ "kind": "unknown", "reason": … }` with `name` and `local_path` null, instead of `subject: null` and the limitation "Artifact identity is unavailable for this observation.". Their Evidence IDs change. * fix(evidence): name explicit unknown subjects in JavaScript callers and keep a managed graph's file subject The verification scripts are not type-checked, so five createEvidence callers still passed undefined (or a missing first target) after the subject became required. They now pass unknownTarget("not-observed"). A managed application graph chose the first present input subject. Every subject is now present, so an unknown artifact subject hid a file subject on the member or boundary Evidence. The graph now takes the first input subject that names a file. * test(evidence): assert the subject kind instead of a presence the type now guarantees Every Evidence record has a subject after this change, so test guards and assertions that checked it for null always passed. Each now checks that the fixture subject names a file, or is removed where a later fileIdentity, fileSubjectTarget or fileSubjectDisplay call already requires that. Non-null assertions on Evidence subjects are removed; analysis-view inputs, whose subject is optional, keep an undefined check. * test(evidence): expect the Evidence subject format under its identity Two boundary tests still matched subject.format, which slice 2e moved into subject.identity. toMatchObject is not type-checked against the Evidence shape, so they failed only when run (the signature test on macOS).
653 lines
22 KiB
TypeScript
653 lines
22 KiB
TypeScript
import { fileIdentity } from "../../tests/fixtures/evidenceSubject.js";
|
|
import { expect, it } from "vitest";
|
|
import { WebNetworkCaptureService } from "./WebNetworkCaptureService.js";
|
|
import { historicalHar } from "../../tests/fixtures/historicalHar.js";
|
|
import { err, ok } from "../domain/result.js";
|
|
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
|
import { parseEvidence } from "../domain/evidence.js";
|
|
import {
|
|
AnalysisCancelledError,
|
|
AnalysisOutputError,
|
|
} from "../domain/analysisErrorCore.js";
|
|
import {
|
|
webNetworkCaptureSchema,
|
|
type WebNetworkCapture,
|
|
} from "../domain/webNetworkCapture.js";
|
|
import {
|
|
AnalysisCleanupLease,
|
|
AnalysisCleanupLeaseGroup,
|
|
} from "../resources/AnalysisCleanupLease.js";
|
|
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
|
|
import { analysisErrorWithCleanupFailure } from "../domain/analysisErrorCleanup.js";
|
|
|
|
it.each(["REDACTED", "[", "]", "/capture.har"])(
|
|
"excludes sensitive path text even when a replacement marker would collide: %s",
|
|
async (literal) => {
|
|
const report = fixture();
|
|
report.artifact.path = `/capture.har/${literal}`;
|
|
const result = await new WebNetworkCaptureService({
|
|
inspect: () => Promise.resolve(ok(report)),
|
|
}).inspect({
|
|
capture_path: report.artifact.path,
|
|
format: "har",
|
|
sensitive_values: [literal],
|
|
});
|
|
if (!result.ok) throw result.error;
|
|
expect(result.value.subject?.local_path).not.toContain(literal);
|
|
expect(result.value.parameters.capture_path).not.toContain(literal);
|
|
expect(
|
|
result.value.locations.every(
|
|
(location) =>
|
|
location.kind !== "artifact-path" || !location.path.includes(literal),
|
|
),
|
|
).toBe(true);
|
|
expect(fileIdentity(result.value.subject).sha256).toBe(
|
|
report.artifact.sha256,
|
|
);
|
|
},
|
|
);
|
|
|
|
it("records an explicit capture deadline and omits the default", async () => {
|
|
const seen: Array<number | undefined> = [];
|
|
const service = new WebNetworkCaptureService({
|
|
inspect: (input) => {
|
|
seen.push(input.capture_timeout_ms);
|
|
return Promise.resolve(ok(fixture()));
|
|
},
|
|
});
|
|
const explicit = await service.inspect({
|
|
capture_path: "/capture.har",
|
|
format: "har",
|
|
capture_timeout_ms: 250,
|
|
});
|
|
if (!explicit.ok) throw explicit.error;
|
|
expect(explicit.value.parameters.capture_timeout_ms).toBe(250);
|
|
const omitted = await service.inspect({
|
|
capture_path: "/capture.har",
|
|
format: "har",
|
|
});
|
|
if (!omitted.ok) throw omitted.error;
|
|
expect(omitted.value.parameters).not.toHaveProperty("capture_timeout_ms");
|
|
expect(seen).toEqual([250, undefined]);
|
|
});
|
|
|
|
it("keeps observed artifact identity when the entire sensitive path is excluded", async () => {
|
|
const result = await new WebNetworkCaptureService({
|
|
inspect: () => Promise.resolve(ok(fixture())),
|
|
}).inspect({
|
|
capture_path: "/capture.har",
|
|
format: "har",
|
|
sensitive_values: ["/", "[", "REDACTED"],
|
|
});
|
|
if (!result.ok) throw result.error;
|
|
expect(result.value.subject).toMatchObject({
|
|
local_path: "",
|
|
identity: { sha256: "a".repeat(64) },
|
|
});
|
|
expect(result.value.locations).toEqual([]);
|
|
});
|
|
|
|
const fixture = (): WebNetworkCapture => ({
|
|
decoder: { id: "test-historical-port", name: "test port", version: "1" },
|
|
container: {
|
|
reported: null,
|
|
numeric_literals: [],
|
|
redactions: [],
|
|
records_pointer: "/log/entries",
|
|
},
|
|
total_records: 1,
|
|
records: [
|
|
{
|
|
ordinal: 0,
|
|
location: { kind: "json-pointer", pointer: "/log/entries/0" },
|
|
reported: historicalHar().log.entries[0] ?? null,
|
|
numeric_literals: [],
|
|
binary_fields: [],
|
|
redactions: [],
|
|
limitations: [],
|
|
},
|
|
],
|
|
artifact: { path: "/capture.har", sha256: "a".repeat(64), bytes: 10 },
|
|
format: "har",
|
|
runtime_attribution: "unknown",
|
|
limitations: ["historical fixture"],
|
|
});
|
|
|
|
it.each(["a".repeat(64), "aaaa"])(
|
|
"marks an explicitly sensitive artifact digest unknown without inventing another identity: %s",
|
|
async (literal) => {
|
|
const result = await new WebNetworkCaptureService({
|
|
inspect: () => Promise.resolve(ok(fixture())),
|
|
}).inspect({
|
|
capture_path: "/capture.har",
|
|
format: "har",
|
|
sensitive_values: [literal],
|
|
});
|
|
if (!result.ok) throw result.error;
|
|
expect(result.value.subject.identity.kind).toBe("unknown");
|
|
expect(result.value.normalized_result).toMatchObject({
|
|
artifact: { path: "/capture.har", sha256: null, bytes: 10 },
|
|
});
|
|
expect(result.value.parameters.capture_path).toBe("/capture.har");
|
|
expect(result.value.locations).toEqual([
|
|
{ kind: "artifact-path", path: "/capture.har" },
|
|
]);
|
|
expect(parseEvidence(result.value)).toEqual(result.value);
|
|
},
|
|
);
|
|
|
|
it("projects the unknown-subject explanation before generating its Evidence ID", async () => {
|
|
const result = await new WebNetworkCaptureService({
|
|
inspect: () => Promise.resolve(ok(fixture())),
|
|
}).inspect({
|
|
capture_path: "/capture.har",
|
|
format: "har",
|
|
sensitive_values: ["a"],
|
|
});
|
|
if (!result.ok) throw result.error;
|
|
expect(result.value.subject.identity.kind).toBe("unknown");
|
|
expect(result.value.limitations).toContainEqual(
|
|
expect.stringMatching(/digest.*unknown.*Evidence/u),
|
|
);
|
|
expect(result.value.limitations.every((text) => !text.includes("a"))).toBe(
|
|
true,
|
|
);
|
|
expect(parseEvidence(result.value)).toEqual(result.value);
|
|
});
|
|
|
|
it("rejects an adapter omitting its original observed digest before caller projection", async () => {
|
|
const report = fixture();
|
|
report.artifact.sha256 = null;
|
|
const result = await new WebNetworkCaptureService({
|
|
inspect: () => Promise.resolve(ok(report)),
|
|
}).inspect({ capture_path: report.artifact.path, format: "har" });
|
|
expect(result.ok).toBe(false);
|
|
if (!result.ok) expect(result.error._tag).toBe("AnalysisOutputError");
|
|
});
|
|
|
|
it("retains valid completed capture Evidence on late cancellation and preserves invalid output", async () => {
|
|
const controller = new AbortController();
|
|
const report = fixture();
|
|
const late = await new WebNetworkCaptureService({
|
|
inspect: () => {
|
|
controller.abort();
|
|
return Promise.resolve(ok(report));
|
|
},
|
|
}).inspect(
|
|
{ capture_path: report.artifact.path, format: "har" },
|
|
{ signal: controller.signal },
|
|
);
|
|
expect(late.ok).toBe(false);
|
|
if (!late.ok) {
|
|
expect(late.error).toBeInstanceOf(AnalysisCancelledError);
|
|
expect(parseEvidence(late.error.partialObservation)).toMatchObject({
|
|
operation: "inspect_web_network_capture",
|
|
normalized_result: expect.objectContaining({ total_records: 1 }),
|
|
});
|
|
}
|
|
|
|
const malformed = fixture();
|
|
malformed.artifact.path = "/other.har";
|
|
const outputController = new AbortController();
|
|
const invalid = await new WebNetworkCaptureService({
|
|
inspect: () => {
|
|
outputController.abort();
|
|
return Promise.resolve(ok(malformed));
|
|
},
|
|
}).inspect(
|
|
{ capture_path: "/capture.har", format: "har" },
|
|
{ signal: outputController.signal },
|
|
);
|
|
expect(invalid.ok).toBe(false);
|
|
if (!invalid.ok) expect(invalid.error).toBeInstanceOf(AnalysisOutputError);
|
|
});
|
|
|
|
it("projects completed raw capture facts on failure through the sensitivity rules", async () => {
|
|
const report = fixture();
|
|
report.artifact.path = "/private-marker/capture.har";
|
|
report.limitations = ["private-marker producer limitation"];
|
|
const reason = { request: "cancel after decoder completion" };
|
|
const error = new AnalysisCancelledError("inspect_web_network_capture", {
|
|
cause: reason,
|
|
partialObservation: report,
|
|
});
|
|
const result = await new WebNetworkCaptureService({
|
|
inspect: () => Promise.resolve({ ok: false, error }),
|
|
}).inspect(
|
|
{
|
|
capture_path: report.artifact.path,
|
|
format: "har",
|
|
record_ordinals: [0],
|
|
sensitive_values: ["private-marker"],
|
|
},
|
|
undefined,
|
|
);
|
|
if (result.ok) throw new Error("Cancellation must remain the primary result");
|
|
expect(result.error._tag).toBe("AnalysisCancelledError");
|
|
expect(result.error.cause).toBe(reason);
|
|
const partial = parseEvidence(result.error.partialObservation);
|
|
expect(partial).toMatchObject({
|
|
operation: "inspect_web_network_capture",
|
|
parameters: { record_ordinals: [0] },
|
|
subject: { local_path: "" },
|
|
normalized_result: {
|
|
artifact: { path: "", sha256: "a".repeat(64) },
|
|
records: [{ ordinal: 0 }],
|
|
},
|
|
});
|
|
// Caller spellings belong to the CLI delivery, not the service.
|
|
expect(partial.caller_input_path).toBeUndefined();
|
|
expect(JSON.stringify(partial)).not.toContain("private-marker");
|
|
});
|
|
|
|
it("does not expose a malformed capture-shaped partial observation", async () => {
|
|
const malformed = fixture();
|
|
malformed.artifact.path = "/private-marker";
|
|
malformed.artifact.sha256 = "invalid";
|
|
const error = new AnalysisCancelledError("inspect_web_network_capture", {
|
|
partialObservation: malformed,
|
|
});
|
|
const result = await new WebNetworkCaptureService({
|
|
inspect: () => Promise.resolve({ ok: false, error }),
|
|
}).inspect({
|
|
capture_path: "/capture.har",
|
|
format: "har",
|
|
sensitive_values: ["private-marker"],
|
|
});
|
|
expect(result.ok).toBe(false);
|
|
if (!result.ok) expect(result.error.partialObservation).toBeUndefined();
|
|
});
|
|
|
|
it("does not recover a rejected capture from a cleanup primary", async () => {
|
|
const malformed = fixture();
|
|
malformed.artifact.sha256 = "invalid";
|
|
malformed.limitations = ["rejected-capture-only-marker"];
|
|
const primary = new AnalysisCancelledError("inspect_web_network_capture", {
|
|
partialObservation: malformed,
|
|
});
|
|
const cleanup = new ProviderCleanupError("fixture", ["workspace"], {});
|
|
const error = analysisErrorWithCleanupFailure(primary, cleanup);
|
|
const result = await new WebNetworkCaptureService({
|
|
inspect: async () => err(error),
|
|
}).inspect({ capture_path: "/capture.har", format: "har" });
|
|
if (result.ok) throw new Error("expected rejected capture");
|
|
const projected = projectAnalysisError(result.error);
|
|
expect(projected.code).toBe("cleanup_incomplete");
|
|
expect(JSON.stringify(projected)).not.toContain(
|
|
"rejected-capture-only-marker",
|
|
);
|
|
});
|
|
|
|
it("keeps a redacted cleanup error linked to its live owner through service close", async () => {
|
|
const report = fixture();
|
|
const cleanupPath = "/tmp/private-marker-capture-root";
|
|
const lease = new AnalysisCleanupLease(async () => {}, [cleanupPath]);
|
|
const original = new ProviderCleanupError(
|
|
"test-capture",
|
|
[cleanupPath],
|
|
{ reason: "private-marker cleanup remains pending" },
|
|
{
|
|
operation: "inspect_web_network_capture",
|
|
partialObservation: report,
|
|
},
|
|
);
|
|
new AnalysisCleanupLeaseGroup(original, [lease]);
|
|
const service = new WebNetworkCaptureService({
|
|
inspect: () => Promise.resolve(err(original)),
|
|
close: () => lease.release(),
|
|
});
|
|
const result = await service.inspect({
|
|
capture_path: report.artifact.path,
|
|
format: "har",
|
|
sensitive_values: ["private-marker"],
|
|
});
|
|
if (result.ok) throw new Error("Retained cleanup must remain a failure");
|
|
const returnedError = result.error;
|
|
expect(returnedError.cleanupIncomplete).toBe(true);
|
|
expect(returnedError.cleanupResources).toEqual([
|
|
"/tmp/[REDACTED]-capture-root",
|
|
]);
|
|
expect(JSON.stringify(projectAnalysisError(returnedError))).not.toContain(
|
|
"private-marker",
|
|
);
|
|
expect(parseEvidence(returnedError.partialObservation)).toMatchObject({
|
|
operation: "inspect_web_network_capture",
|
|
});
|
|
|
|
await service.close();
|
|
expect(returnedError.cleanupIncomplete).toBe(false);
|
|
expect(returnedError.cleanupResources).toEqual([]);
|
|
});
|
|
|
|
it.each([
|
|
["producer"],
|
|
["artifact"],
|
|
["coordinates"],
|
|
["producer", "REDACTED", "…"],
|
|
["producer", "[", "]"],
|
|
])(
|
|
"excludes declared literals from all authored limitations: %j",
|
|
async (...literals) => {
|
|
const report = fixture();
|
|
report.artifact.path = "/artifact/capture.har";
|
|
report.limitations = [
|
|
"Historical producer artifact coordinates are retained.",
|
|
];
|
|
const first = report.records[0];
|
|
if (first === undefined) throw new Error("fixture missing record");
|
|
first.limitations = ["This is producer-decoded artifact evidence."];
|
|
const result = await new WebNetworkCaptureService({
|
|
inspect: () => Promise.resolve(ok(report)),
|
|
}).inspect({
|
|
capture_path: report.artifact.path,
|
|
format: "har",
|
|
sensitive_values: literals,
|
|
});
|
|
if (!result.ok) throw result.error;
|
|
const projected = webNetworkCaptureSchema.parse(
|
|
result.value.normalized_result,
|
|
);
|
|
const texts = [
|
|
result.value.limitations,
|
|
projected.limitations,
|
|
...projected.records.map((record) => record.limitations),
|
|
].flat();
|
|
for (const literal of literals)
|
|
expect(texts.every((text) => !text.includes(literal))).toBe(true);
|
|
expect(fileIdentity(result.value.subject).sha256).toBe(
|
|
report.artifact.sha256,
|
|
);
|
|
expect(projected.decoder).toEqual(report.decoder);
|
|
expect(projected.records[0]?.reported).toEqual(first.reported);
|
|
},
|
|
);
|
|
|
|
it("keeps explicitly sensitive values out of Evidence parameters and preserves historical authority", async () => {
|
|
const service = new WebNetworkCaptureService({
|
|
inspect: () => Promise.resolve(ok(fixture())),
|
|
});
|
|
const result = await service.inspect({
|
|
capture_path: "/capture.har",
|
|
format: "har",
|
|
sensitive_values: ["explicit-private-value"],
|
|
});
|
|
if (!result.ok) throw result.error;
|
|
expect(result.value.parameters).toMatchObject({
|
|
sensitive_value_count: 1,
|
|
record_ordinals: [0],
|
|
});
|
|
expect(JSON.stringify(result.value)).not.toContain("explicit-private-value");
|
|
expect(result.value.authority).toBe("historical-reference");
|
|
expect(result.value.provider).toEqual(fixture().decoder);
|
|
});
|
|
|
|
it.each(["har", "ha"])(
|
|
"omits a format parameter containing a declared sensitive literal: %s",
|
|
async (literal) => {
|
|
const result = await new WebNetworkCaptureService({
|
|
inspect: () => Promise.resolve(ok(fixture())),
|
|
}).inspect({
|
|
capture_path: "/capture.har",
|
|
format: "har",
|
|
sensitive_values: [literal],
|
|
});
|
|
if (!result.ok) throw result.error;
|
|
expect(result.value.parameters).not.toHaveProperty("format");
|
|
expect(JSON.stringify(result.value.parameters)).not.toContain(literal);
|
|
expect(result.value.normalized_result).toMatchObject({ format: "har" });
|
|
},
|
|
);
|
|
|
|
it.each([
|
|
{ record_ordinals: [0, 0] },
|
|
{ record_ordinals: [1] },
|
|
{ capture_path: "relative.har" },
|
|
])("rejects invalid caller selection %j", async (extra) => {
|
|
const result = await new WebNetworkCaptureService({
|
|
inspect: () => Promise.resolve(ok(fixture())),
|
|
}).inspect({ capture_path: "/capture.har", format: "har", ...extra });
|
|
expect(result.ok).toBe(false);
|
|
if (!result.ok) expect(result.error._tag).toBe("AnalysisInputError");
|
|
});
|
|
|
|
it("reports an ordinal past the capture's records as an out-of-range selection", async () => {
|
|
const report = fixture();
|
|
const result = await new WebNetworkCaptureService({
|
|
inspect: () => Promise.resolve(ok(report)),
|
|
}).inspect({
|
|
capture_path: "/capture.har",
|
|
format: "har",
|
|
record_ordinals: [0, 5],
|
|
});
|
|
if (result.ok) throw new Error("expected an out-of-range ordinal");
|
|
expect(projectAnalysisError(result.error)).toMatchObject({
|
|
code: "invalid_request",
|
|
details: {
|
|
issues: [
|
|
{
|
|
path: ["record_ordinals", 1],
|
|
reason: "out_of_range",
|
|
minimum: 0,
|
|
maximum: report.total_records - 1,
|
|
},
|
|
],
|
|
},
|
|
});
|
|
});
|
|
|
|
it("rejects a port changing the artifact identity or producer ordinal sequence", async () => {
|
|
const report = fixture();
|
|
report.artifact.path = "/different.har";
|
|
const result = await new WebNetworkCaptureService({
|
|
inspect: () => Promise.resolve(ok(report)),
|
|
}).inspect({ capture_path: "/capture.har", format: "har" });
|
|
expect(result.ok).toBe(false);
|
|
if (!result.ok) expect(result.error._tag).toBe("AnalysisOutputError");
|
|
});
|
|
|
|
it("applies an explicit sensitive path literal after verifying the selected artifact", async () => {
|
|
const result = await new WebNetworkCaptureService({
|
|
inspect: () => Promise.resolve(ok(fixture())),
|
|
}).inspect({
|
|
capture_path: "/capture.har",
|
|
format: "har",
|
|
sensitive_values: ["capture.har"],
|
|
});
|
|
if (!result.ok) throw result.error;
|
|
expect(JSON.stringify(result.value)).not.toContain("capture.har");
|
|
expect(result.value.parameters.capture_path).toBe("");
|
|
});
|
|
|
|
it.each(["log", "entries"])(
|
|
"excludes a sensitive producer coordinate without inventing a replacement: %s",
|
|
async (literal) => {
|
|
const result = await new WebNetworkCaptureService({
|
|
inspect: () => Promise.resolve(ok(fixture())),
|
|
}).inspect({
|
|
capture_path: "/capture.har",
|
|
format: "har",
|
|
sensitive_values: [literal],
|
|
});
|
|
if (!result.ok) throw result.error;
|
|
expect(result.value.normalized_result).toMatchObject({
|
|
container: { records_pointer: null },
|
|
records: [
|
|
{
|
|
ordinal: 0,
|
|
location: { kind: "unknown", reason: "explicit-sensitive-value" },
|
|
},
|
|
],
|
|
});
|
|
expect(JSON.stringify(result.value)).not.toContain(literal);
|
|
},
|
|
);
|
|
|
|
it("excludes an escaped sensitive sidecar coordinate while preserving its reported field", async () => {
|
|
const report = fixture();
|
|
report.container.reported = { "field/name": 42 };
|
|
report.container.numeric_literals = [
|
|
{ pointer: "/field~1name", producer_type: "json-number", literal: "42" },
|
|
];
|
|
report.container.redactions = [
|
|
{ pointer: "/field~1name", reason: "explicit-sensitive-value" },
|
|
];
|
|
const result = await new WebNetworkCaptureService({
|
|
inspect: () => Promise.resolve(ok(report)),
|
|
}).inspect({
|
|
capture_path: "/capture.har",
|
|
format: "har",
|
|
sensitive_values: ["~1"],
|
|
});
|
|
if (!result.ok) throw result.error;
|
|
expect(result.value.normalized_result).toMatchObject({
|
|
container: {
|
|
reported: { "field/name": 42 },
|
|
numeric_literals: [],
|
|
redactions: [],
|
|
},
|
|
});
|
|
expect(JSON.stringify(result.value)).not.toContain("~1");
|
|
});
|
|
|
|
it.each([
|
|
{ literal: "12345", input: { record_ordinals: [12345] } },
|
|
{ literal: "Each", input: { record_ordinals: [0, 0] } },
|
|
{ literal: "absolute", input: { capture_path: "relative.har" } },
|
|
{ literal: "secret", input: { mysecret: true } },
|
|
])(
|
|
"excludes declared text from application-generated input errors: $literal",
|
|
async ({ literal, input }) => {
|
|
const result = await new WebNetworkCaptureService({
|
|
inspect: () => Promise.resolve(ok(fixture())),
|
|
}).inspect({
|
|
capture_path: "/capture.har",
|
|
format: "har",
|
|
sensitive_values: [literal],
|
|
...input,
|
|
});
|
|
if (result.ok) throw new Error("Expected invalid selection");
|
|
expect(result.error._tag).toBe("AnalysisInputError");
|
|
expect(JSON.stringify(projectAnalysisError(result.error))).not.toContain(
|
|
literal,
|
|
);
|
|
},
|
|
);
|
|
|
|
it.each(["12345", "67890", "234", "789"])(
|
|
"excludes sensitive native byte-range coordinates: %s",
|
|
async (literal) => {
|
|
const report = fixture();
|
|
report.format = "mitmproxy";
|
|
report.artifact.path = "/capture.mitm";
|
|
const record = report.records[0];
|
|
if (record === undefined) throw new Error("record missing");
|
|
record.location = { kind: "byte-range", offset: 12345, bytes: 67890 };
|
|
const result = await new WebNetworkCaptureService({
|
|
inspect: () => Promise.resolve(ok(report)),
|
|
}).inspect({
|
|
capture_path: report.artifact.path,
|
|
format: "mitmproxy",
|
|
sensitive_values: [literal],
|
|
});
|
|
if (!result.ok) throw result.error;
|
|
expect(result.value.normalized_result).toMatchObject({
|
|
records: [
|
|
{ location: { kind: "unknown", reason: "explicit-sensitive-value" } },
|
|
],
|
|
});
|
|
expect(result.value.raw_result).toBeNull();
|
|
expect(parseEvidence(result.value)).toEqual(result.value);
|
|
},
|
|
);
|
|
|
|
it("preserves a pre-abort reason without entering the capture adapter", async () => {
|
|
const reason = new Error("stop historical capture inspection");
|
|
const controller = new AbortController();
|
|
controller.abort(reason);
|
|
let providerCalls = 0;
|
|
const service = new WebNetworkCaptureService({
|
|
inspect: async () => {
|
|
providerCalls += 1;
|
|
return ok(fixture());
|
|
},
|
|
});
|
|
|
|
const result = await service.inspect(
|
|
{
|
|
capture_path: "/capture.har",
|
|
format: "har",
|
|
sensitive_values: [],
|
|
},
|
|
{ signal: controller.signal },
|
|
);
|
|
|
|
expect(result.ok).toBe(false);
|
|
if (!result.ok) {
|
|
expect(result.error).toBeInstanceOf(AnalysisCancelledError);
|
|
expect(result.error.cause).toBe(reason);
|
|
}
|
|
expect(providerCalls).toBe(0);
|
|
});
|
|
|
|
it("reports malformed retained facts while keeping their cleanup owner retryable", async () => {
|
|
const report = fixture();
|
|
report.artifact.sha256 = "invalid";
|
|
const lease = new AnalysisCleanupLease(async () => {}, [
|
|
"/tmp/private-marker-root",
|
|
]);
|
|
const cleanup = new ProviderCleanupError(
|
|
"test-historical-port",
|
|
["/tmp/private-marker-root"],
|
|
{ reason: "close denied" },
|
|
{ operation: "inspect_web_network_capture", partialObservation: report },
|
|
);
|
|
new AnalysisCleanupLeaseGroup(cleanup, [lease]);
|
|
const service = new WebNetworkCaptureService({
|
|
inspect: async () => err(cleanup),
|
|
close: async () => {
|
|
await lease.release();
|
|
},
|
|
});
|
|
const result = await service.inspect({
|
|
capture_path: "/capture.har",
|
|
format: "har",
|
|
sensitive_values: ["private-marker"],
|
|
});
|
|
if (result.ok) throw new Error("Expected malformed retained evidence");
|
|
expect(result.error.cleanupIncomplete).toBe(true);
|
|
expect(result.error.cleanupPrimary).toBeInstanceOf(AnalysisOutputError);
|
|
expect(result.error.partialObservation).toBeUndefined();
|
|
expect(JSON.stringify(projectAnalysisError(result.error))).not.toContain(
|
|
"private-marker",
|
|
);
|
|
await service.close();
|
|
expect(result.error.cleanupIncomplete).toBe(false);
|
|
expect(projectAnalysisError(result.error).code).toBe("unreadable_output");
|
|
});
|
|
|
|
it("rejects relative descriptor paths before starting a capture decoder", async () => {
|
|
const service = new WebNetworkCaptureService({
|
|
inspect: () => {
|
|
throw new Error("Invalid input must fail before provider admission");
|
|
},
|
|
});
|
|
const result = await service.inspect({
|
|
capture_path: "/capture.har",
|
|
format: "har",
|
|
record_ordinals: [0],
|
|
protobuf: {
|
|
schema: {
|
|
descriptor_set_path: "relative.pb",
|
|
message_type: "capture.Message",
|
|
},
|
|
},
|
|
});
|
|
if (result.ok) throw new Error("Expected typed invalid input");
|
|
expect(projectAnalysisError(result.error)).toMatchObject({
|
|
code: "invalid_request",
|
|
details: {
|
|
issues: [{ path: ["protobuf", "schema", "descriptor_set_path"] }],
|
|
},
|
|
});
|
|
});
|