Skip to content

fix(electron): recover IPC registered through bound Electron methods - #7268

Draft
patrunks wants to merge 1 commit into
morluto:mainfrom
patrunks:fix/electron-bound-ipc
Draft

patrunks wants to merge 1 commit into
morluto:mainfrom
patrunks:fix/electron-bound-ipc

Conversation

@patrunks

Copy link
Copy Markdown

Summary

Electron IPC handlers registered through a bound ipcMain method were silently dropped by analyze_javascript_application. On a real Electron app (215 ipcMain.handle registrations made through ipcMain.handle.bind(ipcMain) plus two guard wrappers), REA reported main_handlers: 0 and every renderer invoke as unpaired, with no unknown recorded. No related issue was filed; the trigger is described below.

Problem and expected behavior

Smallest trigger:

const electron_1 = require("electron");
const handle = electron_1.ipcMain.handle.bind(electron_1.ipcMain);
handle("ch:a", async () => 1);

Base revision: ipc.operations: 0. The registration disappears instead of remaining an explicit unknown, which violates the "unresolved identity remains unknown, not absent" invariant. The same holds for ipcRenderer.invoke.bind(ipcRenderer).

Two producers lose the identity:

  1. javascriptModuleInterop resolves bound callables only for JavaScript intrinsics (capturedIntrinsic), so electronInvocationPath cannot see handle(...) as ipcMain.handle, and inspectIpcCall only consulted electronCalleePath.
  2. JavaScriptSymbolicBindings turns a call on an external ….bind value into an unknown, so wrapper call-path resolution loses site-determined channels passed through protectedIpc(channel, …) → rawIpcHandle → bound handle.

Change and scope

  • resolveBoundIntrinsic/boundIntrinsic accept the caller-selected callable path that intrinsicInvocation already takes. A bind site whose callee is a proven Electron export is admitted with the existing stable-initializer, write-coverage and bound-argument rules. The intrinsic-only default is unchanged.
  • inspectIpcCall falls back to context.electronInvocationPath, as setAppPath detection already does.
  • The symbolic evaluator keeps external.method.bind(receiver) as external.method only when the bind supplies at most a receiver and no spread. Extra bound arguments would shift the channel position, so that case stays unknown.

Not included: receiver validation for bound methods (direct member calls do not validate receivers either), and bound arguments beyond the receiver.

Contribution scope: ordinary fix within existing boundaries; maintainer scope decision not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: Electron identity for bound callables (javascriptModuleInterop, consumed by electronInvocationPath → inspectIpcCall), and symbolic call evaluation (JavaScriptSymbolicBindings, consumed by electronWrappedCallPaths). No superseded path remains.
  • Contribution scope fit and linked maintainer decision: not applicable (fix inside existing static JavaScript analysis).
  • CLI and MCP/tool-catalog contract: no schema change. More electron.ipc findings are reported.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: a bound app.setAppPath invocation is now reported in addition to its existing bind-site escape finding (2 app_path_changes instead of 1 for const change = app.setAppPath.bind(app); change("./other")). Both are justified: the bind may escape, and the invocation is now proven. The existing test expectation was updated accordingly.
  • Target selection, authority, upstream behavior, and cleanup details: not applicable.
  • Generated metadata, package, or installation impact: none.

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.

Evidence and regression coverage

  • Tests added or updated (src/domain/javascript/electronStaticAnalysisIdentity.test.ts):

    • recovers IPC operations invoked through bound Electron methods: bound ipcMain.handle and ipcRenderer.invoke. On the base revision it returns [] instead of both operations (executed).
    • recovers a bound IPC registration passed through guard wrappers: the exact .bind + rawIpcHandle + protectedIpc shape; the channel resolves to sites:list.
    • setAppPath bound case: expectation changed from 1 to 2 findings, as described above.
  • Base reproduction (executed, local CLI node scripts/rea.mjs analyze-javascript-application <dir> --json on minimal directories):

    Case base main_handlers / literal_channels this branch
    direct ipcMain.handle 1 / 1 1 / 1
    .bind only 0 / 0 1 / 1
    .bind + two wrappers 0 / 0 2 / 1 (1 literal + 1 dynamic wrapper-internal registration)
    real app ASAR, --source-path dist-electron/electron/main.js 0 / 0 216 / 215
  • User-visible CLI/MCP output: electron.ipc summary counts above.

  • Remaining proof gaps: MCP adapter not exercised on this branch (same producer as CLI). The real-app ASAR is third-party and not included. Boundary regressions: identity/alias resolution for parser output; malformed-input and lifecycle regressions are not applicable.

For evidence-bearing changes:

  • 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

  • npx vitest run src/domain/javascript/electronStaticAnalysisIdentity.test.ts: 37 passed.
  • npx vitest run src/domain/javascript src/application/javascript: 178 files, 4804 passed, 6 skipped.
  • npm run check:fast: typecheck and lint, 2/2 tasks successful.
  • npm run compile, then the CLI runs above, using the Windows native controls extracted from the published [email protected] tarball (manifest SHA-256 matched). Windows Server 2022, Node 24.22.1.
  • npm run check:pr: not run.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Additional findings only, including the extra bound setAppPath finding.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable (static JavaScript). Windows only for the CLI runs.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no execution; analysis remains inert parsing.

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.

🤖 Generated with Claude Code

`const handle = ipcMain.handle.bind(ipcMain); handle("ch", fn)` was
silently dropped: bound-callable resolution only admitted JavaScript
intrinsics, and the symbolic evaluator turned a bound external method
into an unknown value, losing channels passed through guard wrappers.

Resolve bound Electron methods at the bind site through the caller's
callable path, and keep a receiver-only `.bind` of an external method as
that method. Extra bound arguments stay unknown because they shift the
argument order. A bound `app.setAppPath` invocation is now reported in
addition to its bind-site escape finding.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@greptile-apps

greptile-apps Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 3/5

[Medium impact] The changes affect findings from static JavaScript analysis of Electron apps.

Fix the wrong argument positions and the missing native bind check before merging.

Findings

  1. P1 Bound calls read wrong arguments ▶
  2. P1 Replaced bind creates false registrations ▶
Fix with agent prompt
### Issue 1
src/domain/javascript/electronStaticAnalysisIpc.ts:44-47
For `const h = ipcMain.handle.bind(ipcMain); h.call(ipcMain, 'ch:a', async () => 1)`, `electronInvocationPath` identifies the underlying method, but `inspectIpcCall` reads the original arguments. It treats `ipcMain` as the channel and `'ch:a'` as the handler. The recovered registration has an unknown channel and the wrong handler location, so renderer calls cannot be paired correctly. Return and consume the normalized arguments alongside the method path.

### Issue 2
src/domain/javascript/javascriptSymbolicBindings.ts:1124-1132
If `Function.prototype.bind` is replaced with `function () { return () => {}; }`, binding `ipcMain.handle` and calling it through guard wrappers does nothing. This new branch still produces `electron.ipcMain.handle`, and `electronWrappedCallPaths` reports a literal registration that never happens.

Reuse the shared bind proof instead of stripping the path alone. That reader already checks whether native bind was overwritten. This also violates the repository requirement to preserve unknown identity and use the owning reader's proven facts.

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

Recovers Electron IPC calls made through bound methods, including calls passed through guard wrappers.

  • Bound Electron methods now keep their identity in analysis.

Acknowledged scope decisions:

  • patrunks explicitly deferred receiver validation and extra bound arguments in the PR description.
  • patrunks explicitly acknowledged the additional bound setAppPath finding as intentional; the test expectation matches that decision.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Bound Electron method] --> B[Shared invocation reader]
  B --> C[Method path]
  B --> D[Normalized arguments]
  C --> E[IPC reader]
  F[Original call arguments] --> E
  D -. Must be consumed together .-> E
  A --> G[Symbolic bind reader]
  G --> H[External method path]
  H --> I[Wrapper reader]
Loading

Reviews (1) · Last reviewed commit: "fix(electron): recover IPC registered th..." · Reviewed by Greptile

Comment on lines +44 to +47
ipcDescriptor(
electronCalleePath(node.callee, context) ??
context.electronInvocationPath?.(node),
);

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 Bound calls read wrong arguments

For const h = ipcMain.handle.bind(ipcMain); h.call(ipcMain, 'ch:a', async () => 1), electronInvocationPath identifies the underlying method, but inspectIpcCall reads the original arguments. It treats ipcMain as the channel and 'ch:a' as the handler. The recovered registration has an unknown channel and the wrong handler location, so renderer calls cannot be paired correctly. Return and consume the normalized arguments alongside the method path.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/electronStaticAnalysisIpc.ts
Line: 44-47

Comment:
**Bound calls read wrong arguments**

For `const h = ipcMain.handle.bind(ipcMain); h.call(ipcMain, 'ch:a', async () => 1)`, `electronInvocationPath` identifies the underlying method, but `inspectIpcCall` reads the original arguments. It treats `ipcMain` as the channel and `'ch:a'` as the handler. The recovered registration has an unknown channel and the wrong handler location, so renderer calls cannot be paired correctly. Return and consume the normalized arguments alongside the method path.

---

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

Comment on lines +1124 to +1132
} else if (
value.kind === "external" &&
value.path.length > 2 &&
value.path.at(-1) === "bind" &&
node.arguments.length <= 1 &&
!node.arguments.some((argument) => t.isSpreadElement(argument))
) {
// Binding only a receiver keeps the external method's argument order.
result = { kind: "external", path: value.path.slice(0, -1) };

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 Replaced bind creates false registrations

If Function.prototype.bind is replaced with function () { return () => {}; }, binding ipcMain.handle and calling it through guard wrappers does nothing. This new branch still produces electron.ipcMain.handle, and electronWrappedCallPaths reports a literal registration that never happens.

Reuse the shared bind proof instead of stripping the path alone. That reader already checks whether native bind was overwritten. This also violates the repository requirement to preserve unknown identity and use the owning reader's proven facts.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptSymbolicBindings.ts
Line: 1124-1132

Comment:
**Replaced bind creates false registrations**

If `Function.prototype.bind` is replaced with `function () { return () => {}; }`, binding `ipcMain.handle` and calling it through guard wrappers does nothing. This new branch still produces `electron.ipcMain.handle`, and `electronWrappedCallPaths` reports a literal registration that never happens.

Reuse the shared bind proof instead of stripping the path alone. That reader already checks whether native bind was overwritten. This also violates the repository requirement to preserve unknown identity and use the owning reader's proven facts.

**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.

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!

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: I ran the Electron identity test file at draft head 01dab07 on Node 22, 24 and 26, and all 37 tests passed each time. With the three fix files swapped back to the merge base, 3 tests failed on all three versions. So those 3 tests fail without the fix and pass with it.

Test file: src/domain/javascript/electronStaticAnalysisIdentity.test.ts. The red run is the same head with electronStaticAnalysisIpc.ts, javascriptModuleInterop.ts and javascriptSymbolicBindings.ts swapped back to the merge base 5508b2a.

Run Node 22.23.4 Node 24.22.1 Node 26.12.1
Head 01dab07 pass: 1 file, 37 tests passed pass: 1 file, 37 tests passed pass: 1 file, 37 tests passed
Red run fail: 3 failed, 34 passed fail: 3 failed, 34 passed fail: 3 failed, 34 passed

The 3 tests that failed in the red run:

  • recovers a bound IPC registration passed through guard wrappers
  • recovers IPC operations invoked through bound Electron methods
  • retains indirect application path changes by Electron identity: const change = app.setAppPath.bind(app); change("./other");

CI on 01dab07:

  • CI and PR title are waiting for a maintainer to approve them (action_required).
  • Greptile Review and Validate author declaration passed.
  • The PR readiness workflow passed, but its commit status is pending.

The head is 1,085 commits behind main b81da90. GitHub says the PR is mergeable, and its merge state is blocked.

Not run

  • Bound IPC calls reached through .call, .apply or Reflect.apply, so I did not check which argument is read as the channel there.
  • A real Electron app.
  • A merge with current main, b81da90.
Test setup
  • Box: Fedora 44 VM (4 vCPUs, 8 GB) on my Nobara 44 PC, Linux 7.2.11
  • Node: 22.23.4, 24.22.1, 26.12.1
  • Head / base: 01dab07 / 5508b2a (merge base with main)
  • Red run: 01dab07 with the 3 changed source files from 5508b2a
  • Install: npm ci --offline and npm run test:prepare on Node 24.22.1, exit 0, for both trees
Commands
npm ci --offline
npm run test:prepare
xvfb-run -a npm run test:focused -- src/domain/javascript/electronStaticAnalysisIdentity.test.ts

🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊

@morluto morluto added bug Something isn't working provider: electron Analysis provider / engine: electron labels Nov 23, 2026
@morluto

morluto commented Nov 24, 2026

Copy link
Copy Markdown
Owner

@patrunks thanks for the PR — there are 2 open review threads here:

Could you address or reply to these? Once they're resolved and CI is green we can take another look.
cc @gensokyo-dev @dandgabr

@morluto

morluto commented Nov 24, 2026

Copy link
Copy Markdown
Owner

@patrunks also, this branch has merge conflicts with main — please resolve those along with the open threads.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working provider: electron Analysis provider / engine: electron

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants