fix(electron): bound hook retention and report dropped coverage
This commit is contained in:
@@ -10,10 +10,9 @@ import type {
|
||||
ProviderIdentity,
|
||||
} from "../application/AnalysisProvider.js";
|
||||
import type { ElectronActiveObservationPort } from "../application/javascript/ElectronActiveObservationPort.js";
|
||||
import {
|
||||
electronActiveObservationResultSchema,
|
||||
type ElectronActiveObservationInput,
|
||||
type ElectronActiveObservationResult,
|
||||
import type {
|
||||
ElectronActiveObservationInput,
|
||||
ElectronActiveObservationResult,
|
||||
} from "../domain/javascript/electronActiveObservation.js";
|
||||
import { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import { BrowserObservationError } from "../domain/browserObservationError.js";
|
||||
@@ -38,10 +37,8 @@ import {
|
||||
runElectronActions,
|
||||
readApplicationState,
|
||||
runWithExecutionLimits,
|
||||
type ElectronHookEvent,
|
||||
type ElectronHookSnapshot,
|
||||
type ElectronMetrics,
|
||||
} from "./PlaywrightElectronActiveActions.js";
|
||||
import { projectElectronActiveCapture } from "./PlaywrightElectronActiveProjection.js";
|
||||
|
||||
const OPERATION = "capture_electron_scenario" as const;
|
||||
const STARTUP_TIMEOUT_MS = 60_000;
|
||||
@@ -61,89 +58,6 @@ type ElectronPaths = {
|
||||
readonly root: string;
|
||||
};
|
||||
|
||||
const observableEventFamilies = [
|
||||
"app-lifecycle",
|
||||
"window-lifecycle",
|
||||
"web-contents-lifecycle",
|
||||
"navigation",
|
||||
"shell-attempt",
|
||||
"process-lifecycle",
|
||||
"permission",
|
||||
"popup-attempt",
|
||||
"download",
|
||||
"protocol",
|
||||
"preload",
|
||||
"preload-configuration",
|
||||
"renderer-ipc",
|
||||
"native-addon",
|
||||
"updater",
|
||||
"error",
|
||||
"ipc",
|
||||
] as const;
|
||||
|
||||
const ipcEventKinds = new Set<ElectronHookEvent["kind"]>([
|
||||
"main-handler-invocation",
|
||||
"main-event-invocation",
|
||||
"utility-process-fork",
|
||||
"utility-process-message",
|
||||
"ipc-main-to-renderer",
|
||||
"ipc-utility-to-main",
|
||||
"ipc-renderer-send",
|
||||
"ipc-renderer-invoke",
|
||||
"ipc-renderer-post-message",
|
||||
]);
|
||||
|
||||
const createCoverage = (hookSnapshot: ElectronHookSnapshot) => {
|
||||
const observedEventFamilies: string[] = [
|
||||
...new Set(
|
||||
hookSnapshot.events.map(({ kind, process_type }) => {
|
||||
if (kind === "preload" && process_type === "main")
|
||||
return "preload-configuration";
|
||||
if (kind.startsWith("ipc-renderer") && process_type !== "renderer")
|
||||
return "ipc";
|
||||
return ipcEventKinds.has(kind) ? "ipc" : kind;
|
||||
}),
|
||||
),
|
||||
].sort();
|
||||
const unavailableEventFamilies = new Set(
|
||||
observableEventFamilies.filter(
|
||||
(family) => !observedEventFamilies.includes(family),
|
||||
),
|
||||
);
|
||||
const observedRoles = [
|
||||
...new Set(
|
||||
hookSnapshot.events.flatMap(({ process_type, kind }) => [
|
||||
...(process_type === null ? [] : [process_type]),
|
||||
...(kind === "window-lifecycle" ? ["window"] : []),
|
||||
...(kind === "web-contents-lifecycle" || kind === "navigation"
|
||||
? ["web_contents"]
|
||||
: []),
|
||||
...(kind === "preload" && process_type === "preload"
|
||||
? ["preload"]
|
||||
: []),
|
||||
...(kind.startsWith("ipc-renderer") && process_type === "renderer"
|
||||
? ["renderer"]
|
||||
: []),
|
||||
]),
|
||||
),
|
||||
].sort();
|
||||
const rendererContextObserved = hookSnapshot.events.some(
|
||||
({ process_type }) =>
|
||||
process_type === "renderer" || process_type === "preload",
|
||||
);
|
||||
if (!rendererContextObserved) {
|
||||
unavailableEventFamilies.add("preload");
|
||||
unavailableEventFamilies.add("renderer-ipc");
|
||||
}
|
||||
return {
|
||||
status: hookSnapshot.hook_error ? "hook_conflict" : "partial_attach",
|
||||
observed_event_families: observedEventFamilies,
|
||||
unavailable_event_families: [...unavailableEventFamilies].sort(),
|
||||
observed_roles: observedRoles,
|
||||
pre_capture_activity: "unavailable",
|
||||
} as const;
|
||||
};
|
||||
|
||||
/** Launch an owned Electron application through the official Playwright API. */
|
||||
export class PlaywrightElectronActiveProvider implements ElectronActiveObservationPort {
|
||||
identity(): ProviderIdentity {
|
||||
@@ -200,7 +114,7 @@ export class PlaywrightElectronActiveProvider implements ElectronActiveObservati
|
||||
readApplicationState(application),
|
||||
options.signal,
|
||||
);
|
||||
outcome = ok(createResult(paths, input, actions, state));
|
||||
outcome = ok(projectElectronActiveCapture(paths, actions, state));
|
||||
} catch (cause: unknown) {
|
||||
outcome = err(
|
||||
options.signal?.aborted === true &&
|
||||
@@ -339,64 +253,6 @@ const cleanupElectronProcesses = async (
|
||||
};
|
||||
};
|
||||
|
||||
const createResult = (
|
||||
paths: ElectronPaths,
|
||||
input: ElectronActiveObservationInput,
|
||||
actions: ElectronActiveObservationResult["actions"],
|
||||
state: {
|
||||
readonly windows: ReadonlyArray<{
|
||||
readonly window_id: string;
|
||||
readonly web_contents_id: string;
|
||||
readonly url: string;
|
||||
readonly title: string;
|
||||
readonly visible: boolean | null;
|
||||
readonly destroyed: boolean;
|
||||
}>;
|
||||
readonly metrics: ElectronMetrics;
|
||||
readonly electronVersion: string;
|
||||
readonly hookSnapshot: ElectronHookSnapshot;
|
||||
},
|
||||
): ElectronActiveObservationResult => {
|
||||
const { hookSnapshot } = state;
|
||||
const ipcEvents = hookSnapshot.events.filter(({ kind }) =>
|
||||
ipcEventKinds.has(kind),
|
||||
);
|
||||
return electronActiveObservationResultSchema.parse({
|
||||
application: {
|
||||
executable_path: paths.executable,
|
||||
application_path: paths.application,
|
||||
electron_version: state.electronVersion,
|
||||
process_ownership: "provider-owned",
|
||||
cleanup: "terminated-owned-process",
|
||||
},
|
||||
actions,
|
||||
windows: state.windows,
|
||||
processes: {
|
||||
items: state.metrics,
|
||||
},
|
||||
ipc: {
|
||||
events: ipcEvents,
|
||||
observed: hookSnapshot.observed_ipc,
|
||||
},
|
||||
timeline: {
|
||||
events: hookSnapshot.events,
|
||||
observed: hookSnapshot.observed,
|
||||
},
|
||||
coverage: createCoverage(hookSnapshot),
|
||||
limitations: [
|
||||
"IPC payloads are represented by value shapes; payload values are never retained.",
|
||||
"IPC direction and sender/receiver identifiers are observed only where Electron exposes them at the hooked boundary.",
|
||||
"The runtime timeline records lifecycle, navigation, shell, permission, popup, download, protocol, preload, native-addon, process, and IPC events; activity before hook installation is unavailable.",
|
||||
"The preload and renderer process contexts are not instrumented by the main-process -r hook; preload configuration and contextBridge API-shape events are main-boundary observations, not proof of renderer-side execution.",
|
||||
"Process metrics are an Electron API snapshot and do not prove hostile-local-user isolation.",
|
||||
"External shell opens, external navigation, permission grants, downloads, popup windows, updater relaunches, and OS integration are blocked and recorded by the active hook; other application filesystem and network behavior is not sandboxed by this provider.",
|
||||
...(hookSnapshot.hook_error
|
||||
? ["The active IPC hook could not be installed."]
|
||||
: []),
|
||||
],
|
||||
});
|
||||
};
|
||||
|
||||
const canonicalPaths = async (
|
||||
input: ElectronActiveObservationInput,
|
||||
): Promise<ElectronPaths> => {
|
||||
|
||||
Reference in New Issue
Block a user