diff --git a/src/application/WebNetworkCaptureService.test.ts b/src/application/WebNetworkCaptureService.test.ts index 4674ef12da..fa66539487 100644 --- a/src/application/WebNetworkCaptureService.test.ts +++ b/src/application/WebNetworkCaptureService.test.ts @@ -199,7 +199,7 @@ it("retains valid completed capture Evidence on late cancellation and preserves if (!invalid.ok) expect(invalid.error).toBeInstanceOf(AnalysisOutputError); }); -it("projects completed raw capture facts on failure through the caller's selection and sensitivity rules", async () => { +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"]; @@ -218,7 +218,6 @@ it("projects completed raw capture facts on failure through the caller's selecti sensitive_values: ["private-marker"], }, undefined, - { capture: "./capture.har" }, ); if (result.ok) throw new Error("Cancellation must remain the primary result"); expect(result.error._tag).toBe("AnalysisCancelledError"); @@ -226,7 +225,6 @@ it("projects completed raw capture facts on failure through the caller's selecti const partial = parseEvidence(result.error.partialObservation); expect(partial).toMatchObject({ operation: "inspect_web_network_capture", - caller_input_path: "./capture.har", parameters: { record_ordinals: [0] }, subject: { local_path: "" }, normalized_result: { @@ -234,6 +232,8 @@ it("projects completed raw capture facts on failure through the caller's selecti 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"); }); diff --git a/src/application/WebNetworkCaptureService.ts b/src/application/WebNetworkCaptureService.ts index b772c8eb25..315f8ce1d6 100644 --- a/src/application/WebNetworkCaptureService.ts +++ b/src/application/WebNetworkCaptureService.ts @@ -10,11 +10,7 @@ import { cancelledBy, } from "../domain/analysisErrorCore.js"; import { createAnalysisProfile } from "../domain/analysisProfile.js"; -import { - createEvidence, - withEvidenceCallerInputPath, - type Evidence, -} from "../domain/evidence.js"; +import { createEvidence, type Evidence } from "../domain/evidence.js"; import { analysisInputErrorFromIssues } from "../domain/inputIssueProjection.js"; import { jsonObjectSchema } from "../domain/jsonValue.js"; import { err, ok, type Result } from "../domain/result.js"; @@ -43,7 +39,6 @@ export class WebNetworkCaptureService { async inspect( rawInput: unknown, options?: ExecutionOptions, - callerPaths?: { readonly capture: string; readonly descriptor?: string }, ): Promise> { if (options?.signal?.aborted) return err(cancelledBy(OPERATION, options.signal)); @@ -88,11 +83,7 @@ export class WebNetworkCaptureService { ); let partialFailure: AnalysisError | undefined; if (partial.success) { - const projected = this.#projectCapture( - input, - partial.data, - callerPaths, - ); + const projected = this.#projectCapture(input, partial.data); if (projected.ok) loaded.error.partialObservation = projected.value; else partialFailure = projected.error; } else if (isCapturePartialCandidate(loaded.error.partialObservation)) { @@ -133,7 +124,7 @@ export class WebNetworkCaptureService { "Capture adapter returned malformed historical evidence.", ), ); - const projected = this.#projectCapture(input, report.data, callerPaths); + const projected = this.#projectCapture(input, report.data); if (!projected.ok) return failure(projected.error); return completeProviderEvidence(projected.value, options?.signal); } @@ -141,7 +132,6 @@ export class WebNetworkCaptureService { #projectCapture( input: InspectWebNetworkCaptureInput, value: WebNetworkCapture, - callerPaths?: { readonly capture: string; readonly descriptor?: string }, ): Result { const artifactSha256 = value.artifact.sha256; if (artifactSha256 === null) @@ -294,20 +284,7 @@ export class WebNetworkCaptureService { safePath === "" ? [] : [{ kind: "artifact-path", path: safePath }], }, ); - if (callerPaths === undefined) return ok(evidence); - const safeCallerPath = (path: string | undefined) => - path === undefined || isSensitive(path) ? undefined : path; - const callerPath = safeCallerPath(callerPaths.capture); - const descriptor = safeCallerPath(callerPaths.descriptor); - return ok( - withEvidenceCallerInputPath( - evidence, - callerPath, - descriptor === undefined - ? undefined - : { descriptor_set_path: descriptor }, - ), - ); + return ok(evidence); } } diff --git a/src/cli/analysisEvidenceDelivery.ts b/src/cli/analysisEvidenceDelivery.ts index a0ade8c4b2..3c72ee6df2 100644 --- a/src/cli/analysisEvidenceDelivery.ts +++ b/src/cli/analysisEvidenceDelivery.ts @@ -1,3 +1,4 @@ +import { explicitValuesOccurIn } from "../domain/explicitSensitiveValues.js"; import { recordCliEvidencePublication } from "./cliEvidencePublication.js"; import { analysisEvidenceSources, @@ -133,14 +134,16 @@ export const deliverCliAnalysisEvidence = async ( undefined, { redactFailure }, ).then(projectCliAnalysisResult); + const callerInputPath = + input.callerInputPath === undefined || + revealsSensitiveValue(input.callerInputPath, input) + ? undefined + : input.callerInputPath; + const callerInputPaths = safeCallerInputPaths(input); const complete = await finishAnalysisCommand( - input.callerInputPath === undefined + callerInputPath === undefined && callerInputPaths === undefined ? run - : bindCliEvidenceCallerPath( - input.callerInputPath, - run, - input.callerInputPaths, - ), + : bindCliEvidenceCallerPath(callerInputPath, run, callerInputPaths), service, providerId, operation, @@ -311,18 +314,36 @@ const publishDeliveredEvidence = async ( return ok({ delivered: published.value.delivered, receipt }); }; +/** Whether a caller-selected path contains an excluded sensitive literal. */ +const revealsSensitiveValue = ( + path: string, + input: Pick, +): boolean => explicitValuesOccurIn(path, input.sensitiveValues ?? []); + +/** + * The named caller paths the Evidence may retain: a choice that contains an + * excluded sensitive literal is omitted whole, so a repeated option never + * loses its order. + */ +const safeCallerInputPaths = ( + input: Pick, +): CallerInputPaths | undefined => { + if (input.callerInputPaths === undefined) return undefined; + const kept = Object.entries(input.callerInputPaths).filter(([, value]) => + (typeof value === "string" ? [value] : value).every( + (path) => !revealsSensitiveValue(path, input), + ), + ); + return kept.length === 0 ? undefined : Object.fromEntries(kept); +}; + /** A receipt omits a path that contains an excluded sensitive literal. */ const bundleReceipt = ( path: string | undefined, bytes: Bytes, input: Pick, ): { readonly path?: string; readonly bytes: Bytes } => ({ - ...(path === undefined || - input.sensitiveValues?.some( - (literal) => literal !== "" && path.includes(literal), - ) - ? {} - : { path }), + ...(path === undefined || revealsSensitiveValue(path, input) ? {} : { path }), bytes, }); diff --git a/src/cli/cliEvidenceCallerPath.ts b/src/cli/cliEvidenceCallerPath.ts index 082bbef561..005916a8bb 100644 --- a/src/cli/cliEvidenceCallerPath.ts +++ b/src/cli/cliEvidenceCallerPath.ts @@ -9,10 +9,14 @@ import type { Result } from "../domain/result.js"; import { ZodError } from "zod"; import { finishAnalysisCommand } from "./finishAnalysisCommand.js"; -/** Bind the CLI selection before final cleanup or publication can retain it. */ +/** + * Bind the CLI selection before final cleanup or publication can retain it. + * An omitted `callerPath` keeps the Evidence's own, binding only the named + * auxiliary paths. + */ export const bindCliEvidenceCallerPath = ( - callerPath: string, + callerPath: string | undefined, run: () => Promise>, additionalPaths?: CallerInputPaths, ): (() => Promise>) => diff --git a/src/cli/environmentCommands.ts b/src/cli/environmentCommands.ts index 9998167b4d..7e9f0a3b55 100644 --- a/src/cli/environmentCommands.ts +++ b/src/cli/environmentCommands.ts @@ -39,7 +39,7 @@ import { createLogger } from "../logger.js"; import { TEMPLATE_RULES } from "../domain/analysisView/environmentManifestRules.js"; import { inspectWebNetworkCaptureInputSchema } from "../domain/webNetworkCapture.js"; import { withCommandCancellation } from "./commandCancellation.js"; -import { finishAnalysisCommand } from "./finishAnalysisCommand.js"; +import { finishCliEvidenceCommand } from "./cliEvidenceCallerPath.js"; import type { CliInstance } from "./types.js"; import { cliDecimalField, publishArgvInput } from "./options.js"; @@ -352,7 +352,8 @@ const inspectBuildHar = async ( const { ENVIRONMENT_BUILD_OPERATION } = await import("../application/environment/environmentBuild.js"); const service = createWebNetworkCaptureService(environment); - const inspected = await finishAnalysisCommand( + const inspected = await finishCliEvidenceCommand( + callerInputPath, () => service.inspect( { @@ -363,7 +364,6 @@ const inspectBuildHar = async ( : { capture_timeout_ms: captureTimeoutMs }), }, { signal }, - { capture: callerInputPath }, ), service, "web-network-capture", diff --git a/src/cli/webNetworkCaptureCommands.ts b/src/cli/webNetworkCaptureCommands.ts index b764e2196c..12100b1efa 100644 --- a/src/cli/webNetworkCaptureCommands.ts +++ b/src/cli/webNetworkCaptureCommands.ts @@ -73,16 +73,12 @@ export const registerWebNetworkCaptureCommands = ( const service = createWebNetworkCaptureService(environment); const descriptor = callerInputs[DESCRIPTOR_PATH] as string | undefined; return deliverCliAnalysisEvidence({ + run: () => service.inspect(input, { signal }), // Evidence keeps each caller path as the caller spelled it. - run: () => - service.inspect( - input, - { signal }, - { - capture: callerInputs.capture_path as string, - ...(descriptor === undefined ? {} : { descriptor }), - }, - ), + callerInputPath: callerInputs.capture_path as string, + ...(descriptor === undefined + ? {} + : { callerInputPaths: { descriptor_set_path: descriptor } }), service, providerId: "web-network-capture", operation: "inspect_web_network_capture",