feat: add web and Electron reverse-engineering workflows
This commit is contained in:
@@ -11,29 +11,73 @@ import type {
|
||||
ListBrowserTargetsInput,
|
||||
WebPageInspection,
|
||||
} from "../domain/browserObservation.js";
|
||||
import type {
|
||||
AnalyzeWebBundleInput,
|
||||
WebBundleAnalysis,
|
||||
} from "../domain/webBundleAnalysis.js";
|
||||
import type {
|
||||
ObserveWebSessionInput,
|
||||
WebObservationSession,
|
||||
} from "../domain/browserSession.js";
|
||||
import type {
|
||||
DiscoverWebMcpToolsInput,
|
||||
WebMcpDiscovery,
|
||||
} from "../domain/webMcpDiscovery.js";
|
||||
import type {
|
||||
CompareWebCapturesInput,
|
||||
WebCaptureDiff,
|
||||
} from "../domain/webCaptureDiff.js";
|
||||
import type {
|
||||
CaptureWebScreenshotInput,
|
||||
CompareWebScreenshotsInput,
|
||||
WebScreenshot,
|
||||
WebScreenshotDiff,
|
||||
} from "../domain/webScreenshot.js";
|
||||
|
||||
type BrowserEvidenceInput = ListBrowserTargetsInput | InspectWebPageInput;
|
||||
type BrowserEvidenceResult = BrowserTargetList | WebPageInspection;
|
||||
type BrowserEvidenceInput =
|
||||
| ListBrowserTargetsInput
|
||||
| InspectWebPageInput
|
||||
| AnalyzeWebBundleInput
|
||||
| ObserveWebSessionInput
|
||||
| DiscoverWebMcpToolsInput
|
||||
| CompareWebCapturesInput
|
||||
| CaptureWebScreenshotInput
|
||||
| CompareWebScreenshotsInput;
|
||||
type BrowserEvidenceResult =
|
||||
| BrowserTargetList
|
||||
| WebPageInspection
|
||||
| WebBundleAnalysis
|
||||
| WebObservationSession
|
||||
| WebMcpDiscovery
|
||||
| WebCaptureDiff
|
||||
| WebScreenshot
|
||||
| WebScreenshotDiff;
|
||||
type BrowserEvidenceOperation =
|
||||
| "list_browser_targets"
|
||||
| "inspect_web_page"
|
||||
| "analyze_web_bundle"
|
||||
| "observe_web_session"
|
||||
| "discover_webmcp_tools"
|
||||
| "compare_web_captures"
|
||||
| "capture_web_screenshot"
|
||||
| "compare_web_screenshots";
|
||||
|
||||
/** Create Evidence v2 for a policy-scoped external browser observation. */
|
||||
export const createBrowserEvidence = (
|
||||
operation: "list_browser_targets" | "inspect_web_page",
|
||||
operation: BrowserEvidenceOperation,
|
||||
input: BrowserEvidenceInput,
|
||||
result: BrowserEvidenceResult,
|
||||
provider: ProviderIdentity,
|
||||
): Evidence =>
|
||||
createEvidence(undefined, provider, {
|
||||
predicateType:
|
||||
operation === "list_browser_targets"
|
||||
? "rea.browser-target-list/v1"
|
||||
: "rea.web-page-inspection/v1",
|
||||
predicateType: browserPredicate(operation),
|
||||
operation,
|
||||
parameters: browserParameters(input),
|
||||
result: jsonValueSchema.parse(result),
|
||||
confidence: "observed",
|
||||
authority: "external-service",
|
||||
environment:
|
||||
"target" in result
|
||||
"browser" in result
|
||||
? {
|
||||
id: `${result.browser.product}@${result.browser.revision}`,
|
||||
platform: process.platform,
|
||||
@@ -46,16 +90,92 @@ export const createBrowserEvidence = (
|
||||
|
||||
const browserParameters = (
|
||||
input: BrowserEvidenceInput,
|
||||
): EvidenceObservation["parameters"] => ({
|
||||
cdp_endpoint: input.cdp_endpoint,
|
||||
allowed_origins: input.allowed_origins,
|
||||
...("target_id" in input
|
||||
? {
|
||||
target_id: input.target_id,
|
||||
observation_ms: input.observation_ms,
|
||||
include_script_sources: input.include_script_sources,
|
||||
include_storage_keys: input.include_storage_keys,
|
||||
limits: input.limits,
|
||||
}
|
||||
: { offset: input.offset, limit: input.limit }),
|
||||
});
|
||||
): EvidenceObservation["parameters"] => {
|
||||
if (!("cdp_endpoint" in input)) {
|
||||
if ("max_changes" in input)
|
||||
return {
|
||||
before_target_id: input.before.inspection.target.target_id,
|
||||
before_capture_ended_at:
|
||||
input.before.inspection.capture_window.ended_at,
|
||||
after_target_id: input.after.inspection.target.target_id,
|
||||
after_capture_ended_at: input.after.inspection.capture_window.ended_at,
|
||||
max_changes: input.max_changes,
|
||||
};
|
||||
return {
|
||||
before_artifact_uri: input.before.uri,
|
||||
after_artifact_uri: input.after.uri,
|
||||
channel_threshold: input.channel_threshold,
|
||||
maximum_pixels: input.maximum_pixels,
|
||||
};
|
||||
}
|
||||
const scope = {
|
||||
cdp_endpoint: input.cdp_endpoint,
|
||||
allowed_origins: input.allowed_origins,
|
||||
};
|
||||
if (!("target_id" in input))
|
||||
return { ...scope, offset: input.offset, limit: input.limit };
|
||||
if ("screenshot_approved" in input)
|
||||
return {
|
||||
...scope,
|
||||
target_id: input.target_id,
|
||||
maximum_image_bytes: input.maximum_image_bytes,
|
||||
};
|
||||
if ("max_tools" in input)
|
||||
return {
|
||||
...scope,
|
||||
target_id: input.target_id,
|
||||
observation_ms: input.observation_ms,
|
||||
max_tools: input.max_tools,
|
||||
max_schema_bytes: input.max_schema_bytes,
|
||||
max_schema_nodes: input.max_schema_nodes,
|
||||
max_schema_depth: input.max_schema_depth,
|
||||
};
|
||||
if (!("include_accessibility_text" in input))
|
||||
return {
|
||||
...scope,
|
||||
target_id: input.target_id,
|
||||
observation_ms: input.observation_ms,
|
||||
max_timeline_events: input.max_timeline_events,
|
||||
};
|
||||
return {
|
||||
...scope,
|
||||
target_id: input.target_id,
|
||||
observation_ms: input.observation_ms,
|
||||
include_accessibility_text: input.include_accessibility_text,
|
||||
include_console_text: input.include_console_text,
|
||||
include_json_body_shapes: input.include_json_body_shapes,
|
||||
include_websocket_shapes: input.include_websocket_shapes,
|
||||
include_script_sources: input.include_script_sources,
|
||||
include_storage_keys: input.include_storage_keys,
|
||||
limits: input.limits,
|
||||
...(input.include_script_sources && "source_capture_approved" in input
|
||||
? {
|
||||
source_capture_approved: input.source_capture_approved,
|
||||
fetch_source_maps: input.fetch_source_maps,
|
||||
source_map_fetch_approved: input.source_map_fetch_approved,
|
||||
analysis_limits: input.analysis_limits,
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
};
|
||||
|
||||
const browserPredicate = (operation: BrowserEvidenceOperation): string => {
|
||||
switch (operation) {
|
||||
case "list_browser_targets":
|
||||
return "rea.browser-target-list/v1";
|
||||
case "inspect_web_page":
|
||||
return "rea.web-page-inspection/v2";
|
||||
case "analyze_web_bundle":
|
||||
return "rea.web-bundle-analysis/v1";
|
||||
case "observe_web_session":
|
||||
return "rea.web-observation-session/v1";
|
||||
case "discover_webmcp_tools":
|
||||
return "rea.webmcp-discovery/v1";
|
||||
case "compare_web_captures":
|
||||
return "rea.web-capture-diff/v1";
|
||||
case "capture_web_screenshot":
|
||||
return "rea.web-screenshot/v1";
|
||||
case "compare_web_screenshots":
|
||||
return "rea.web-screenshot-diff/v1";
|
||||
}
|
||||
};
|
||||
|
||||
@@ -6,6 +6,28 @@ import type {
|
||||
WebPageInspection,
|
||||
} from "../domain/browserObservation.js";
|
||||
import type { Result } from "../domain/result.js";
|
||||
import type {
|
||||
AnalyzeWebBundleInput,
|
||||
WebBundleAnalysis,
|
||||
} from "../domain/webBundleAnalysis.js";
|
||||
import type {
|
||||
ObserveWebSessionInput,
|
||||
WebObservationSession,
|
||||
} from "../domain/browserSession.js";
|
||||
import type {
|
||||
DiscoverWebMcpToolsInput,
|
||||
WebMcpDiscovery,
|
||||
} from "../domain/webMcpDiscovery.js";
|
||||
import type {
|
||||
CompareWebCapturesInput,
|
||||
WebCaptureDiff,
|
||||
} from "../domain/webCaptureDiff.js";
|
||||
import type {
|
||||
CaptureWebScreenshotInput,
|
||||
CompareWebScreenshotsInput,
|
||||
WebScreenshot,
|
||||
WebScreenshotDiff,
|
||||
} from "../domain/webScreenshot.js";
|
||||
import type { ProviderIdentity } from "./AnalysisProvider.js";
|
||||
import type { ExecutionOptions } from "./AnalysisProvider.js";
|
||||
|
||||
@@ -20,4 +42,26 @@ export interface BrowserObservationPort {
|
||||
input: InspectWebPageInput,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<WebPageInspection, AnalysisError>>;
|
||||
analyzeBundle(
|
||||
input: AnalyzeWebBundleInput,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<WebBundleAnalysis, AnalysisError>>;
|
||||
observeSession(
|
||||
input: ObserveWebSessionInput,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<WebObservationSession, AnalysisError>>;
|
||||
discoverWebMcpTools(
|
||||
input: DiscoverWebMcpToolsInput,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<WebMcpDiscovery, AnalysisError>>;
|
||||
compareCaptures(
|
||||
input: CompareWebCapturesInput,
|
||||
): Promise<Result<WebCaptureDiff, AnalysisError>>;
|
||||
captureScreenshot(
|
||||
input: CaptureWebScreenshotInput,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<WebScreenshot, AnalysisError>>;
|
||||
compareScreenshots(
|
||||
input: CompareWebScreenshotsInput,
|
||||
): Promise<Result<WebScreenshotDiff, AnalysisError>>;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,14 @@ import type {
|
||||
InspectWebPageInput,
|
||||
ListBrowserTargetsInput,
|
||||
} from "../domain/browserObservation.js";
|
||||
import type { AnalyzeWebBundleInput } from "../domain/webBundleAnalysis.js";
|
||||
import type { ObserveWebSessionInput } from "../domain/browserSession.js";
|
||||
import type { DiscoverWebMcpToolsInput } from "../domain/webMcpDiscovery.js";
|
||||
import type { CompareWebCapturesInput } from "../domain/webCaptureDiff.js";
|
||||
import type {
|
||||
CaptureWebScreenshotInput,
|
||||
CompareWebScreenshotsInput,
|
||||
} from "../domain/webScreenshot.js";
|
||||
import {
|
||||
AnalysisCapabilityUnavailableError,
|
||||
AnalysisProtocolError,
|
||||
@@ -69,11 +77,154 @@ export const inspectWebPage = async (
|
||||
: result;
|
||||
};
|
||||
|
||||
/** Capture approved sources and derive bounded static web-bundle evidence. */
|
||||
export const analyzeWebBundle = async (
|
||||
browser: BrowserObservationPort | undefined,
|
||||
authority: PermissionAuthority | undefined,
|
||||
input: AnalyzeWebBundleInput,
|
||||
options: ExecutionOptions = {},
|
||||
): Promise<Result<Evidence, AnalysisError>> => {
|
||||
const ready = await prepare(browser, authority, input, "analyze_web_bundle");
|
||||
if (!ready.ok) return ready;
|
||||
const analyzed = await ready.value.analyzeBundle(input, options);
|
||||
if (!analyzed.ok) return analyzed;
|
||||
return ok(
|
||||
createBrowserEvidence(
|
||||
"analyze_web_bundle",
|
||||
input,
|
||||
analyzed.value,
|
||||
ready.value.identity(),
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
/** Observe navigation caused by external user actions during one armed window. */
|
||||
export const observeWebSession = async (
|
||||
browser: BrowserObservationPort | undefined,
|
||||
authority: PermissionAuthority | undefined,
|
||||
input: ObserveWebSessionInput,
|
||||
options: ExecutionOptions = {},
|
||||
): Promise<Result<Evidence, AnalysisError>> => {
|
||||
const ready = await prepare(browser, authority, input, "observe_web_session");
|
||||
if (!ready.ok) return ready;
|
||||
const observed = await ready.value.observeSession(input, options);
|
||||
return observed.ok
|
||||
? ok(
|
||||
createBrowserEvidence(
|
||||
"observe_web_session",
|
||||
input,
|
||||
observed.value,
|
||||
ready.value.identity(),
|
||||
),
|
||||
)
|
||||
: observed;
|
||||
};
|
||||
|
||||
/** Discover WebMCP declarations without exposing an invocation surface. */
|
||||
export const discoverWebMcpTools = async (
|
||||
browser: BrowserObservationPort | undefined,
|
||||
authority: PermissionAuthority | undefined,
|
||||
input: DiscoverWebMcpToolsInput,
|
||||
options: ExecutionOptions = {},
|
||||
): Promise<Result<Evidence, AnalysisError>> => {
|
||||
const ready = await prepare(
|
||||
browser,
|
||||
authority,
|
||||
input,
|
||||
"discover_webmcp_tools",
|
||||
);
|
||||
if (!ready.ok) return ready;
|
||||
const discovered = await ready.value.discoverWebMcpTools(input, options);
|
||||
return discovered.ok
|
||||
? ok(
|
||||
createBrowserEvidence(
|
||||
"discover_webmcp_tools",
|
||||
input,
|
||||
discovered.value,
|
||||
ready.value.identity(),
|
||||
),
|
||||
)
|
||||
: discovered;
|
||||
};
|
||||
|
||||
/** Compare two already-normalized web captures without external access. */
|
||||
export const compareWebCaptureEvidence = async (
|
||||
browser: BrowserObservationPort | undefined,
|
||||
input: CompareWebCapturesInput,
|
||||
): Promise<Result<Evidence, AnalysisError>> => {
|
||||
const ready = requireBrowser(browser, "compare_web_captures");
|
||||
if (!ready.ok) return ready;
|
||||
const compared = await ready.value.compareCaptures(input);
|
||||
return compared.ok
|
||||
? ok(
|
||||
createBrowserEvidence(
|
||||
"compare_web_captures",
|
||||
input,
|
||||
compared.value,
|
||||
ready.value.identity(),
|
||||
),
|
||||
)
|
||||
: compared;
|
||||
};
|
||||
|
||||
/** Capture one explicitly approved visible-viewport screenshot. */
|
||||
export const captureWebScreenshot = async (
|
||||
browser: BrowserObservationPort | undefined,
|
||||
authority: PermissionAuthority | undefined,
|
||||
input: CaptureWebScreenshotInput,
|
||||
options: ExecutionOptions = {},
|
||||
): Promise<Result<Evidence, AnalysisError>> => {
|
||||
const ready = await prepare(
|
||||
browser,
|
||||
authority,
|
||||
input,
|
||||
"capture_web_screenshot",
|
||||
);
|
||||
if (!ready.ok) return ready;
|
||||
const captured = await ready.value.captureScreenshot(input, options);
|
||||
return captured.ok
|
||||
? ok(
|
||||
createBrowserEvidence(
|
||||
"capture_web_screenshot",
|
||||
input,
|
||||
captured.value,
|
||||
ready.value.identity(),
|
||||
),
|
||||
)
|
||||
: captured;
|
||||
};
|
||||
|
||||
/** Compare two self-verifying PNG artifacts without external access. */
|
||||
export const compareWebScreenshotEvidence = async (
|
||||
browser: BrowserObservationPort | undefined,
|
||||
input: CompareWebScreenshotsInput,
|
||||
): Promise<Result<Evidence, AnalysisError>> => {
|
||||
const ready = requireBrowser(browser, "compare_web_screenshots");
|
||||
if (!ready.ok) return ready;
|
||||
const compared = await ready.value.compareScreenshots(input);
|
||||
return compared.ok
|
||||
? ok(
|
||||
createBrowserEvidence(
|
||||
"compare_web_screenshots",
|
||||
input,
|
||||
compared.value,
|
||||
ready.value.identity(),
|
||||
),
|
||||
)
|
||||
: compared;
|
||||
};
|
||||
|
||||
const prepare = async (
|
||||
browser: BrowserObservationPort | undefined,
|
||||
authority: PermissionAuthority | undefined,
|
||||
input: ScopedBrowserInput,
|
||||
operation: "list_browser_targets" | "inspect_web_page",
|
||||
operation:
|
||||
| "list_browser_targets"
|
||||
| "inspect_web_page"
|
||||
| "analyze_web_bundle"
|
||||
| "observe_web_session"
|
||||
| "discover_webmcp_tools"
|
||||
| "capture_web_screenshot",
|
||||
): Promise<Result<BrowserObservationPort, AnalysisError>> => {
|
||||
if (authority === undefined)
|
||||
return err(
|
||||
@@ -115,6 +266,20 @@ const prepare = async (
|
||||
: ok(browser);
|
||||
};
|
||||
|
||||
const requireBrowser = (
|
||||
browser: BrowserObservationPort | undefined,
|
||||
operation: string,
|
||||
): Result<BrowserObservationPort, AnalysisError> =>
|
||||
browser === undefined
|
||||
? err(
|
||||
new AnalysisCapabilityUnavailableError(
|
||||
"rea-cdp-browser",
|
||||
operation,
|
||||
"browser comparison provider is not configured",
|
||||
),
|
||||
)
|
||||
: ok(browser);
|
||||
|
||||
const browserNetworkScope = (
|
||||
allowedOrigins: readonly string[],
|
||||
): "loopback" | "external" =>
|
||||
|
||||
@@ -55,6 +55,7 @@ export const buildCapabilityInventory = (
|
||||
readonly processCaptureEnabled: boolean;
|
||||
readonly evidenceFileRoots: number;
|
||||
readonly browserObservationEnabled?: boolean;
|
||||
readonly electronObservationEnabled?: boolean;
|
||||
},
|
||||
) => {
|
||||
const status = statusSchema.parse(sessionStatus);
|
||||
@@ -99,6 +100,7 @@ const availabilityFor = (
|
||||
readonly processCaptureEnabled: boolean;
|
||||
readonly evidenceFileRoots: number;
|
||||
readonly browserObservationEnabled?: boolean;
|
||||
readonly electronObservationEnabled?: boolean;
|
||||
},
|
||||
): {
|
||||
readonly reason: ToolAvailabilityReason;
|
||||
@@ -123,6 +125,14 @@ const availabilityFor = (
|
||||
remediation:
|
||||
"Enable browser observation and configure exact CDP endpoint and page origins.",
|
||||
};
|
||||
if (kind === "electron-provider")
|
||||
return policy.electronObservationEnabled === true
|
||||
? { reason: "available", remediation: null }
|
||||
: {
|
||||
reason: "policy_disabled",
|
||||
remediation:
|
||||
"Enable Electron observation and configure a loopback CDP endpoint and canonical file roots.",
|
||||
};
|
||||
if (kind === "session") return { reason: "available", remediation: null };
|
||||
if (!targetOpen)
|
||||
return {
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import type { ProviderIdentity } from "./AnalysisProvider.js";
|
||||
import {
|
||||
createEvidence,
|
||||
type Evidence,
|
||||
type EvidenceObservation,
|
||||
} from "../domain/evidence.js";
|
||||
import { jsonValueSchema } from "../domain/jsonValue.js";
|
||||
import type {
|
||||
ElectronPageInspection,
|
||||
ElectronTargetList,
|
||||
InspectElectronPageInput,
|
||||
ListElectronTargetsInput,
|
||||
} from "../domain/electronObservation.js";
|
||||
|
||||
type ElectronOperation = "list_electron_targets" | "inspect_electron_page";
|
||||
|
||||
/** Create Evidence v2 for one root-confined Electron observation. */
|
||||
export const createElectronEvidence = (
|
||||
operation: ElectronOperation,
|
||||
input: ListElectronTargetsInput | InspectElectronPageInput,
|
||||
result: ElectronTargetList | ElectronPageInspection,
|
||||
provider: ProviderIdentity,
|
||||
): Evidence =>
|
||||
createEvidence(undefined, provider, {
|
||||
predicateType:
|
||||
operation === "list_electron_targets"
|
||||
? "rea.electron-target-list/v1"
|
||||
: "rea.electron-page-inspection/v1",
|
||||
operation,
|
||||
parameters: parameters(input),
|
||||
result: jsonValueSchema.parse(result),
|
||||
confidence: "observed",
|
||||
authority: "external-service",
|
||||
environment:
|
||||
"target" in result
|
||||
? {
|
||||
id: `${result.browser.product}@${result.browser.revision}`,
|
||||
platform: process.platform,
|
||||
architecture: process.arch,
|
||||
isolation: "none",
|
||||
}
|
||||
: null,
|
||||
limitations: result.limitations,
|
||||
});
|
||||
|
||||
const parameters = (
|
||||
input: ListElectronTargetsInput | InspectElectronPageInput,
|
||||
): EvidenceObservation["parameters"] => ({
|
||||
cdp_endpoint: input.cdp_endpoint,
|
||||
allowed_file_roots: input.allowed_file_roots,
|
||||
...("target_id" in input
|
||||
? {
|
||||
target_id: input.target_id,
|
||||
observation_ms: input.observation_ms,
|
||||
include_script_sources: input.include_script_sources,
|
||||
source_capture_approved: input.source_capture_approved,
|
||||
limits: input.limits,
|
||||
}
|
||||
: { offset: input.offset, limit: input.limit }),
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
import type { ExecutionOptions, ProviderIdentity } from "./AnalysisProvider.js";
|
||||
import type { AnalysisError } from "../domain/errors.js";
|
||||
import type {
|
||||
ElectronPageInspection,
|
||||
ElectronTargetList,
|
||||
InspectElectronPageInput,
|
||||
ListElectronTargetsInput,
|
||||
} from "../domain/electronObservation.js";
|
||||
import type { Result } from "../domain/result.js";
|
||||
|
||||
/** Provider-neutral boundary for root-confined Electron file-page observation. */
|
||||
export interface ElectronObservationPort {
|
||||
identity(): ProviderIdentity;
|
||||
listTargets(
|
||||
input: ListElectronTargetsInput,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<ElectronTargetList, AnalysisError>>;
|
||||
inspectPage(
|
||||
input: InspectElectronPageInput,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<ElectronPageInspection, AnalysisError>>;
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
import type { ExecutionOptions } from "./AnalysisProvider.js";
|
||||
import type { ElectronObservationPort } from "./ElectronObservationPort.js";
|
||||
import type { PermissionAuthority } from "./PermissionAuthority.js";
|
||||
import type { Evidence } from "../domain/evidence.js";
|
||||
import type {
|
||||
InspectElectronPageInput,
|
||||
ListElectronTargetsInput,
|
||||
} from "../domain/electronObservation.js";
|
||||
import {
|
||||
AnalysisCapabilityUnavailableError,
|
||||
AnalysisProtocolError,
|
||||
PermissionRequiredError,
|
||||
type AnalysisError,
|
||||
} from "../domain/errors.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import { createElectronEvidence } from "./ElectronEvidence.js";
|
||||
|
||||
/** Authorize and list root-confined Electron page targets. */
|
||||
export const listElectronTargets = async (
|
||||
provider: ElectronObservationPort | undefined,
|
||||
authority: PermissionAuthority | undefined,
|
||||
input: ListElectronTargetsInput,
|
||||
options: ExecutionOptions = {},
|
||||
): Promise<Result<Evidence, AnalysisError>> => {
|
||||
const ready = await prepare(
|
||||
provider,
|
||||
authority,
|
||||
input,
|
||||
"list_electron_targets",
|
||||
);
|
||||
if (!ready.ok) return ready;
|
||||
const result = await ready.value.listTargets(input, options);
|
||||
return result.ok
|
||||
? ok(
|
||||
createElectronEvidence(
|
||||
"list_electron_targets",
|
||||
input,
|
||||
result.value,
|
||||
ready.value.identity(),
|
||||
),
|
||||
)
|
||||
: result;
|
||||
};
|
||||
|
||||
/** Authorize and inspect one root-confined Electron page. */
|
||||
export const inspectElectronPage = async (
|
||||
provider: ElectronObservationPort | undefined,
|
||||
authority: PermissionAuthority | undefined,
|
||||
input: InspectElectronPageInput,
|
||||
options: ExecutionOptions = {},
|
||||
): Promise<Result<Evidence, AnalysisError>> => {
|
||||
const ready = await prepare(
|
||||
provider,
|
||||
authority,
|
||||
input,
|
||||
"inspect_electron_page",
|
||||
);
|
||||
if (!ready.ok) return ready;
|
||||
const result = await ready.value.inspectPage(input, options);
|
||||
return result.ok
|
||||
? ok(
|
||||
createElectronEvidence(
|
||||
"inspect_electron_page",
|
||||
input,
|
||||
result.value,
|
||||
ready.value.identity(),
|
||||
),
|
||||
)
|
||||
: result;
|
||||
};
|
||||
|
||||
const prepare = async (
|
||||
provider: ElectronObservationPort | undefined,
|
||||
authority: PermissionAuthority | undefined,
|
||||
input: ListElectronTargetsInput | InspectElectronPageInput,
|
||||
operation: "list_electron_targets" | "inspect_electron_page",
|
||||
): Promise<Result<ElectronObservationPort, AnalysisError>> => {
|
||||
if (authority === undefined)
|
||||
return err(
|
||||
new AnalysisCapabilityUnavailableError(
|
||||
"rea-cdp-electron",
|
||||
operation,
|
||||
"Electron observation permission policy is not configured",
|
||||
),
|
||||
);
|
||||
const authorized = await authority.authorize(
|
||||
{
|
||||
capability: "electron_observe",
|
||||
roots: input.allowed_file_roots,
|
||||
executables: [],
|
||||
environment_names: [],
|
||||
origins: [input.cdp_endpoint],
|
||||
network: "loopback",
|
||||
mount: false,
|
||||
operation_identity: `${operation}:${"target_id" in input ? input.target_id : input.cdp_endpoint}`,
|
||||
},
|
||||
"read",
|
||||
);
|
||||
if (!authorized.ok)
|
||||
return err(
|
||||
authorized.error instanceof PermissionRequiredError
|
||||
? authorized.error
|
||||
: new AnalysisProtocolError(authorized.error.message, {
|
||||
cause: authorized.error,
|
||||
}),
|
||||
);
|
||||
return provider === undefined
|
||||
? err(
|
||||
new AnalysisCapabilityUnavailableError(
|
||||
"rea-cdp-electron",
|
||||
operation,
|
||||
"Electron observation provider is not configured",
|
||||
),
|
||||
)
|
||||
: ok(provider);
|
||||
};
|
||||
@@ -23,6 +23,7 @@ const grantSchema = z.object({
|
||||
capability: z.enum([
|
||||
"process_capture",
|
||||
"browser_observe",
|
||||
"electron_observe",
|
||||
"evidence_read",
|
||||
"evidence_write",
|
||||
"investigation_input",
|
||||
|
||||
Reference in New Issue
Block a user