mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 19:53:50 +00:00
refactor(cli): bind web capture caller paths through the CLI delivery owner (#11322)
WebNetworkCaptureService.inspect took a CLI-only callerPaths argument and bound caller_input_path and caller_input_paths itself, with its own copy of the sensitive-literal filter. deliverCliAnalysisEvidence already binds caller paths for one-shot commands, so the service no longer takes them. The CLI delivery now omits a caller path, or a named caller-path choice, that contains a declared sensitive literal, using the same predicate as bundle receipts. environment-build binds its HAR spelling with finishCliEvidenceCommand.
This commit is contained in:
1 parent
0d35ea065d
commit
5c5c87d0fe
6 files changed
+54
-56
No files matched your search
@@ -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<CliEvidenceDelivery, "sensitiveValues">,
|
||||
): 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<CliEvidenceDelivery, "callerInputPaths" | "sensitiveValues">,
|
||||
): 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 = <Bytes extends JsonValue>(
|
||||
path: string | undefined,
|
||||
bytes: Bytes,
|
||||
input: Pick<CliEvidencePublication, "sensitiveValues">,
|
||||
): { readonly path?: string; readonly bytes: Bytes } => ({
|
||||
...(path === undefined ||
|
||||
input.sensitiveValues?.some(
|
||||
(literal) => literal !== "" && path.includes(literal),
|
||||
)
|
||||
? {}
|
||||
: { path }),
|
||||
...(path === undefined || revealsSensitiveValue(path, input) ? {} : { path }),
|
||||
bytes,
|
||||
});
|
||||
|
||||
|
||||
@@ -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<Result<Evidence, AnalysisError>>,
|
||||
additionalPaths?: CallerInputPaths,
|
||||
): (() => Promise<Result<Evidence, AnalysisError>>) =>
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in new issue
Block a user