Repository navigation
Conversation
`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]>
[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. FindingsFix 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.SummaryRecovers Electron IPC calls made through bound methods, including calls passed through guard wrappers.
Acknowledged scope decisions:
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]
Reviews (1) · Last reviewed commit: "fix(electron): recover IPC registered th..." · Reviewed by Greptile |
| ipcDescriptor( | ||
| electronCalleePath(node.callee, context) ?? | ||
| context.electronInvocationPath?.(node), | ||
| ); |
There was a problem hiding this 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.
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.| } 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) }; |
There was a problem hiding this 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)
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!
|
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:
The 3 tests that failed in the red run:
CI on 01dab07:
The head is 1,085 commits behind main b81da90. GitHub says the PR is mergeable, and its merge state is blocked. Not run
Test setup
Commandsnpm 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 🦊 |
|
@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. |
|
@patrunks also, this branch has merge conflicts with |
Summary
Electron IPC handlers registered through a bound
ipcMainmethod were silently dropped byanalyze_javascript_application. On a real Electron app (215ipcMain.handleregistrations made throughipcMain.handle.bind(ipcMain)plus two guard wrappers), REA reportedmain_handlers: 0and 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:
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 foripcRenderer.invoke.bind(ipcRenderer).Two producers lose the identity:
javascriptModuleInteropresolves bound callables only for JavaScript intrinsics (capturedIntrinsic), soelectronInvocationPathcannot seehandle(...)asipcMain.handle, andinspectIpcCallonly consultedelectronCalleePath.JavaScriptSymbolicBindingsturns a call on an external….bindvalue into an unknown, so wrapper call-path resolution loses site-determined channels passed throughprotectedIpc(channel, …)→rawIpcHandle→ boundhandle.Change and scope
resolveBoundIntrinsic/boundIntrinsicaccept the caller-selected callable path thatintrinsicInvocationalready 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.inspectIpcCallfalls back tocontext.electronInvocationPath, assetAppPathdetection already does.external.method.bind(receiver)asexternal.methodonly 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
javascriptModuleInterop, consumed byelectronInvocationPath→inspectIpcCall), and symbolic call evaluation (JavaScriptSymbolicBindings, consumed byelectronWrappedCallPaths). No superseded path remains.electron.ipcfindings are reported.app.setAppPathinvocation is now reported in addition to its existing bind-site escape finding (2app_path_changesinstead of 1 forconst 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.Expected effects:
Evidence and regression coverage
Tests added or updated (
src/domain/javascript/electronStaticAnalysisIdentity.test.ts):recovers IPC operations invoked through bound Electron methods: boundipcMain.handleandipcRenderer.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+protectedIpcshape; the channel resolves tosites:list.setAppPathbound case: expectation changed from 1 to 2 findings, as described above.Base reproduction (executed, local CLI
node scripts/rea.mjs analyze-javascript-application <dir> --jsonon minimal directories):main_handlers/literal_channelsipcMain.handle.bindonly.bind+ two wrappers--source-path dist-electron/electron/main.jsUser-visible CLI/MCP output:
electron.ipcsummary 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:
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
setAppPathfinding.Author readiness
Human owner:
Before merge
type(scope): outcome.🤖 Generated with Claude Code