Skip to content

fix(javascript): reject Webpack getters replaced through any identity write - #3860

Merged
kaoru0822-kitauji merged 1 commit into
mainfrom
fix/3315-getter-identity-writes
Oct 15, 2026
Merged

kaoru0822-kitauji merged 1 commit into
mainfrom
fix/3315-getter-identity-writes

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Summary

Fixes #3315. The Webpack n.n default-export getter proof ran its own write scan. That scan saw only direct loader.n = … assignments and four Object.* methods. A getter replaced through Reflect.set or Reflect.defineProperty, removed with delete, 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, any Object.defineProperty/assign on 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 direct load.n = … correctly yields none. The proof must reject every visible write that may select n, through any write form the analyzer recognizes.

Change and scope

  • Write owner: canonicalWebpackInteropBindings now 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:
    • assignment, update, delete and destructuring targets;
    • Object.defineProperty/defineProperties/assign/setPrototypeOf;
    • Reflect.set/deleteProperty/defineProperty/setPrototypeOf, including intrinsic aliases and bind/call/apply.
  • Counted writes: a write counts when its path may select 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.
  • Removed: the hand-rolled assignment/Object.* scan is gone.
  • Not included: the bootstrap integrity proof (javascriptBootstrapIntegrity.ts) has its own table and cache write checks. Those cover different slots and are not changed here.

Contract and boundary impact

  • Semantic owner and earliest changed stage: JavaScript bundled-require origin (javascriptBundledRequireOrigin.ts), using the identity-write owner in javascriptElectronMemberWrites.ts.
  • Contribution scope fit and linked maintainer decision: an ordinary fix within existing boundaries, so not applicable.
  • CLI and MCP/tool-catalog contract: no schema change.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: Electron facts behind a replaced or deleted getter are no longer reported as direct observations. A reflective write to an unrelated loader key no longer suppresses them.
  • 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.

Evidence and regression coverage

  • Tests added to src/domain/javascript/electronBundledRequireIdentity.test.ts:

    • getter writes through Reflect.set, Reflect.defineProperty, delete, a destructuring write and an unknown key;
    • a positive case, 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.

Variant main BrowserWindows branch BrowserWindows Evidence bytes (main → branch)
reflective (Reflect.set) 1 0 183,004 → 179,795
deleted (delete load.n) 1 0 169,742 → 166,533
direct (load.n = …) 0 0 175,304 → 175,310
intact 1 1 166,210 → 166,216
  • Real-app comparison (executed): main vs. this branch over every JS file in six corpora (Discord, Notion, Signal, Claude, Tabby and VS Code out/). It covers 3,300 files for semantic IR and 3,311 for static facts. Static facts include the Electron inventory.
  • Timing: the proof adds one identity-write pass per Webpack bootstrap that passes the integrity checks. Proofs are cached per bootstrap call.
    • Notion's Webpack 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.
    • VS Code bundles, 5 alternating runs: within ±1.6% (agentHostMain.js 6,693 → 6,741 ms, extensionHostProcess.js 4,457 → 4,526 ms, extensionHostWorkerMain.js 3,835 → 3,824 ms).
  • Remaining proof gaps:
    • No MCP-adapter run; the CLI and MCP share the static analysis producer.
    • Timings come from one machine.

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

  • npm run test:local -- src/domain/javascript/electronBundledRequireIdentity.test.ts: 41 passed. On main, the 6 new cases fail.
  • 161 JavaScript/domain test files via npm run test:local: all passed after rebasing onto cf0a38a.
  • npm run check:fast: typecheck and lint pass. The pre-push hook also passed.
  • The CLI reproduction, corpus comparisons and timing above.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable (static JavaScript analysis).
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no target interaction. Private app bundles are referenced only by name and path.

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

… 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]>
@kaoru0822-kitauji kaoru0822-kitauji added the track:perf Performance track PRs (issues & perf loop) label Oct 15, 2026
@kaoru0822-kitauji
kaoru0822-kitauji marked this pull request as ready for review October 15, 2026 06:15
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-15T06:15:45.809393Z 62911c5 Draft marked ready
ℹ️ 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] Tightens detection of Webpack loader identity overwrites.

Fix the missed reflective calls with unknown argument lists before merging.

Findings

  1. P1 Replaced getter still looks trusted ▶
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.

Summary

The PR replaces the separate Webpack getter write scan with collectJavaScriptIdentityWritesSteps.

  • Webpack getter calls keep Electron identity only when loader writes preserve n.

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

Comment on lines +160 to +169
(root, kind) => {
const node = unwrapJavaScriptExpression(root).node;
return kind === "member" &&
t.isIdentifier(node) &&
loaderBindingIds.has(
resolveSemanticBindingState(state, node, node.name)?.bindingId ??
"",
)
? [["loader"]]
: [];

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 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!

@kaoru0822-kitauji
kaoru0822-kitauji merged commit 57f3002 into main Oct 15, 2026
33 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the fix/3315-getter-identity-writes branch October 15, 2026 06:25
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working track:perf Performance track PRs (issues & perf loop)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Replaced or deleted Webpack export getters still produce Electron API facts

2 participants