Skip to content

feat(electron)!: run active captures with a private profile by default - #10704

Closed
morluto wants to merge 1 commit into
mainfrom
fix/electron-capture-isolation
Closed

morluto wants to merge 1 commit into
mainfrom
fix/electron-capture-isolation

Conversation

@morluto

@morluto morluto commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

capture_electron_scenario launched the target Electron app with the operator's real HOME, temp directory and Electron profile. A capture could read and change the operator's existing app data, caches and saved logins, and nothing in the request let the caller choose otherwise.

This adds profile: "isolated" | "real". Omitting it means isolated: the app runs with a private temporary profile that REA owns and deletes. "real" keeps the previous behavior as an explicit caller choice. The tool description also stops claiming that updater effects are blocked.

No open issue tracks profile isolation; this implements the maintainer's structural-audit decision D7 ("Electron capture scope: research and address").

User-visible change: by default, active Electron captures no longer see saved logins or existing app data. To capture against the operator's real profile, pass "profile": "real".

Problem and expected behavior

Observed on macOS with stock Electron 44.7.0, driving a REA-authored probe app through PlaywrightElectronActiveProvider (no third-party app was run):

  • app.getPath('userData') was ~/Library/Application Support/Electron, the operator's real directory, and the run updated its mtime. home, os.homedir() and os.tmpdir() were also the real ones.
  • REA starts .js entries, so the app is named Electron. As a result, every such capture shared one persistent profile, and state carried over from one capture to the next.
  • The single-instance lock lives in userData. When I started a second instance against the same profile, requestSingleInstanceLock() returned false. Per the Electron docs, that second instance forwards its argv to the running one. So capturing an app the operator already has open hands REA's launch, including the caller's arguments, to the operator's running instance.
  • Setting only a temporary HOME does not isolate Electron on macOS, because Cocoa paths ignore $HOME. --user-data-dir moves userData but leaves appData and home real. Calling app.setPath('appData'|'home'|...) from the pre-app -r hook moves everything: userData, sessionData and the lock follow appData.

Expected: a capture does not touch the operator's real app profile unless the caller explicitly asks for it.

Change and scope

  • ElectronCaptureProfile is the new owner of the per-capture private root. It is created with mode 0700 and contains the home, appData, temp, logs and crashDumps directories. It also provides the environment to launch with: HOME, TMPDIR, TMP, and on Windows TEMP, USERPROFILE, APPDATA and LOCALAPPDATA. In isolated mode the real HOMEDRIVE/HOMEPATH are not forwarded.
  • scripts/electron-active-hook.cjs reads the one-time REA_ELECTRON_CAPTURE_PROFILE handoff and calls app.setPath for each path before application code runs. If any path cannot be applied, it fails closed: it writes a stderr message and exits with code 78, so the app never runs against the real profile instead.
  • ElectronCaptureCleanup gains an electron_profile lease that is released only after the owned process family is released. If process cleanup cannot be verified, the profile stays retained with the cleanup error, and a later retry or close removes it in that order. A launch that never produced an application still removes its profile, and if that removal fails the profile is retained.
  • The omitted→isolated interpretation happens once, in canonicalizeInput (application layer). The canonical input type requires profile. I used .optional() rather than a schema default so the advertised-dialect default baseline does not grow.
  • Evidence parameters keep the caller's request unchanged (an omitted field stays omitted) and add resolved_profile. The first limitation in the result states the mode and what it does not isolate.
  • Docs: the guide gains an "Application profile" section and an exact list of what the hook blocks and what it does not. The tool description is corrected.

Intentionally not included (proposed follow-ups):

  • The Linux renderer sandbox. Playwright adds --no-sandbox because REA does not pass chromiumSandbox. The browser-scenario sibling passes chromiumSandboxEnabled(env). Adopting the same rule would change behavior on Linux hosts without user namespaces or a SUID chrome-sandbox, and I have no real Linux run to verify it.
  • Isolating the keychain and credential store (--use-mock-keychain, --password-store=basic). It is unverified whether Electron 44 safeStorage honors these, and testing it on macOS risks touching the real login keychain.
  • Blocking child processes or filesystem writes (option C in the research). Interception cannot be complete and breaks app startup. Real containment needs an OS sandbox, which needs its own scope decision.

The research and options are in the structural-audit report 17 (local), decision D7.

Contract and boundary impact

  • Semantic owner and earliest changed stage: ElectronCaptureProfile (resource owner) together with canonicalizeInput (owns the profile choice). Consumers: provider launch env, hook, cleanup owner, projection limitations, Evidence parameters.
  • Contribution scope fit and linked maintainer decision: the maintainer's D7 decision asked to "research and address" Electron capture isolation. The change narrows the effect of target execution; it adds no new authority.
  • CLI and MCP/tool-catalog contract: additive optional input profile on capture_electron_scenario (MCP and the CLI JSON request). The description text changed. The result schema is unchanged; one limitation string was added.
  • Provider, bridge, target-format, or platform compatibility: macOS was verified with real Electron 44.7.0. The Linux and Windows environment and paths are derived from the Electron docs and not run.
  • Evidence, artifact, provenance, or reconstruction contract: Evidence parameters gains resolved_profile. The reconciliation parser uses passthrough, and scenario_sha256 still covers only the caller's scenario.
  • Target selection, authority, upstream behavior, and cleanup details: the private root is removed only after verified process release and is retained with the cleanup error otherwise. Isolated mode fails closed.
  • Generated metadata: tool description and input schema; CI regenerates the catalogs.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

(These are the tool's existing effects. This PR reduces which files it changes by default.)

Evidence and regression coverage

  • Tests added or updated:

    • tests/boundary/browser/electronActiveHook.test.ts: the hook applies all five paths before app code and consumes the handoff. When setPath is rejected or a path is malformed, the process exits with code 78 and no app code runs. All 3 cases fail against the origin/main hook (checked by swapping the file in).
    • PlaywrightElectronActiveProvider.test.ts:
      • The launch env for isolated and real: isolated redirects HOME/TMPDIR/TMP into an existing rea-electron-profile-* root, ignores a forged ambient handoff, and removes the root after a failed launch.
      • Windows variable redirection.
      • The profile is retained while process cleanup fails, then removed by close().
      • Removal of an unlaunched profile fails, the profile is retained, and a retry removes it.
      • The limitation text for each mode.
    • ElectronActiveObservationService.test.ts: omitted → isolated, the caller-selected mode reaches the provider, and Evidence records resolved_profile.
    • Existing canonical-input fixtures now carry profile. electronMcp.test.ts splits resolved_profile out of the scenario digest check.
  • Base reproduction: the probe run against the unchanged provider showed the real userData/home/tmp values above. Lifecycle regressions covered: cleanup retry, mixed outcomes (process failure + profile), and launch failure. The existing cancellation-during-cleanup tests now run with the isolated profile by default and pass.

  • User-visible output: the first limitation of an isolated capture now reads "The application ran with a private temporary home, temp directory and Electron profile that REA deletes after the capture; …".

  • Remaining proof gaps: no Linux or Windows real-Electron run. Keychain isolation is not attempted.

  • Observed, derived, and inferred claims remain distinguishable.

  • Artifact identity, source provenance, and failed attempts remain preserved.

  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run check:fast: passed (typecheck + lint).
  • npx oxfmt --check <changed files>: passed.
  • npm run docs:check: passed.
  • npm run test:local -- src/browser/PlaywrightElectronActiveProvider.test.ts src/browser/PlaywrightElectronActiveProjection.test.ts src/browser/ElectronCaptureCleanup.test.ts src/electron/ElectronFuseCleanup.test.ts src/application/javascript/ElectronActiveObservationService.test.ts src/contracts/toolEffects.test.ts src/browser/PlaywrightElectronActiveFuses.test.ts: all passed.
  • npm run test:focused -- tests/boundary/mcp/advertisedDialect.test.ts tests/boundary/mcp/electronMcp.test.ts tests/acceptance/tools/localToolContracts.test.ts tests/boundary/cli/scenarioCliInputDiagnostics.test.ts tests/boundary/mcp/toolSchemaValidity.test.ts tests/boundary/cli/cliInputSchemaRequired.test.ts tests/acceptance/applications/electronInvalidPaths.test.ts tests/boundary/browser/electronActiveHook.test.ts tests/boundary/filesystem/javascript-applications/javascriptRuntimeReconciliation.test.ts tests/boundary/process/darwinProcessRunTokenReader.test.ts: all passed after the final changes. electronMcp and advertisedDialect were rerun after their fixes.
  • Real Electron 44.7.0 (macOS) through the built provider with a REA-authored probe app:
    • Omitted and isolated: userData, appData, home, os.homedir() and tmp were all inside rea-electron-profile-*. The real ~/Library/Application Support/Electron mtime was unchanged, and the root was gone afterwards.
    • real: the real paths, as before.
  • REA_ELECTRON_EXECUTABLE=… npm run verify:electron: fails before the active stage in the reconcile_javascript_runtime MCP probe with "MCP tool arguments exceed the configured input element allowance (1024)". That failure is independent of this change.
  • The active stage of the same verifier, run alone with profile forced to real and then isolated (twice each), failed identically in both modes: "did not observe the readiness IPC round trip", with the post-crash wait failing with "Page crashed". Actions, IPC count (5), timeline count (133) and event kinds were identical across modes, so isolation does not change this pre-existing lane result.

Compatibility, safety, and release

  • Breaking changes or migration steps: no schema break. The default behavior changes: captures that relied on the real profile's login state now need "profile": "real". The maintainer may prefer a ! marker for this default change.
  • Real Hopper/Ghidra, browser, or OS coverage: real Electron on macOS only.
  • Package or release metadata impact: none beyond the generated tool catalog.
  • Security, privacy, process, or containment review: this reduces writes to the operator's data by default and fails closed. It is not a sandbox: network, child processes, the credential store and absolute paths chosen by the app are not isolated, and the docs and limitation say so.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

Migration

BREAKING CHANGE: capture_electron_scenario now runs the app with a private temporary profile by default. Captures that relied on the app's saved logins or other existing state must now pass "profile": "real". Example: {"app": "/Applications/Example.app", "steps": [...]} previously ran with the user's real profile. It now runs isolated. Add "profile": "real" to keep the old behaviour. The change is breaking because the default changes what the launched app can read and write, and no compatibility shim can preserve both defaults.

capture_electron_scenario launched the target with the operator's real
HOME, temp directory and Electron profile. A capture could read and change
existing app data, caches and saved logins, every capture of a .js entry
shared one persistent 'Electron' profile, and launching an app the operator
already runs handed the launch to that instance through the single-instance
lock.

Add profile: isolated | real. Omitted means isolated: the provider owns a
private 0700 root, redirects HOME/TMPDIR/TMP (and Windows TEMP, USERPROFILE,
APPDATA, LOCALAPPDATA) into it, and the active hook sets Electron's home,
appData, temp, logs and crashDumps paths before application code runs,
stopping the launch if it cannot. The root is removed after the owned
processes are released and is retained with the cleanup error otherwise.
profile real keeps the previous behaviour as an explicit choice.

The tool description no longer claims updater effects are blocked.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T00:53:09.163664Z 1e0b39e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@morluto morluto changed the title feat(electron): run active captures with a private profile by default feat(electron)!: run active captures with a private profile by default Nov 15, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1e0b39e7c0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +44 to +46
} catch (cause: unknown) {
await profile.remove();
throw cause;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Retain the profile owner when initialization rollback fails

If profile initialization fails in chmod or mkdir and the subsequent profile.remove() also fails, create() rejects without returning or retaining the allocated profile. The provider's profile variable therefore remains undefined, so its cleanup path and later close() cannot retry removal. Fault-injecting initialization and rollback failures leaves the directory present and produces an error without cleanup metadata or a cleanup lease; the rollback error also replaces the original failure. Retain the allocated owner through the resource scope when rollback fails, preserving both the initialization failure and retryable cleanup authority.

AGENTS.md reference: AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

@greptile-apps

greptile-apps Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5 Tier: plus

[Medium impact] The default-profile change affects active Electron captures, not the other observation workflows.

Fix X11 display access and satisfy the failed-cleanup ownership requirement before merging.

Fix All in CodexFindings

  1. P1 Isolated captures lose X11 access ▶
  2. P2 Failed setup loses cleanup ownership ▶
  3. P2 Security Profile description overstates file protection ▶
Fix with agent prompt
### Issue 1
src/browser/PlaywrightElectronActiveProvider.ts:463-464
If a Linux desktop uses `$HOME/.Xauthority` without setting `XAUTHORITY`, the new default profile prevents Electron from opening the X11 display. The launch replaces `HOME` with an empty private directory but only forwards `XAUTHORITY` when already set. Electron then looks for the display cookie in the private home.

Resolve the existing authority-file path before replacing `HOME`, while preserving an explicit `XAUTHORITY`, as the desktop reader already does.

### Issue 2
src/browser/ElectronCaptureProfile.ts:44-46
If profile setup fails and `profile.remove()` also fails, `create()` loses the directory's cleanup owner and replaces the original setup error. The provider never receives the profile, so neither another capture nor `close()` can retry removal.

This violates the repository requirement, “Retain ownership of resources whose cleanup failed,” which must be satisfied before merging. Register cleanup ownership as soon as the root exists and preserve both failures.

### Issue 3
src/domain/javascript/electronActiveObservation.ts:91
The new `profile` description promises that an isolated app “cannot read or change” existing app data. Redirecting default paths does not provide that protection: the app keeps normal filesystem access, and app-selected paths remain accessible. Callers may mistake a private profile for a security sandbox.

Qualify the advertised description to say that default paths are redirected, not that existing files are protected.

> **How this was verified:** The capture redirects environment and Electron paths, while the app keeps host filesystem privileges and access to paths it chooses.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds optional profile selection, defaults captures to a private profile, and ties profile removal to process cleanup.

  • Active Electron captures use a private profile unless the caller chooses the real one.
  • The guide and tool summary say which effects the capture hook leaves unblocked.

Acknowledged scope:

  • morluto intentionally changes the default login/data state and leaves caller arguments, including --user-data-dir, unchanged.
  • morluto deferred Linux renderer sandbox changes and credential-store isolation because real-platform verification is missing.
  • morluto excluded filesystem and child-process containment because complete containment needs an OS sandbox.
  • morluto identified the verifier's input-limit and readiness failures as pre-existing, with matching results in both profile modes.
  • morluto cites maintainer decision D7 instead of a linked issue and explicitly leaves the breaking-change title marker to maintainer preference.

No runtime tests were run during this review. Whether another PR supersedes this one could not be checked because GitHub access was unavailable.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  Request[Capture request] --> Choice{Profile choice}
  Choice -->|omitted or isolated|Private[Create private profile]
  Choice -->|real|Launch[Launch Electron]
  Private --> Launch
  Launch --> Hook[Apply private paths when selected]
  Hook --> Capture[Capture actions and events]
  Capture --> Release[Release owned processes]
  Release -->|confirmed|Remove[Remove private profile]
  Release -->|unconfirmed|Retain[Retain profile and cleanup error]
  Retain -->|retry|Release
Loading

Reviews (1) · Last reviewed commit: "feat(electron): run active captures with..." · Reviewed by Greptile

Comment on lines +463 to +464
...operatorElectronEnvironment(environment, platform, profile !== undefined),
...profile?.environment(platform),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Isolated captures lose X11 access

If a Linux desktop uses $HOME/.Xauthority without setting XAUTHORITY, the new default profile prevents Electron from opening the X11 display. The launch replaces HOME with an empty private directory but only forwards XAUTHORITY when already set. Electron then looks for the display cookie in the private home.

Resolve the existing authority-file path before replacing HOME, while preserving an explicit XAUTHORITY, as the desktop reader already does.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/browser/PlaywrightElectronActiveProvider.ts
Line: 463-464

Comment:
**Isolated captures lose X11 access**

If a Linux desktop uses `$HOME/.Xauthority` without setting `XAUTHORITY`, the new default profile prevents Electron from opening the X11 display. The launch replaces `HOME` with an empty private directory but only forwards `XAUTHORITY` when already set. Electron then looks for the display cookie in the private home.

Resolve the existing authority-file path before replacing `HOME`, while preserving an explicit `XAUTHORITY`, as the desktop reader already does.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Codex

Comment on lines +44 to +46
} catch (cause: unknown) {
await profile.remove();
throw cause;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Failed setup loses cleanup ownership

If profile setup fails and profile.remove() also fails, create() loses the directory's cleanup owner and replaces the original setup error. The provider never receives the profile, so neither another capture nor close() can retry removal.

This violates the repository requirement, “Retain ownership of resources whose cleanup failed,” which must be satisfied before merging. Register cleanup ownership as soon as the root exists and preserve both failures.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/browser/ElectronCaptureProfile.ts
Line: 44-46

Comment:
**Failed setup loses cleanup ownership**

If profile setup fails and `profile.remove()` also fails, `create()` loses the directory's cleanup owner and replaces the original setup error. The provider never receives the profile, so neither another capture nor `close()` can retry removal.

This violates the repository requirement, “Retain ownership of resources whose cleanup failed,” which must be satisfied before merging. Register cleanup ownership as soon as the root exists and preserve both failures.

**Context Used:** AGENTS.md ([source](https://github.com/morluto/rea/blob/main/AGENTS.md))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Codex

profile: electronCaptureProfileSchema
.optional()
.describe(
"Omit for isolated. isolated: the app runs with a private temporary home, temp directory and Electron profile that REA deletes after the capture, so it cannot read or change the operator's existing app data and starts without saved login state. real: the app uses the operator's HOME and its normal Electron profile, so it can read and change existing app data, caches and saved logins, and if the same app is already running it may hand the launch to that instance.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 security Profile description overstates file protection

The new profile description promises that an isolated app “cannot read or change” existing app data. Redirecting default paths does not provide that protection: the app keeps normal filesystem access, and app-selected paths remain accessible. Callers may mistake a private profile for a security sandbox.

Qualify the advertised description to say that default paths are redirected, not that existing files are protected.

How this was verified: The capture redirects environment and Electron paths, while the app keeps host filesystem privileges and access to paths it chooses.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/electronActiveObservation.ts
Line: 91

Comment:
**Profile description overstates file protection**

The new `profile` description promises that an isolated app “cannot read or change” existing app data. Redirecting default paths does not provide that protection: the app keeps normal filesystem access, and app-selected paths remain accessible. Callers may mistake a private profile for a security sandbox.

Qualify the advertised description to say that default paths are redirected, not that existing files are protected.

> **How this was verified:** The capture redirects environment and Electron paths, while the app keeps host filesystem privileges and access to paths it chooses.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Codex

@morluto

morluto commented Nov 15, 2026

Copy link
Copy Markdown
Owner Author

Thank you for the careful research here, especially the macOS path findings. The maintainer decided to keep active Electron captures on the real app profile. Running against a logged-in app is the common workflow, and no problems with it have been reported, so the private-profile default and profile option will not be merged.

The single-instance handoff you found is a real correctness bug. A capture of an app that is already running gets handed to the running instance. That is fixed separately in #10989: the hook stops the launched instance when its lock request is refused, and the capture fails with application_already_running and a recovery step. Closing this PR in favor of that one.

@morluto morluto closed this Nov 15, 2026
@morluto morluto added area: runtime Process capture and runtime observation enhancement New feature or request provider: electron Analysis provider / engine: electron labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation enhancement New feature or request provider: electron Analysis provider / engine: electron

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant