Skip to content

fix(javascript): follow Electron through Webpack bootstrap externals - #2948

Closed
UnknownHacker1 wants to merge 4 commits into
morluto:mainfrom
UnknownHacker1:fix/electron-webpack-externals
Closed

UnknownHacker1 wants to merge 4 commits into
morluto:mainfrom
UnknownHacker1:fix/electron-webpack-externals

Conversation

@UnknownHacker1

@UnknownHacker1 UnknownHacker1 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Refs #2932. if an electron app's main process is bundled with webpack, electron gets loaded through the bundle's module table (45840: e => { e.exports = require("electron") }) and then n(45840) everywhere, never a direct require("electron"). electron identity only knew the direct require so it just saw nothing. BrowserWindow, webPreferences, ipc handlers on the module, all 0.

this lets a loader call count as the require it re-exports, but only when the bootstrap can be proven intact.

Problem and expected behavior

smallest case (normal webpack 5 target: "electron-main" shape):

(()=>{var m={45840:e=>{"use strict";e.exports=require("electron")},100:(e,t,n)=>{"use strict";const s=n(45840);new s.BrowserWindow({webPreferences:{preload:"./preload.js"}});s.ipcMain.handle("get-connections",async()=>[])}},c={};function n(t){var r=c[t];if(void 0!==r)return r.exports;var o=c[t]={exports:{}};return m[t](o,o.exports,n),o.exports}n(100)})();

main gives browser_windows: []. should be one window with preload_path: "./preload.js" plus the get-connections handler, which is what you get now.

Change and scope

new semanticBundledRequireOrigin reuses javascriptBootstrapAt for the bootstrap shape, and proveJavaScriptBootstrapIntegrity checks the rest. n(KEY) only resolves when all of this holds:

  • n is the bootstrap loader (never reassigned) or a factory's 3rd param that the bootstrap passes the loader as
  • the loader's key param is never reassigned and the dispatch runs unconditionally
  • every return in the loader is the dispatched module's .exports (after the dispatch) or the cache entry the loader made for it
  • the module object is a plain literal and only reaches the dispatch, .exports reads and writes to other members
  • the cache starts as {}
  • the table only has literal keys and is only touched by the dispatch or the runtime's n.m = table exposure. same for the cache with n.c. n.m/n.c can only be assigned or indexed, a literal key write through them drops that slot, and writing into an entry drops the proof
  • the factory at KEY is a plain function (not generator/async/getter, no duplicate params) whose whole body is module.exports = require("x")

only electron identity uses it (rootExport and bindingOrigin). other semanticRequireOrigin users are unchanged. the member chain walk moved into semanticMemberChain so both resolvers share it.

not in here:

  • the n.n() default interop getter form (a = n.n(n(45840)); a().ipcMain). separate follow up
  • dynamic key writes through n.m[k] are left alone. thats chunk install adding its own ids, refusing those would turn this off for pretty much every chunked bundle

Contract and boundary impact

  • Semantic owner and earliest changed stage: electron identity in indexJavaScriptElectronIdentitySteps. bootstrap shape still owned by javascriptBootstrapAt

  • Contribution scope fit and linked maintainer decision: not applicable, static analysis fix

  • CLI and MCP/tool-catalog contract: none, same fields just more findings

  • Provider, bridge, target-format, or platform compatibility: none

  • Evidence, artifact, provenance, or reconstruction contract: calls through a proven loader are direct observations now. one existing test that reached electron through load(2) gets no resolution_basis instead of "wrapper-substitution" (same api key, members, world). thats what the same call through require("electron") gives too

  • Target selection, authority, upstream behavior, and cleanup details: not applicable

  • Generated metadata, package, or installation impact: none

  • 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: electronBundledRequireIdentity.test.ts. 3 positive shapes, 4 real world loader shapes that have to keep working (try/finally cache delete like compass, n.c = cache, chunk install through n.m, module.loaded = !0 before the return), and 24 tampered or wrong shapes that have to stay unresolved (replaced loader, generator/async factory, loader returning something else, table slot replaced directly / through an alias / through n.m, planted cache entry, computed table keys, shadowed require, etc). electronWrappedCallPaths.test.ts has the one updated expectation above

  • Base reproduction: the positive cases fail on main. the tamper cases fail on the earlier pushes of this PR and pass now

  • fixture repo with a one command repro: https://github.com/UnknownHacker1/rea-groundtruth (python scripts/run_repro.py <rea>)

    variant     windows  handlers  channels  verdict
    plain             1         1         1  ok
    namespace         1         1         1  ok
    webpack           1         1         1  ok      (main: 0 0 0)
    interop           0         0         0  MISSED  (n.n form, follow up)
    
  • real apps, installed windows builds, --integrity-policy record-and-continue, same base commit with and without this:

    main this PR
    MongoDB Compass 1.43.4, browser_windows 0 1
    MongoDB Compass 1.43.4, ipc.operations 26 31
    Compass normalized result size 205.9 MB 206.1 MB
  • Discord is unresolved on purpose: it ships require-in-the-middle, which reads the whole module cache through __webpack_require__.c and writes into entries with runtime keys, so what n(91288) returns cant be proven

  • Remaining proof gaps:

    • compass still has explicit_web_preferences: 0 because its window options are built before the call (new s.BrowserWindow(u)), separate thing
    • the older wrapper-substitution path on main still reports ipc for a lot of the tampered shapes above. thats not from this PR so i didnt touch it, the tests only check that nothing direct comes out of the new path
  • 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 -- <all 57 files in src/domain/javascript/*.test.ts>: 1313 passed
  • npx tsc --noEmit: pass
  • npm run lint: 0 errors, no warnings in touched files
  • npm run verify:test-discovery: all test files discovered once
  • pre-commit and pre-push hooks pass
  • npm run build then node scripts/rea.mjs analyze-javascript-application ... on the fixtures, Discord and Compass (numbers above). single cold runs, timing looked the same within noise. didnt measure memory or tokens

Compatibility, safety, and release

  • Breaking changes or migration steps: none
  • Real Hopper/Ghidra, browser, or OS coverage: windows 11 x64, node 22.22.3 (in the engines range, not the pinned 24.18.0). source checkout used the published 6.4.0 native/windows/build, not committed. no native provider involved
  • Package or release metadata impact: none
  • Security, privacy, process, or containment review: static parsing only, nothing gets executed

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.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issue remains from this review.

Summary

Follows Electron imports through proven Webpack loaders.

  • Electron analysis now follows proven Webpack externals.

No new actionable issues were found. The numbered previous finding is fixed. The security review found no new security issue. Local history showed no superseding change; repository-wide supersession was not established.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["Electron use through n(KEY)"] --> B["Recognize Webpack bootstrap"]
  B --> C["Check loader, table, and cache"]
  C --> D["Exclude replaced slots"]
  D --> E["Check factory only re-exports require"]
  E --> F["Assign Electron identity"]
Loading

Reviews (6) · Last reviewed commit: "fix(javascript): require a dispatched re..." · Reviewed by Greptile

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e1c408a391

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

loaderBindingIds.add(bindingId);
}
const key = modulePropertyName(property);
const specifier = externalSpecifier(factory, state);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Invalidate rewritten bootstrap module slots

When a recognized table is later changed through an alias—e.g. const alias = modules; alias[45840] = fake or delete alias[45840]—this still records the factory from the initializer, although it is no longer the slot dispatched by the loader. JavaScriptSymbolicBindings.#invalidateBootstrapTable already makes these writes unknown, but direct Electron identity bypasses that invalidation, so a consumer can now produce bogus BrowserWindow/IPC findings; consult visible slot mutations before adding the specifier.

AGENTS.md reference: AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

call: t.CallExpression,
state: JavaScriptSemanticAnalysisState,
): BootstrapExternals | null => {
const bootstrap = javascriptBootstrapAt(call, state);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Require the loader to return dispatched exports

javascriptBootstrapAt proves only that a loader body contains a matching table[id](module, module.exports, loader) dispatch; it does not prove that the loader returns those exports. For an otherwise matching IIFE whose loader invokes the external factory and then return fake, this treats the loader as a require origin anyway, so load(45840).BrowserWindow is attributed to Electron even though its runtime receiver is fake. Require a synchronous return/cache relation to the dispatched module exports before exposing this origin.

AGENTS.md reference: AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

Comment on lines +145 to +149
factory: t.FunctionExpression | t.ArrowFunctionExpression | t.ObjectMethod,
state: JavaScriptSemanticAnalysisState,
): string | undefined => {
const moduleParameter = factory.params[0];
if (!t.isIdentifier(moduleParameter)) return undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject non-eager external module factories

externalSpecifier assumes that any factory node with this body executes it when the dispatch calls the table slot. A valid object-literal entry such as 45840: function* (module) { module.exports = require("electron") } only creates a generator, leaving module.exports unchanged, while a setter ObjectMethod is not callable at all; both shapes can reach this check and assign Electron identity to consumers. Restrict accepted entries to ordinary, non-generator callable factories before inspecting the assignment.

AGENTS.md reference: AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

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-15T07:00:12.264625Z 800ac03 New commits
ℹ️ 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.

@morluto
morluto force-pushed the fix/electron-webpack-externals branch from e1c408a to 039e70e Compare October 13, 2026 18:05

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 039e70eafe

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const initializer = semanticStableInitializer(binding, state);
if (initializer === undefined) return undefined;
const origin = semanticRequireOrigin(initializer.node, state)?.origin;
const origin = electronRequireOrigin(initializer.node, state)?.origin;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Propagate bundled origins through stable aliases

When a proven loader result crosses even one stable alias, for example const loaded = n(45840); const electron = loaded; new electron.BrowserWindow({}), this immediate-initializer lookup sees only the identifier loaded and returns no origin. electronExport then falls back to evaluateSemanticProvenance, whose provenanceForExpression still recognizes only semanticRequireOrigin, so BrowserWindow/IPC findings disappear; the same ownership gap affects the existing module-interop paths around bundled loads. Feed the bundled origin into the shared provenance/interop owner rather than recognizing it only at this leaf.

AGENTS.md reference: AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

)
loaderBindingIds.add(bindingId);
}
const key = modulePropertyName(property);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Invalidate externals shadowed by unknown table keys

When a later table property has a nonliteral computed key, such as {45840: external, [externalId]: local} with externalId === 45840, modulePropertyName assigns that property a synthetic marker, so this map leaves the earlier 45840 external intact. At runtime the computed property overwrites that slot before the loader runs, but n(45840) is still attributed to Electron and produces bogus findings. A later unresolved key must leave every earlier slot it could shadow unknown (or be resolved) rather than being treated as a disjoint key.

AGENTS.md reference: AGENTS.md:L21-L21

Useful? React with 👍 / 👎.

@morluto
morluto force-pushed the fix/electron-webpack-externals branch from 039e70e to d22374e Compare October 13, 2026 18:23
@UnknownHacker1
UnknownHacker1 force-pushed the fix/electron-webpack-externals branch from d22374e to 305818b Compare October 13, 2026 18:30
@UnknownHacker1

Copy link
Copy Markdown
Contributor Author

thanks, these were all real. pushed a fix in 305818b (squashed, rebased on the current main):

  • replaced loader: if the bootstrap loader gets reassigned anywhere the whole proof is dropped now, not just the loader binding
  • generator / async / getter factories: only plain functions count as externals
  • loader returning something else: every return in the loader has to be the dispatched module's .exports or the cache entry the loader made for it
  • replaced slots: any table reference other than the dispatch or n.m = table kills the proof, so direct writes and alias writes are out. literal key writes through n.m[...] / n.c[...] drop that slot, and a planted cache entry kills it too
  • computed / unresolved keys in the table: whole table refused

each one has a test in electronBundledRequireIdentity.test.ts. they fail on the first push and pass now. the real world shapes still work (compass style try/finally cache delete, discord style n.c = cache), and discord still goes 0 -> 1 window and 0 -> 14 ipc ops vs main.

two things i left on purpose:

  • dynamic key writes through n.m[k]. thats chunk install adding its own ids, refusing those would basically turn this off for every chunked bundle. can go stricter if you'd rather
  • following the origin through a plain alias (const a = n(45840); const e = a), from the codex note. fair point but id rather do it as a follow up so this stays small

also noticed while testing: the existing wrapper-substitution path on main still reports ipc for most of these tampered shapes (generator external, replaced loader, etc). not from this PR so i didnt touch it, the new tests just make sure nothing direct comes out of the new path. i can open a separate issue for that if its useful

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 305818b2d1

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

)
return null;
const cacheId = keyedSlot(value.left, parameterId, state);
return cacheId === undefined ? null : { cacheId, site: value.left };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject pre-populated module caches

When a bootstrap initializes its cache as c={45840:{exports:local}}, the normal early-cache return yields local and never dispatches the Electron external. moduleCache accepts the later c[t]={...} assignment as sufficient cache proof without checking c's initializer, so n(45840) is still given Electron identity and can produce bogus BrowserWindow or IPC findings.

AGENTS.md reference: AGENTS.md:L21-L21

Useful? React with 👍 / 👎.

Comment on lines +203 to +205
const value = t.isSequenceExpression(argument)
? argument.expressions.at(-1)
: argument;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject exports rewritten after dispatch

When the loader returns m[t](o,o.exports,n),o.exports=local,o.exports, runtime returns local, not the external's exports. Although a direct return fake is now rejected, the new returnsModuleExports implementation provides fresh evidence of the same proof gap because it discards every sequence element except the last, so this rewrite still assigns Electron identity to n(45840).

AGENTS.md reference: AGENTS.md:L21-L21

Useful? React with 👍 / 👎.

const role = id === undefined ? undefined : tracked.get(id);
if (role === undefined) return;
const use: Use = { node, parent, ancestors, shape, loaderIds, state };
if (role === "loader") exposedSlotWrite(use, replacedKeys);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject aliases of exposed module tables

With the supported exposure n.m=m, code can do const a=n.m; a[45840]=local; n(100), replacing the external before its consumer loads it. The direct-table alias case is now rejected, but this revision's role === "loader" branch only calls exposedSlotWrite and never rejects an unrecognized loader-property read, so the alias mutation leaves replacedKeys empty and yields bogus Electron findings.

AGENTS.md reference: AGENTS.md:L21-L21

Useful? React with 👍 / 👎.

Bundled Electron main processes load Electron through a Webpack external
(`45840: e => { e.exports = require("electron") }`) and the bootstrap
loader (`n(45840)`) instead of a direct require, so Electron identity
missed BrowserWindow, IPC and contextBridge calls made on that module.

A loader call now counts as a require origin only when the bootstrap is
proven intact: the loader is never reassigned and returns only the
dispatched module's exports or its own cache entry, the table has only
literal keys and is touched only by the dispatch or the runtime's
loader.m/loader.c exposure, literal-key writes through that exposure
drop their slot, and the external factory is an ordinary function whose
whole body is `module.exports = require(specifier)`.

Refs morluto#2932
@morluto
morluto force-pushed the fix/electron-webpack-externals branch from 305818b to 88bfa85 Compare October 13, 2026 18:38

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 88bfa85deb

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +75 to +76
if (parameterId === undefined || loader.async || loader.generator)
return undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject rewritten bootstrap module keys

When the loader rewrites its module-ID parameter, for example with if (t === 45840) t = 1, this check still accepts m[t](...), while semanticBundledRequireOrigin indexes the caller's original literal 45840. An entry at key 100 can therefore run normally, but its n(45840) dispatches a local module at key 1 while the analyzer attributes Electron's factory at 45840 and emits bogus BrowserWindow/IPC findings; require the key parameter to have a single unmodified binding before accepting the proof.

AGENTS.md reference: AGENTS.md:L21-L21

Useful? React with 👍 / 👎.

Comment on lines +85 to +87
const dispatch = tableDispatch(node, tableId, parameterId, state);
if (dispatch === undefined) return;
dispatches.add(dispatch.table);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Require dispatch on every uncached loader path

The new returns.every check still accepts a dispatch that appears only under a guard, because this traversal records the call without its control-flow context. For example, if (t === 100) m[t](o, o.exports, n); return o.exports lets the entry module run, but n(45840) never invokes the Electron external and returns the initial exports object; calls through that result are nevertheless labeled Electron. Require the dispatch to dominate every non-cache return path, or leave the origin unknown.

AGENTS.md reference: AGENTS.md:L21-L21

Useful? React with 👍 / 👎.

Comment on lines +202 to +205
if (
moduleBinding === undefined ||
target?.bindingId !== moduleBinding.bindingId
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject duplicate module-parameter bindings

For a valid sloppy-mode factory such as function (e, e, n) { e.exports = require("electron") }, the first parameter and the body target resolve to the same semantic binding, so this comparison succeeds. At runtime the duplicate binding contains the second argument (module.exports), so the assignment adds an exports property to that object instead of replacing the loader module's exports; n(45840).BrowserWindow is still attributed to Electron even though it is absent. Require the first parameter's binding to have exactly one parameter definition.

AGENTS.md reference: AGENTS.md:L21-L21

Useful? React with 👍 / 👎.

Comment on lines +160 to +161
const value = initializer.node;
if (t.isObjectExpression(value)) return undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Prove ordinary storage for module exports

Accepting every fresh object literal allows a loader module object to define an exports getter and a setter that discards writes. The external's module.exports = require("electron") then executes without changing the getter's returned local value, while the syntactic return o.exports still passes the proof and consumers are labeled Electron. Reject accessor/prototype-intercepted exports properties unless ordinary writable data-property behavior is proven.

AGENTS.md reference: AGENTS.md:L21-L21

Useful? React with 👍 / 👎.

- the loader's key parameter can't be reassigned, and the dispatch has to
  run unconditionally before any return of the module's exports
- the module object is a plain literal (no accessors, computed keys or
  __proto__) and is only touched by the dispatch, returned exports reads
  and writes to members other than exports
- the cache has to start as an empty literal
- loader.m / loader.c can only be assigned or indexed directly, and
  writing a member of an indexed entry drops the proof
- factories with duplicate parameter names are rejected
@UnknownHacker1

Copy link
Copy Markdown
Contributor Author

second round in 4b7e2d6, all of these were fair:

  • rewritten key (if(t===45840)t=200): the loader's key param has to have a single definition now
  • dispatch behind a guard: the dispatch has to run unconditionally (only sequence / statement / block / try-block parents up to the loader body) and every return of the module's exports has to come after it
  • exports rewritten after dispatch, in the return sequence or as its own statement: the module object can only show up in the dispatch args, in .exports reads after the dispatch, or in writes to other members (so module.loaded = !0 still works)
  • accessor exports: the module object has to be a plain literal, no getters/setters/computed keys/__proto__
  • pre-populated cache: the cache has to start as {}
  • const a = n.m; a[45840] = local: n.m / n.c can only be assigned (the exposure) or indexed directly now. also found while testing that a write into an entry like n.c[id].exports = x slipped through, thats rejected too
  • function (e, e, n): duplicate param names are rejected

tests for each are in the two "tampered" blocks in electronBundledRequireIdentity.test.ts, they all fail on 88bfa85 and pass now.

one honest side effect: discord goes back to unresolved. its bundle ships require-in-the-middle (from its error reporting sdk), which reads the whole module cache through __webpack_require__.c and writes into cache entries with runtime keys (__webpack_require__.c[filename][this._kRitmExports] = exports). thats literally a tool for swapping module exports at runtime, so i dont think rea should claim to know what n(91288) returns there. compass still resolves the same as before (0 -> 1 window, 26 -> 31 ipc ops vs main). updated the numbers in the description

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4b7e2d601a

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +125 to +127
return returns.every((argument) =>
returnsModuleExports(argument, shape, state),
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Require a nonempty set of loader returns

Fresh evidence after adding return validation is that returns.every(...) is vacuously true for a loader with no return. For function n(t){var o={exports:{}};m[t](o,o.exports,n)}, entry modules execute, but n(45840) evaluates to undefined; bindingOrigin nevertheless assigns Electron identity to that result and can report calls on it. Require at least one proven return in addition to validating each return.

AGENTS.md reference: AGENTS.md:L21-L21

Useful? React with 👍 / 👎.

Comment on lines +202 to +206
return (
binding?.definitions.length === 1 &&
initializer?.projection.length === 0 &&
t.isObjectExpression(initializer.node) &&
initializer.node.properties.length === 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject caches mutated outside the bootstrap

Fresh evidence after adding startsEmpty is that it trusts an empty initializer without proving the cache is owned by the bootstrap. In var c={}; c[45840]={exports:local}; (()=>{/* loader closes over c */})(), the member write does not add a binding definition and lies outside the call subtree scanned later, so this function returns true and the cache hit is mislabeled as the external. Require the cache declaration and references to be contained by the bootstrap, or incorporate out-of-subtree member mutations.

AGENTS.md reference: AGENTS.md:L21-L21

Useful? React with 👍 / 👎.

Comment on lines +421 to +423
if (role !== "loader") contained = containedUse(role, use);
else if (exposedTableUse(use) === "escaped") contained = false;
else exposedSlotWrite(use, replacedKeys);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject escaped loader aliases

The loader branch treats every use other than a recognized .m/.c escape as safe. Thus n.m=m; mutate(n); n(100), where mutate(x) writes x.m[45840]=local, leaves both the loader argument and the alias's mutation untracked and still attributes the consumer to Electron. Reject or track loader values that are passed, stored, or returned rather than silently accepting them.

AGENTS.md reference: AGENTS.md:L21-L21

Useful? React with 👍 / 👎.

((t.isAssignmentExpression(target) && target.left === member) ||
t.isUpdateExpression(target) ||
t.isUnaryExpression(target, { operator: "delete" }));
return entryWritten ? "escaped" : "contained";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject aliases of indexed cache entries

Fresh evidence after the whole-table alias fix is that an indexed entry can still escape: with n.c=c; n(45840); const entry=n.c[45840]; entry.exports=local; n(100), this branch calls the initializer contained, and the later write contains no tracked loader or cache identifier. The consumer's n(45840) therefore returns local, but the proof still assigns Electron identity and can emit bogus findings; treat stored, returned, or passed entries as escaped.

AGENTS.md reference: AGENTS.md:L21-L21

Useful? React with 👍 / 👎.

Comment on lines +517 to +520
const key = slot.computed
? argumentValue(slot.property)
: semanticStaticPropertyKey(slot.property, false);
if (key !== undefined && key !== null) replacedKeys.add(key);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Invalidate externals after unresolved slot writes

Fresh evidence after computed initializer keys were rejected is that post-initialization writes through the exposure still drop an unresolved key. For const id=45840; n.m=m; n.m[id]=local; n(100), argumentValue(id) is undefined, so this code records no replacement even though runtime overwrites external slot 45840; the consumer is then falsely attributed to Electron. Resolve stable keys or invalidate all possibly matching externals on unknown writes.

AGENTS.md reference: AGENTS.md:L21-L21

Useful? React with 👍 / 👎.

@morluto morluto added area: runtime Process capture and runtime observation bug Something isn't working labels Oct 14, 2026
morluto added a commit that referenced this pull request Oct 14, 2026
Track module writes and escapes at their owner, preserve capture and reassignment ordering, and share CommonJS/default namespace identity without erasing parent-slot changes. Carry write sites into ambient alias resolution and use parsed write targets across consumers. Deduplicate returned-reference work with cycle context; retain unchanged temporal selection identity so provenance memoization stays effective.

Reviewed fixes include #2041, #2465, #2830, #2881, and #2948. Remove superseded mutation representations and the ineffective per-markValue dedup layer.

Validation: 380 focused JavaScript tests passed under a 384 MiB heap cap, including the previously aborting 30-level/128-call alias regression. Six public CLI/MCP builtin tests passed. Exact pdf.js completed-workflow performance remains unmeasured.
…t keys

- the loader must return the dispatched module's exports somewhere; a
  cache-only early return is not enough, since a first load would fall
  off the end and yield undefined
- a slot write through a constant key (`const id = 45840; n.m[id] = x`)
  resolves to the declared slot and drops it
@UnknownHacker1

Copy link
Copy Markdown
Contributor Author

pushed two more from the latest codex round:

  • loader with no return: the loader now has to actually return the dispatched module's .exports somewhere, not just pass every return check (a cache-only early return isnt enough)
  • const id = 45840; n.m[id] = local: slot writes through a constant key resolve to the declared slot and drop it

@morluto question on where you want the bar for this one. the remaining codex findings are things like an outside function mutating the loader (mutate(n)), cache entries aliased into a variable, or a cache poisoned in the outer scope before the bootstrap runs. closing those properly means real escape analysis, and the simple version (refuse if the loader or an entry gets passed or stored anywhere) would also refuse normal bundles, since webpack passes the loader around all the time (n.bind(n, id) for lazy chunks, etc). on compass that would take it back to 0.

so i see two options:

  1. keep it at this level: closed against everything the bundler itself emits plus the obvious tampering, document that hand-written adversarial bundles can still fool it (same as the existing wrapper-substitution path does today)
  2. go fully sound and accept it mostly turns off on real apps

im leaning 1 but its your call, happy to do either

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

# Conflicts:
#	src/domain/javascript/electronBundledRequireIdentity.test.ts
#	src/domain/javascript/electronWrappedCallPaths.test.ts
#	src/domain/javascript/javascriptBootstrapIntegrity.ts
#	src/domain/javascript/javascriptBundledRequireOrigin.ts
#	src/domain/javascript/javascriptSemanticAnalysis.ts
#	src/domain/javascript/javascriptSemanticRequireOrigin.ts
@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Merged latest main into this branch to resolve conflicts in six files. No rebase or force-push was used. Main already includes this PR. Commit 04672f2 ("fix(javascript): preserve builtin identity and share alias traversal") lists #2948 among its reviewed fixes, and main has hardened the code since (6e34430, #3860). Every conflicted file takes main's version, and this branch no longer differs from main, so maintainers can close it as incorporated. Validation: main's electronBundledRequireIdentity and electronWrappedCallPaths tests pass on the merged tree, and typecheck and lint pass via the pre-push hook.

@morluto

morluto commented Oct 18, 2026

Copy link
Copy Markdown
Owner

Thanks @UnknownHacker1. Closing this PR as superseded by 04672f2b9 on main.

The current PR head has no remaining diff from its merge base with main.

This is an unmerged closure: it does not label this PR as merged or remove contributor history/credit. The decision uses the current source diff and existing validation record; no new local test or provider run is claimed.

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

Labels

area: runtime Process capture and runtime observation bug Something isn't working provider: electron Analysis provider / engine: electron

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants