feat(browser): inspect historical web network captures (#992)
* feat(browser): inspect retained HAR and mitmproxy capture evidence Add independent offline format adapters, inline CLI/MCP evidence, bounded owned decoder processes, and real producer verification. Refs #882 Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) * fix(browser): preserve capture boundaries during cancellation and decoding Honor cancellation during owned-command cleanup, retain opaque HAR extension content, and clean verifier resources on every failure path. Refs #882 Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) * fix(browser): exclude sensitive capture fields across representations Normalize known native transport URLs for both bytes and strings, including backups. Exclude explicitly sensitive text fields with null so redaction markers cannot reintroduce declared literals. Cover both provider identities in catalog conformance. Refs #882 Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) * fix(browser): exclude sensitive capture identities and bound diagnostics * fix(browser): validate excluded HAR subtrees before projection * fix(browser): distinguish capture input limits from decoder failures * fix(browser): preserve decoder failure categories * fix(browser): validate excluded native credential values * test(browser): report capture verifier assertions directly * fix(browser): classify native representation failures precisely * fix(browser): exclude URL userinfo after header whitespace * fix(browser): preserve capture evidence and failure boundaries * fix(browser): exclude sensitive literals from capture limitations * test(browser): check limitation values without JSON syntax * fix(browser): preserve acquisition integrity and exclude selection diagnostics * fix(browser): preserve capture acquisition and declaration boundaries * fix(mcp): project sensitive capture argument validation * fix: preserve capture bytes and prelaunch cancellation * fix(browser): exclude sensitive HAR record ancestry * fix(browser): preserve transport URL and parameter exclusions * fix(browser): preserve numeric redaction and canonical capture provenance * fix(browser): cover derived capture values and ownership preparation deadlines * fix(browser): exclude explicitly sensitive artifact digests * chore: regenerate generated metadata * fix(browser): reject lossy HAR member normalization * test(browser): assert the advertised unsupported-profile outcome * fix(browser): preserve JSON visitor nesting failure locations * fix(browser): exclude explicitly sensitive native source ranges --------- Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
Kaoru0822
github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
parent
6e4535c101
commit
2bf3663f65
@@ -0,0 +1,15 @@
|
||||
import type { ExecutionOptions } from "./AnalysisProvider.js";
|
||||
import type { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import type { Result } from "../domain/result.js";
|
||||
import type {
|
||||
InspectWebNetworkCaptureInput,
|
||||
WebNetworkCapture,
|
||||
} from "../domain/webNetworkCapture.js";
|
||||
|
||||
/** Replaceable offline capture port; producer protocols remain in format adapters. */
|
||||
export interface WebNetworkCapturePort {
|
||||
inspect(
|
||||
input: InspectWebNetworkCaptureInput,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<WebNetworkCapture, AnalysisError>>;
|
||||
}
|
||||
@@ -0,0 +1,340 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { WebNetworkCaptureService } from "./WebNetworkCaptureService.js";
|
||||
import { historicalHar } from "../../tests/fixtures/historicalHar.js";
|
||||
import { ok } from "../domain/result.js";
|
||||
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||
import { parseEvidence } from "../domain/evidence.js";
|
||||
import {
|
||||
webNetworkCaptureSchema,
|
||||
type WebNetworkCapture,
|
||||
} from "../domain/webNetworkCapture.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(result.value.subject?.digest.sha256).toBe(report.artifact.sha256);
|
||||
},
|
||||
);
|
||||
|
||||
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: "",
|
||||
digest: { 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).toBeNull();
|
||||
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).toBeNull();
|
||||
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.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(result.value.subject?.digest.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("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);
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,202 @@
|
||||
import { redactExplicitFailure } from "../domain/explicitSensitiveFailure.js";
|
||||
import { excludeCaptureCoordinates } from "../domain/webNetworkCaptureCoordinates.js";
|
||||
import { redactExplicitText } from "../domain/explicitSensitiveValues.js";
|
||||
import { isAbsolute } from "node:path";
|
||||
import type { ExecutionOptions } from "./AnalysisProvider.js";
|
||||
import type { WebNetworkCapturePort } from "./WebNetworkCapturePort.js";
|
||||
import type { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import {
|
||||
AnalysisCancelledError,
|
||||
AnalysisInputError,
|
||||
AnalysisOutputError,
|
||||
} from "../domain/analysisErrorCore.js";
|
||||
import { createEvidence, type Evidence } from "../domain/evidence.js";
|
||||
import { projectInputIssues } from "../domain/inputIssueProjection.js";
|
||||
import { jsonObjectSchema } from "../domain/jsonValue.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import {
|
||||
inspectWebNetworkCaptureInputSchema,
|
||||
webNetworkCaptureSchema,
|
||||
} from "../domain/webNetworkCapture.js";
|
||||
|
||||
const OPERATION = "inspect_web_network_capture";
|
||||
|
||||
/** Shared CLI/MCP historical inspection preserves caller selection and producer record identity. */
|
||||
export class WebNetworkCaptureService {
|
||||
constructor(readonly port: WebNetworkCapturePort) {}
|
||||
|
||||
/** Return selected complete records inline, without inventing live browser attribution. */
|
||||
async inspect(
|
||||
rawInput: unknown,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<Evidence, AnalysisError>> {
|
||||
if (options?.signal?.aborted)
|
||||
return err(new AnalysisCancelledError(OPERATION));
|
||||
const declarations =
|
||||
inspectWebNetworkCaptureInputSchema.shape.sensitive_values.safeParse(
|
||||
typeof rawInput === "object" &&
|
||||
rawInput !== null &&
|
||||
"sensitive_values" in rawInput
|
||||
? rawInput.sensitive_values
|
||||
: undefined,
|
||||
);
|
||||
const failure = (error: AnalysisError): Result<never, AnalysisError> =>
|
||||
err(
|
||||
redactExplicitFailure(
|
||||
error,
|
||||
declarations.success ? declarations.data : [],
|
||||
),
|
||||
);
|
||||
const parsed = inspectWebNetworkCaptureInputSchema.safeParse(rawInput);
|
||||
if (!parsed.success)
|
||||
return failure(
|
||||
new AnalysisInputError(
|
||||
OPERATION,
|
||||
{ cause: parsed.error },
|
||||
projectInputIssues(parsed.error.issues, rawInput),
|
||||
),
|
||||
);
|
||||
const input = parsed.data;
|
||||
if (!isAbsolute(input.capture_path))
|
||||
return failure(
|
||||
new AnalysisInputError(OPERATION, undefined, [
|
||||
{
|
||||
path: ["capture_path"],
|
||||
reason: "invalid_format",
|
||||
message: "Expected an absolute filesystem path on this host.",
|
||||
},
|
||||
]),
|
||||
);
|
||||
if (
|
||||
input.record_ordinals !== undefined &&
|
||||
new Set(input.record_ordinals).size !== input.record_ordinals.length
|
||||
)
|
||||
return failure(
|
||||
new AnalysisInputError(OPERATION, undefined, [
|
||||
{
|
||||
path: ["record_ordinals"],
|
||||
reason: "invalid_format",
|
||||
message: "Each requested producer ordinal must occur once.",
|
||||
},
|
||||
]),
|
||||
);
|
||||
const loaded = await this.port.inspect(input, options);
|
||||
if (!loaded.ok) return failure(loaded.error);
|
||||
if (options?.signal?.aborted)
|
||||
return failure(new AnalysisCancelledError(OPERATION));
|
||||
const report = webNetworkCaptureSchema.safeParse(loaded.value);
|
||||
if (!report.success)
|
||||
return failure(
|
||||
new AnalysisOutputError(
|
||||
OPERATION,
|
||||
"Capture adapter returned malformed historical evidence.",
|
||||
),
|
||||
);
|
||||
const value = report.data;
|
||||
const artifactSha256 = value.artifact.sha256;
|
||||
if (artifactSha256 === null)
|
||||
return failure(
|
||||
new AnalysisOutputError(
|
||||
OPERATION,
|
||||
"Capture adapter omitted its observed artifact digest before explicit projection.",
|
||||
),
|
||||
);
|
||||
if (
|
||||
value.artifact.path !== input.capture_path ||
|
||||
value.format !== input.format ||
|
||||
value.total_records !== value.records.length ||
|
||||
value.records.some((record, index) => record.ordinal !== index)
|
||||
)
|
||||
return failure(
|
||||
new AnalysisOutputError(
|
||||
OPERATION,
|
||||
"Capture adapter changed the selected artifact, format or original record sequence.",
|
||||
),
|
||||
);
|
||||
const safeValue = excludeCaptureCoordinates(value, input.sensitive_values);
|
||||
const redactText = (text: string): string =>
|
||||
redactExplicitText(text, input.sensitive_values);
|
||||
const selected =
|
||||
input.record_ordinals ?? value.records.map(({ ordinal }) => ordinal);
|
||||
const records = [];
|
||||
for (const ordinal of selected) {
|
||||
const record = safeValue.records[ordinal];
|
||||
if (record === undefined)
|
||||
return failure(
|
||||
new AnalysisInputError(OPERATION, undefined, [
|
||||
{
|
||||
path: ["record_ordinals"],
|
||||
reason: "invalid_format",
|
||||
message: `Producer ordinal ${ordinal} is outside the retained capture (${value.total_records} records).`,
|
||||
},
|
||||
]),
|
||||
);
|
||||
records.push({
|
||||
...record,
|
||||
limitations: record.limitations.map(redactText),
|
||||
});
|
||||
}
|
||||
const safePath = input.sensitive_values.some((literal) =>
|
||||
input.capture_path.includes(literal),
|
||||
)
|
||||
? ""
|
||||
: input.capture_path;
|
||||
const safeSha256 = input.sensitive_values.some((literal) =>
|
||||
artifactSha256.includes(literal),
|
||||
)
|
||||
? null
|
||||
: artifactSha256;
|
||||
const subjectUnavailableReason = redactText(
|
||||
"The explicitly sensitive artifact digest is excluded; its cryptographic identity is unknown in this Evidence.",
|
||||
);
|
||||
const limitations = [
|
||||
...safeValue.limitations,
|
||||
...(safePath === ""
|
||||
? [
|
||||
"The explicitly sensitive artifact path is excluded; its size remains available.",
|
||||
]
|
||||
: []),
|
||||
].map(redactText);
|
||||
const parameters = jsonObjectSchema.parse({
|
||||
capture_path: safePath,
|
||||
...(input.sensitive_values.some((literal) =>
|
||||
input.format.includes(literal),
|
||||
)
|
||||
? {}
|
||||
: { format: input.format }),
|
||||
record_ordinals: selected,
|
||||
sensitive_value_count: input.sensitive_values.length,
|
||||
});
|
||||
return ok(
|
||||
createEvidence(
|
||||
safeSha256 === null
|
||||
? undefined
|
||||
: {
|
||||
path: safePath,
|
||||
sha256: safeSha256,
|
||||
format: "file",
|
||||
},
|
||||
value.decoder,
|
||||
{
|
||||
operation: OPERATION,
|
||||
parameters,
|
||||
result: {
|
||||
...safeValue,
|
||||
artifact: { ...value.artifact, path: safePath, sha256: safeSha256 },
|
||||
records,
|
||||
limitations:
|
||||
safeSha256 === null
|
||||
? [...limitations, subjectUnavailableReason]
|
||||
: limitations,
|
||||
},
|
||||
confidence: "observed",
|
||||
authority: "historical-reference",
|
||||
limitations,
|
||||
...(safeSha256 === null ? { subjectUnavailableReason } : {}),
|
||||
locations:
|
||||
safePath === "" ? [] : [{ kind: "artifact-path", path: safePath }],
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user