feat(electron): add autonomous Electron runtime analysis (#464)
* feat: add autonomous Electron runtime analysis * feat(electron): add lifecycle and boundary telemetry * feat(electron): capture runtime boundary evidence * fix(electron): package boundary hook helper * feat(electron): report active capture coverage * fix(electron): account for bring-your-own runtime * feat(electron): expand agent-owned runtime scenarios * fix(ghidra): keep fixture credentials out of argv * perf(test): serialize local test and docs workloads * fix(electron): harden active runtime capture * fix(inspector): require exact runtime target authorization * fix(docs): make managed manifest host independent * fix(ci): make generated catalog portable * fix: unblock autonomous command and electron flows * fix(electron): close popup and detached helper gaps
This commit is contained in:
@@ -41,6 +41,7 @@ export type AvailabilityPolicy = {
|
||||
readonly browserObservationEnabled?: boolean;
|
||||
readonly browserScenarioEnabled?: boolean;
|
||||
readonly electronObservationEnabled?: boolean;
|
||||
readonly electronAutomationEnabled?: boolean;
|
||||
readonly v8InspectorObservationEnabled?: boolean;
|
||||
readonly javascriptReplayEnabled?: boolean;
|
||||
readonly managedRuntimeEnabled?: boolean;
|
||||
@@ -283,14 +284,8 @@ const policyAvailability = ({
|
||||
reason: "policy_disabled",
|
||||
remediation: "Configure or grant an evidence_read root.",
|
||||
};
|
||||
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.",
|
||||
};
|
||||
const electron = electronPolicyAvailability(name, kind, policy);
|
||||
if (electron !== null) return electron;
|
||||
if (kind === "runtime-provider")
|
||||
return policy.v8InspectorObservationEnabled === true
|
||||
? { reason: "available", remediation: null }
|
||||
@@ -303,6 +298,29 @@ const policyAvailability = ({
|
||||
return null;
|
||||
};
|
||||
|
||||
const electronPolicyAvailability = (
|
||||
name: string,
|
||||
kind: ToolKind,
|
||||
policy: AvailabilityPolicy,
|
||||
): Availability | null => {
|
||||
if (kind !== "electron-provider") return null;
|
||||
if (name === "capture_electron_scenario")
|
||||
return policy.electronAutomationEnabled === true
|
||||
? { reason: "available", remediation: null }
|
||||
: {
|
||||
reason: "policy_disabled",
|
||||
remediation:
|
||||
"Enable active Electron automation and configure exact executable and application roots.",
|
||||
};
|
||||
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.",
|
||||
};
|
||||
};
|
||||
|
||||
const browserPolicyAvailability = (
|
||||
name: string,
|
||||
kind: ToolKind,
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
import type { ProviderIdentity } from "./AnalysisProvider.js";
|
||||
import type { Evidence, EvidenceObservation } from "../domain/evidence.js";
|
||||
import { createEvidence } from "../domain/evidence.js";
|
||||
import type {
|
||||
ElectronActiveObservationInput,
|
||||
ElectronActiveObservationResult,
|
||||
} from "../domain/electronActiveObservation.js";
|
||||
import { jsonValueSchema } from "../domain/jsonValue.js";
|
||||
import { digestJson } from "./JavaScriptReplayPlanning.js";
|
||||
|
||||
/** Create Evidence v2 without retaining arbitrary runtime argument values. */
|
||||
export const createElectronActiveEvidence = (
|
||||
input: ElectronActiveObservationInput,
|
||||
result: ElectronActiveObservationResult,
|
||||
provider: ProviderIdentity,
|
||||
): Evidence =>
|
||||
createEvidence(undefined, provider, {
|
||||
predicateType: "rea.electron-active-scenario/v1",
|
||||
operation: "capture_electron_scenario",
|
||||
parameters: parameters(input),
|
||||
result: jsonValueSchema.parse(result),
|
||||
confidence: "observed",
|
||||
authority: "controlled-replay",
|
||||
environment: {
|
||||
id: `${result.application.electron_version}@${process.platform}`,
|
||||
platform: process.platform,
|
||||
architecture: process.arch,
|
||||
isolation: "none",
|
||||
},
|
||||
limitations: result.limitations,
|
||||
});
|
||||
|
||||
const scenarioProjection = (
|
||||
input: ElectronActiveObservationInput,
|
||||
): EvidenceObservation["parameters"] => ({
|
||||
approved: input.approved,
|
||||
schema_version: input.schema_version,
|
||||
executable_path: input.executable_path,
|
||||
application_path: input.application_path,
|
||||
application_root: input.application_root,
|
||||
args: redactArguments(input.args),
|
||||
actions: input.actions.map(({ step_id, kind }) => ({ step_id, kind })),
|
||||
limits: input.limits,
|
||||
});
|
||||
|
||||
const parameters = (
|
||||
input: ElectronActiveObservationInput,
|
||||
): EvidenceObservation["parameters"] => ({
|
||||
...scenarioProjection(input),
|
||||
scenario_sha256: digestJson(scenarioProjection(input)),
|
||||
});
|
||||
|
||||
const redactArguments = (arguments_: readonly string[]): string[] => {
|
||||
let redactNext = false;
|
||||
return arguments_.map((argument) => {
|
||||
if (redactNext) {
|
||||
redactNext = false;
|
||||
return "<redacted>";
|
||||
}
|
||||
if (sensitiveFlag.test(argument)) {
|
||||
redactNext = true;
|
||||
return argument;
|
||||
}
|
||||
return redactArgument(argument);
|
||||
});
|
||||
};
|
||||
|
||||
const sensitiveFlag =
|
||||
/^--?(?:password|token|secret|api[-_]?key|authorization|cookie)$/iu;
|
||||
|
||||
const redactArgument = (argument: string): string => {
|
||||
if (
|
||||
/^--?(?:password|token|secret|api[-_]?key|authorization|cookie)=/iu.test(
|
||||
argument,
|
||||
)
|
||||
)
|
||||
return `${argument.slice(0, argument.indexOf("=") + 1)}<redacted>`;
|
||||
return argument.length > 256
|
||||
? `${argument.slice(0, 256)}<redacted>`
|
||||
: argument;
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
import type { ExecutionOptions, ProviderIdentity } from "./AnalysisProvider.js";
|
||||
import type { AnalysisError } from "../domain/errors.js";
|
||||
import type {
|
||||
ElectronActiveObservationInput,
|
||||
ElectronActiveObservationResult,
|
||||
} from "../domain/electronActiveObservation.js";
|
||||
import type { Result } from "../domain/result.js";
|
||||
|
||||
/** Provider-neutral boundary for owned Electron runtime experiments. */
|
||||
export interface ElectronActiveObservationPort {
|
||||
identity(): ProviderIdentity;
|
||||
capture(
|
||||
input: ElectronActiveObservationInput,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<ElectronActiveObservationResult, AnalysisError>>;
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
import { realpath } from "node:fs/promises";
|
||||
|
||||
import type { ExecutionOptions } from "./AnalysisProvider.js";
|
||||
import type { ElectronActiveObservationPort } from "./ElectronActiveObservationPort.js";
|
||||
import type { PermissionAuthority } from "./PermissionAuthority.js";
|
||||
import { digestJson } from "./JavaScriptReplayPlanning.js";
|
||||
import {
|
||||
AnalysisCapabilityUnavailableError,
|
||||
AnalysisInputError,
|
||||
AnalysisProtocolError,
|
||||
PermissionRequiredError,
|
||||
type AnalysisError,
|
||||
} from "../domain/errors.js";
|
||||
import type { Evidence } from "../domain/evidence.js";
|
||||
import type { ElectronActiveObservationInput } from "../domain/electronActiveObservation.js";
|
||||
import { isPathContained } from "../domain/permissionPolicy.js";
|
||||
import { err, type Result } from "../domain/result.js";
|
||||
import { createElectronActiveEvidence } from "./ElectronActiveEvidence.js";
|
||||
|
||||
const OPERATION = "capture_electron_scenario" as const;
|
||||
const PROVIDER_ID = "rea-playwright-electron-active";
|
||||
|
||||
const canonicalizeInput = async (
|
||||
input: ElectronActiveObservationInput,
|
||||
): Promise<Result<ElectronActiveObservationInput, AnalysisError>> => {
|
||||
try {
|
||||
const [executablePath, applicationPath, applicationRoot] =
|
||||
await Promise.all([
|
||||
realpath(input.executable_path),
|
||||
realpath(input.application_path),
|
||||
realpath(input.application_root),
|
||||
]);
|
||||
if (!isPathContained(applicationRoot, applicationPath))
|
||||
return err(
|
||||
new AnalysisInputError(OPERATION, undefined, [
|
||||
{
|
||||
path: ["application_path"],
|
||||
reason: "invalid_value",
|
||||
message:
|
||||
"application_path must remain beneath application_root after symlink resolution",
|
||||
},
|
||||
]),
|
||||
);
|
||||
return {
|
||||
ok: true,
|
||||
value: {
|
||||
...input,
|
||||
executable_path: executablePath,
|
||||
application_path: applicationPath,
|
||||
application_root: applicationRoot,
|
||||
},
|
||||
};
|
||||
} catch (cause: unknown) {
|
||||
return err(
|
||||
new AnalysisInputError(OPERATION, { cause }, [
|
||||
{
|
||||
path: ["application_path"],
|
||||
reason: "invalid_format",
|
||||
message:
|
||||
"Electron executable, application, and root must resolve to existing paths",
|
||||
},
|
||||
]),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const authorize = async (
|
||||
authority: PermissionAuthority | undefined,
|
||||
input: ElectronActiveObservationInput,
|
||||
): Promise<Result<ElectronActiveObservationInput, AnalysisError>> => {
|
||||
const canonical = await canonicalizeInput(input);
|
||||
if (!canonical.ok) return canonical;
|
||||
if (authority === undefined)
|
||||
return err(
|
||||
new AnalysisCapabilityUnavailableError(
|
||||
PROVIDER_ID,
|
||||
OPERATION,
|
||||
"active Electron observation permission policy is not configured",
|
||||
),
|
||||
);
|
||||
const authorized = await authority.authorize(
|
||||
{
|
||||
capability: "electron_automate",
|
||||
roots: [canonical.value.application_root],
|
||||
executables: [canonical.value.executable_path],
|
||||
environment_names: [],
|
||||
network: "external",
|
||||
mount: false,
|
||||
operation_identity: `${OPERATION}:${digestJson(canonical.value)}`,
|
||||
},
|
||||
"write",
|
||||
);
|
||||
if (!authorized.ok)
|
||||
return err(
|
||||
authorized.error instanceof PermissionRequiredError
|
||||
? authorized.error
|
||||
: new AnalysisProtocolError(authorized.error.message, {
|
||||
cause: authorized.error,
|
||||
}),
|
||||
);
|
||||
return canonical;
|
||||
};
|
||||
|
||||
/** Authorize and execute one bounded, provider-owned Electron experiment. */
|
||||
export const captureElectronScenario = async (
|
||||
provider: ElectronActiveObservationPort | undefined,
|
||||
authority: PermissionAuthority | undefined,
|
||||
input: ElectronActiveObservationInput,
|
||||
options: ExecutionOptions = {},
|
||||
): Promise<Result<Evidence, AnalysisError>> => {
|
||||
const authorized = await authorize(authority, input);
|
||||
if (!authorized.ok) return authorized;
|
||||
if (provider === undefined)
|
||||
return err(
|
||||
new AnalysisCapabilityUnavailableError(
|
||||
PROVIDER_ID,
|
||||
OPERATION,
|
||||
"active Electron observation provider is not configured",
|
||||
),
|
||||
);
|
||||
const captured = await provider.capture(authorized.value, options);
|
||||
return captured.ok
|
||||
? {
|
||||
ok: true,
|
||||
value: createElectronActiveEvidence(
|
||||
authorized.value,
|
||||
captured.value,
|
||||
provider.identity(),
|
||||
),
|
||||
}
|
||||
: captured;
|
||||
};
|
||||
@@ -333,10 +333,6 @@ const completeCapture = async (options: {
|
||||
}
|
||||
throw processCaptureCancelled();
|
||||
}
|
||||
if (runtime.reactive !== undefined) {
|
||||
await runtime.reactive.coordinator.submit({ kind: "target_lost" });
|
||||
runtime.reactive.unsubscribe();
|
||||
}
|
||||
const settlement = await observeSettlement(
|
||||
options.runId,
|
||||
selectCapturedProcessGroupIds(runtime.terminal.pid, options.samples),
|
||||
@@ -345,6 +341,15 @@ const completeCapture = async (options: {
|
||||
);
|
||||
runtime.checkpoints.trigger("settled");
|
||||
const samplingPartial = (await runtime.stopSampler()).partial;
|
||||
if (runtime.reactive !== undefined) {
|
||||
// Process, filesystem, shim, and protocol observations can be recorded
|
||||
// during settlement after the PTY exits. Make target loss terminal only
|
||||
// after that journal has drained, otherwise the coordinator's control
|
||||
// priority discards a valid multi-source completion predicate.
|
||||
await runtime.reactive.coordinator.drain();
|
||||
await runtime.reactive.coordinator.submit({ kind: "target_lost" });
|
||||
runtime.reactive.unsubscribe();
|
||||
}
|
||||
assertNotCancelled(options.signal);
|
||||
const after = await snapshotRoots(scenario, options.signal);
|
||||
const renderedFrames = await runtime.renderer.frames();
|
||||
|
||||
@@ -71,9 +71,10 @@ export const normalizeProcessSamples = (
|
||||
"<no-temporary-root>",
|
||||
rootPid,
|
||||
);
|
||||
return scenario.normalization.pids
|
||||
const withNormalizedPids = scenario.normalization.pids
|
||||
? normalizePidTokens(normalized, identifiers)
|
||||
: normalized;
|
||||
return withNormalizedPids.trim();
|
||||
};
|
||||
return samples.map((sample) => ({
|
||||
at_ms: normalizeProcessElapsedTime(
|
||||
|
||||
@@ -25,6 +25,7 @@ const grantSchema = z.object({
|
||||
"browser_observe",
|
||||
"browser_automate",
|
||||
"electron_observe",
|
||||
"electron_automate",
|
||||
"evidence_read",
|
||||
"evidence_write",
|
||||
"investigation_input",
|
||||
|
||||
@@ -3,16 +3,19 @@ import { mkdtemp, rm, symlink, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
import {
|
||||
windowsNativeCapabilities,
|
||||
type WindowsNativeCapabilitySet,
|
||||
} from "../process/WindowsAuthority.js";
|
||||
import {
|
||||
probeProcessCaptureCapability,
|
||||
type ProcessCaptureCapability,
|
||||
} from "./ProcessCaptureCapability.js";
|
||||
|
||||
/** One named Windows host observation without inferred authority. */
|
||||
interface WindowsCapabilityOutcome {
|
||||
readonly available: boolean;
|
||||
readonly reason: string | null;
|
||||
}
|
||||
export type WindowsCapabilityOutcome =
|
||||
| { readonly available: true; readonly reason: null }
|
||||
| { readonly available: false; readonly reason: string };
|
||||
|
||||
/** Injectable host probes used by CI and deterministic unit tests. */
|
||||
export interface WindowsCapabilityDependencies {
|
||||
@@ -36,6 +39,8 @@ export interface WindowsCapabilityReport {
|
||||
unix_domain_socket: WindowsCapabilityOutcome;
|
||||
pty: WindowsCapabilityOutcome;
|
||||
}>;
|
||||
/** Security controls that are unavailable until native authority exists. */
|
||||
readonly security: WindowsNativeCapabilitySet;
|
||||
}
|
||||
|
||||
/** Probe named prerequisites without converting missing controls into support. */
|
||||
@@ -54,11 +59,11 @@ export const probeWindowsCapabilities = async (
|
||||
no_follow_open: dependencies.probeNoFollowOpen(),
|
||||
private_acl: dependencies.probePrivateAcl(),
|
||||
unix_domain_socket: dependencies.probeUnixDomainSocket(),
|
||||
pty: {
|
||||
available: pty.available,
|
||||
reason: pty.available ? null : pty.reason,
|
||||
},
|
||||
pty: pty.available
|
||||
? { available: true, reason: null }
|
||||
: { available: false, reason: pty.reason },
|
||||
},
|
||||
security: windowsNativeCapabilities(dependencies.platform),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user