Repository navigation
fix(javascript): follow Electron through aliases of Webpack externals - #6993
mohammadasim224 wants to merge 3 commits into
Conversation
A binding initialized from another binding, such as
`const s = n(45840); const { BrowserWindow } = s`, lost its Electron
identity when `s` held a proven Webpack external. General provenance only
recognizes literal `require`, so destructured windows and IPC handlers
were omitted. Follow stable lexical aliases in the Electron binding owner,
bounded by visited bindings and the shared alias selection limit.
Refs morluto#4490
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ct eval Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
[Medium impact] The change affects findings from JavaScript application analysis. The alias capture-order bug should be fixed before merging. Findings
Fix with agent prompt### Issue 1
src/domain/javascript/javascriptSemanticAnalysis.ts:1052
`bindingOrigin` follows the source initializer without checking whether it ran before the alias was captured. For example, `var w=s; var s=require("electron"); new w.BrowserWindow({});` now proves `w` is Electron, although `w` captured `undefined`. This can produce false window or IPC findings.
Previously, general provenance used `semanticBindingAtRead` to exclude the later initializer. Select the source binding at the alias read before following its origin.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryThe PR follows Electron identity through aliases of proven Webpack externals.
Reviews (3) · Last reviewed commit: "fix(ci): merge main to isolate JavaScrip..." · Reviewed by Greptile |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
| semanticBindingMayHaveOpaqueEffect(hop, state), | ||
| ) | ||
| ? undefined | ||
| : bindingOrigin(alias, state, new Set([...visited, binding.bindingId])); |
There was a problem hiding this comment.
bindingOrigin follows the source initializer without checking whether it ran before the alias was captured. For example, var w=s; var s=require("electron"); new w.BrowserWindow({}); now proves w is Electron, although w captured undefined. This can produce false window or IPC findings.
Previously, general provenance used semanticBindingAtRead to exclude the later initializer. Select the source binding at the alias read before following its origin.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptSemanticAnalysis.ts
Line: 1052
Comment:
**Aliases inherit later values**
`bindingOrigin` follows the source initializer without checking whether it ran before the alias was captured. For example, `var w=s; var s=require("electron"); new w.BrowserWindow({});` now proves `w` is Electron, although `w` captured `undefined`. This can produce false window or IPC findings.
Previously, general provenance used `semanticBindingAtRead` to exclude the later initializer. Select the source binding at the alias read before following its origin.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.|
TL;DR: The fix works on all six fixtures from #4490. I couldn't confirm it on Bitwarden because of a separate 6.8.0 bound (details below). Thanks, mohammadasim224. Build: this PR's head
Bitwarden desktop 2026.10.0 ( I tried raising |
General provenance only knew a literal require, so a bundled Electron
external held in one binding and destructured from another
(`const s=n(K);const{BrowserWindow}=s`) lost its windows and IPC. The
Electron binding origin now follows stable lexical aliases, and stops at
a rebindable binding that direct eval may have changed.
Fixes #4490
Supersedes #6993
Squashed from #6993 and rebased onto main. Rebase adaptation: the walk
uses the caller-selectable precision.alias_selections budget (the fixed
SEMANTIC_ALIAS_SELECTION_LIMIT it used was removed by #9706) and records
alias-selections when it stops there; a test pins that an over-budget
chain is not claimed and the limit is reported.
Co-Authored-By: gensokyo-dev <[email protected]>
General provenance only knew a literal require, so a bundled Electron
external held in one binding and destructured from another
(`const s=n(K);const{BrowserWindow}=s`) lost its windows and IPC. The
Electron binding origin now follows stable lexical aliases, and stops at
a rebindable binding that direct eval may have changed.
Fixes #4490
Supersedes #6993
Squashed from #6993 and rebased onto main. Rebase adaptation: the walk
uses the caller-selectable precision.alias_selections budget (the fixed
SEMANTIC_ALIAS_SELECTION_LIMIT it used was removed by #9706) and records
alias-selections when it stops there; a test pins that an over-budget
chain is not claimed and the limit is reported.
Co-Authored-By: gensokyo-dev <[email protected]>
|
Thank you for this fix. It landed in #10538 with your authorship kept on the commit (plus review follow-ups noted in the PR), so I'm closing this PR as superseded. |
Summary
Refs #4490 (the
BrowserWindow/IPC destructuring part). Electron identity was lost when a destructuring or alias read from a binding that held a proven Webpack external:const s = n(45840); const { BrowserWindow, ipcMain } = s. Windows (includingnodeIntegration: trueones) and identity-based IPC handlers were omitted with no unknown. Directconst { BrowserWindow } = n(45840)andrequire("electron")aliases already worked.Problem and expected behavior
Smallest trigger, Webpack 5 bootstrap from #2948 with this factory body:
On
main(dd02d8ff6)rea analyze-javascript-applicationreportsbrowser_windows: 0. Expected: 1, with the same identity asnew s.BrowserWindow(...).Cause:
bindingOriginresolves an initializer withsemanticRequireOriginorsemanticBundledRequireOrigin, which only accept a call. When the initializer is another identifier, it falls back to general provenance (evaluateSemanticProvenance), which recognizes literalrequireonly, so the bundled external is not followed.Change and scope
bindingOrigin(the Electron identity owner) now follows a stable lexical alias initializer to the binding it names and appends the projection. It reusessemanticStableInitializer, stops on cycles through visited binding IDs, and is bounded bySEMANTIC_ALIAS_SELECTION_LIMIT. Like general provenance, a hop stops at a rebindable binding that directevalmay have changed, solet s=require("electron");eval(code);const{BrowserWindow}=sstays unresolved as onmain. Member writes through such aliases are now attributed by the existing write coverage, soconst w=s; w.BrowserWindow=class{}keeps the window unresolved.The bundled origin is still not added to general provenance; #2948 scoped it to Electron identity, and this keeps that scope.
Pre-existing and unchanged: a direct member read of a bundled external binding (
let s=n(45840);eval(code);new s.BrowserWindow()) resolves onmainwithout the direct-eval check, becausesemanticBundledRequireOriginis not routed through provenance. Not changed here.Not included: unknowns for computed-key or rest destructuring (the issue's last request). This matches plain-
requiredestructuring, which also returns no binding there; it needs a separate decision.Ordinary fix within existing boundaries; maintainer scope decision: not applicable.
Related: #4493 also references #4490 but bundles six issues, has conflicts with
main, and was last updated 2026-10-20.Contract and boundary impact
Semantic owner and earliest changed stage: Electron identity in
src/domain/javascript/javascriptSemanticAnalysis.ts(bindingOrigin).Contribution scope fit and linked maintainer decision: existing static analysis; not applicable.
CLI and MCP/tool-catalog contract: unchanged schema; more
browser_windows/IPC findings for this input shape.Provider, bridge, target-format, or platform compatibility: none.
Evidence, artifact, provenance, or reconstruction contract: unchanged.
Target selection, authority, upstream behavior, and cleanup details: not applicable.
Generated metadata, package, or installation impact: none.
Read existing files or captured data.
Evidence and regression coverage
src/domain/javascript/electronBundledRequireIdentity.test.ts(shorthand, renamed, plain alias, two-hop alias, top-level and guarded destructured IPC; reassigned binding, overwritten member directly and through an alias, cyclic alias, wrong table key, and direct-eval-exposed bundled andrequirealiases stay unresolved).tests/acceptance/applications/webpackLoaderReturnsCli.test.tsadds a CLI row for the destructured form.browser_windows/main_handlers):const{BrowserWindow}=s; new BrowserWindow(...)const{BrowserWindow:W}=s; new W(...)const{BrowserWindow,ipcMain}=s; ...Derived, not read from CLI output (it has no
resolution_basis): themain_handlers: 1before the fix most likely came from the non-identitywrapper-substitutionpath. The equivalent unit test, which filters that basis out, finds no handler on the base.Remaining proof gaps: Bitwarden 2026.10.0 (34/34 handlers in the issue) not run.
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
CI follow-up at
0aa85fb86(2026-10-25), Node 24.22.1 / npm 11.16.0 on macOS:aced9fa9b, including test(mcp): verify recovery before reading retained views #7029 (bc9efc927): recovery is checked before materializing retained views; the original partial Evidence is then verified after the new analysis, with all 1,500 source occurrences and their identities preserved. No additional Electron implementation change was needed.npm run check:fast(typecheck/lint) andnpm run format:check: passed.Earlier author validation:
Node 24.22.1, npm 11.16.0, macOS arm64.
npm run test:local -- src/domain/javascript/*.test.ts— 149 files, 4080 tests passednpm run test:focused -- tests/acceptance/applications/webpackLoaderReturnsCli.test.ts tests/acceptance/applications/applicationWorkflowCli.test.ts— 2 files, 41 tests passednpm run check:fast— typecheck and lint passedanalyze-javascript-applicationon@babel/parser/lib/index.js(481 KB), 3 warm runs each: before 6.65–6.90 s wall, 8.49–8.77 s CPU, 588–593 MiB max RSS; after 6.88–7.39 s wall, 8.68–8.88 s CPU, 588–594 MiB. Within run-to-run noise. Max RSS is/usr/bin/time -l(largest reaped process, not a process-family sum). Agent token cost unchanged except for the added findings. Not measured on a large Electron bundle.Compatibility, safety, and release
Author readiness
Human owner:
Before merge
type(scope): outcome.🤖 Generated with Claude Code