Repository navigation
fix(javascript): reject Webpack getters replaced through any identity write - #3860
Conversation
… write The canonical `n.n` getter proof scanned for direct `loader.n =` assignments and four Object methods on its own. `Reflect.set`, `Reflect.defineProperty`, `delete`, destructuring and unknown-key writes left the proof intact, so a replaced or deleted getter still attributed BrowserWindow calls to Electron. Any Object method call on the loader also rejected the proof, even for an unrelated key. The proof now uses the shared identity-write owner (`collectJavaScriptIdentityWritesSteps` with the module interop's intrinsic resolution), as ambient writes already do. A write whose path may select `n` (the key itself, an unknown key, or the whole loader) counts; exactly one canonical assignment installed before entry dispatch remains required. Fixes #3315 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
[Medium impact] Tightens detection of Webpack loader identity overwrites. Fix the missed reflective calls with unknown argument lists before merging. Findings
Fix with agent prompt### Issue 1
src/domain/javascript/javascriptBundledRequireOrigin.ts:160-169
The callback ignores every `"opaque-call"` write, so the fix still misses `apply` calls whose arguments are stored in a variable. For example, inserting `const args=[n,"n",e=>()=>({BrowserWindow:class{}})];Reflect.set.apply(null,args);` before `n(100)` replaces the getter. The shared collector cannot unpack `args`, so it requests an `"opaque-call"` scope. Returning `[]` leaves only the original getter installation counted, and the analyzer reports the local `BrowserWindow` as Electron.
Return a conservative loader scope for these calls and add a regression test.
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.SummaryThe PR replaces the separate Webpack getter write scan with
Findings are based on source tracing; no runtime verification was performed. The superseded-PR check could not be completed because GitHub access required authentication. No security finding or applicable repository-rule violation was established. Reviews (1) · Last reviewed commit: "fix(javascript): reject Webpack getters ..." · Reviewed by Greptile |
| (root, kind) => { | ||
| const node = unwrapJavaScriptExpression(root).node; | ||
| return kind === "member" && | ||
| t.isIdentifier(node) && | ||
| loaderBindingIds.has( | ||
| resolveSemanticBindingState(state, node, node.name)?.bindingId ?? | ||
| "", | ||
| ) | ||
| ? [["loader"]] | ||
| : []; |
There was a problem hiding this comment.
Replaced getter still looks trusted
The callback ignores every "opaque-call" write, so the fix still misses apply calls whose arguments are stored in a variable. For example, inserting const args=[n,"n",e=>()=>({BrowserWindow:class{}})];Reflect.set.apply(null,args); before n(100) replaces the getter. The shared collector cannot unpack args, so it requests an "opaque-call" scope. Returning [] leaves only the original getter installation counted, and the analyzer reports the local BrowserWindow as Electron.
Return a conservative loader scope for these calls and add a regression test.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptBundledRequireOrigin.ts
Line: 160-169
Comment:
**Replaced getter still looks trusted**
The callback ignores every `"opaque-call"` write, so the fix still misses `apply` calls whose arguments are stored in a variable. For example, inserting `const args=[n,"n",e=>()=>({BrowserWindow:class{}})];Reflect.set.apply(null,args);` before `n(100)` replaces the getter. The shared collector cannot unpack `args`, so it requests an `"opaque-call"` scope. Returning `[]` leaves only the original getter installation counted, and the analyzer reports the local `BrowserWindow` as Electron.
Return a conservative loader scope for these calls and add a regression test.
---
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!
Summary
Fixes #3315. The Webpack
n.ndefault-export getter proof ran its own write scan. That scan saw only directloader.n = …assignments and fourObject.*methods. A getter replaced throughReflect.setorReflect.defineProperty, removed withdelete, or overwritten by destructuring or an unknown key kept the proof, so BrowserWindow calls behind a non-canonical getter were still attributed to Electron. Separately, anyObject.defineProperty/assignon the loader rejected the proof, even for an unrelated key.Problem and expected behavior
Smallest trigger:
Reflect.set(load, "n", mod => () => ({ BrowserWindow: class {} }))before entry dispatch still yields one Electron BrowserWindow fact. A directload.n = …correctly yields none. The proof must reject every visible write that may selectn, through any write form the analyzer recognizes.Change and scope
canonicalWebpackInteropBindingsnow consumes the shared identity-write owner,collectJavaScriptIdentityWritesSteps, with the module interop's intrinsic-invocation resolution. Ambient global writes already use the same owner. It covers:deleteand destructuring targets;Object.defineProperty/defineProperties/assign/setPrototypeOf;Reflect.set/deleteProperty/defineProperty/setPrototypeOf, including intrinsic aliases andbind/call/apply.n, meaning the key itself, an unknown key, or the whole loader. As before, exactly one canonical assignment, installed before entry dispatch, is still required.Object.*scan is gone.javascriptBootstrapIntegrity.ts) has its own table and cache write checks. Those cover different slots and are not changed here.Contract and boundary impact
javascriptBundledRequireOrigin.ts), using the identity-write owner injavascriptElectronMemberWrites.ts.Expected effects:
Evidence and regression coverage
Tests added to
src/domain/javascript/electronBundledRequireIdentity.test.ts:Reflect.set,Reflect.defineProperty,delete, a destructuring write and an unknown key;Object.defineProperty(n, "d", …), which keeps the attribution.All 6 fail on main.
Base reproduction (executed): the issue's four-variant CLI script through
scripts/rea.mjs analyze-javascript-application, main cf0a38a vs. this branch.Reflect.set)delete load.n)load.n = …)out/). It covers 3,300 files for semantic IR and 3,311 for static facts. Static facts include the Electron inventory.RangeErroron both builds; that is the pre-existing [Bug] Getter-result expansion grows combinatorially and crashes semantic analysis of a shipped bundle #3839.main/index.js, which runs the proof: median of 9 alternating static+semantic runs was 8,925 → 9,054 ms (+1.4%). CPU profiles of single runs: 9,464 → 9,509 ms.agentHostMain.js6,693 → 6,741 ms,extensionHostProcess.js4,457 → 4,526 ms,extensionHostWorkerMain.js3,835 → 3,824 ms).For evidence-bearing changes:
Validation performed
npm run test:local -- src/domain/javascript/electronBundledRequireIdentity.test.ts: 41 passed. On main, the 6 new cases fail.npm run test:local: all passed after rebasing onto cf0a38a.npm run check:fast: typecheck and lint pass. The pre-push hook also passed.Compatibility, safety, and release
Author readiness
Human owner:
Before merge
type(scope): outcome.🤖 Generated with Claude Code