Skip to content

fix(electron): resolve const object and function bindings in contextBridge exposures - #9503

Closed
saariuslystoned wants to merge 19 commits into
morluto:mainfrom
saariuslystoned:fix/electron-contextbridge-const-bindings
Closed

saariuslystoned wants to merge 19 commits into
morluto:mainfrom
saariuslystoned:fix/electron-contextbridge-const-bindings

Conversation

@saariuslystoned

@saariuslystoned saariuslystoned commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Recover Electron preload contextBridge.exposeInMainWorld and contextBridge.exposeInIsolatedWorld API shapes and IPC forwarding paths when the exposed API argument is hoisted into an immutable const or function binding, wrapped in an unmodified intrinsic Object.freeze(...) or TypeScript/parenthesized expression wrapper, composed from nested const sub-objects, or exposed directly as a callable function.

Previously, inspectContextBridge inspected call.arguments inline during the initial AST walk without consulting JavaScriptBindingIndex, and collectContextBridgeMembers degraded every non-inline ObjectExpression argument to { status: "dynamic", members: [], unknown: 1 }. Real-world bundled Electron preload scripts (esbuild, Rollup, Rolldown, Vite, Webpack) routinely hoist API objects into const bindings, wrap them in Object.freeze(...), or expose single functions directly, leaving exposed_api_members empty and missing preload-to-IPC forwarding paths.

No existing issue is linked; this is a standalone Electron static-analysis accuracy fix discovered while auditing preload boundary reconstruction.

Problem and expected behavior

Smallest triggers on base:

  1. Hoisted const / Object.freeze / nested const preload exposure:

    const { contextBridge, ipcRenderer } = require("electron");
    const sub = { notify: (msg) => ipcRenderer.send("items:notify", msg) };
    const api = Object.freeze({ nested: sub });
    contextBridge.exposeInMainWorld("DesktopApi", api);

    Base behavior: api_status: "dynamic", members: [], unknown_members: 1 (violating parity with finishElectronBrowserWindowsSteps, which already defers BrowserWindow options and resolves proven immutable const initializers through JavaScriptBindingIndex).
    Expected behavior: api_status: "object-literal", members: ["nested", "nested.notify"], unknown_members: 0, resolution_sources recording the substituted AST initializer ranges, and candidate bridge-member IPC call paths emitted.

  2. Direct callable exposure:

    import { contextBridge, ipcRenderer } from "electron";
    const uploadItem = async (payload: unknown) => ipcRenderer.invoke("items:upload", payload);
    contextBridge.exposeInMainWorld("uploadItem", uploadItem);

    Base behavior: api_status: "dynamic", members: [], unknown_members: 1, and no call_paths entry for ESM Electron imports or direct function exposures.
    Expected behavior: api_status: "function", members: [], unknown_members: 0, and a bridge-member call path (entry: "uploadItem", entry_path: ["uploadItem"], channel: "items:upload", terminal: "electron.ipcRenderer.invoke").

Change and scope

  • Deferred semantic resolution (electronStaticContextBridge.ts, electronStaticAnalysisBrowser.ts, javascriptStaticAnalysis.ts):
    • inspectContextBridge defers contextBridge.exposeInMainWorld / exposeInIsolatedWorld calls whose API expression (or nested object property up to contextBridgeMemberPathDepth) contains an Identifier or call wrapper into pendingContextBridgeApis, then resolves them in finishElectronContextBridgesSteps via JavaScriptBindingIndex and indexMemberMutationFactsSteps() before collectElectronWrappedCallPathsSteps runs.
    • Resolves Identifier references (root and nested object properties) only when bound to a single proven non-rebindable const or FunctionDeclaration initializer with a definite initializer at the read site (immutableLexicalInitializerAtRead) and !index.referenceMayHaveChangedAt(site, ref) (rejecting let/var, reassignments, prior/uncertain property mutations, escapes, TDZ reads, parameters, shadowed bindings, classic-script ambient global function overwrites, and cyclic object/binding references).
  • Sound Object.freeze handling (javascriptSemanticObjectFreeze.ts, javascriptSemanticMemberMutations.ts):
    • Unwraps unmodified global Object.freeze(expr) only when global Object.freeze identity is intact and unescaped.
    • Skips call-argument escape in collectSemanticMemberMutationsSteps only when Object.freeze targets an ordinary object literal or function (isIntrinsicOrdinaryObjectFreezeCall, excluding Proxy/TypedArray/opaque targets), while forwarding member-mutation paths through unwrapUnmodifiedObjectFreezeArgument in branchReferenceValues so shallow Object.freeze({ sub }) still marks api.sub.extra = ... or mutate(api) as unsound for nested sub.
  • Direct callable exposures and wrapper call paths (electronStaticAnalysisValues.ts, electronWrappedCallPaths.ts, javascriptSymbolicBindings.ts):
    • Adds "function" to ElectronContextBridgeFinding["api_status"] (members: [], unknown_members: 0) for inline and constant-resolved functions, and enforces a shared per-file ContextBridgeMemberBudget (4,096 visits, 131,072 UTF-8 bytes checked before path-string allocation) across inline, deferred, and symbolic inventories so shared sub-object DAGs stay bounded and mark truncated branches unknown.
    • Traces callable contextBridge exposures in collectElectronWrappedCallPathsSteps (entry_kind: "bridge-member", entry_path: [apiKey]), unwraps unmodified Object.freeze(...) in JavaScriptSymbolicBindings, and resolves intact ESM import bindings from "electron" via JavaScriptElectronIdentity so ESM preload scripts participate in call-path tracing and IPC pairing.
    • Preserves existing symbolic wrapper substitution (expose(key, value), bag.api, { ...shared }, and isolated world_id constants) while retaining resolved api_status ("object-literal" / "function") and resolution_sources on complete direct API shapes.
  • Evidence & provenance distinction (ElectronBoundaryGraphWindows.ts):
    • Inline literal exposures retain astObservationEvidence (operation: "observe-context-bridge-api", no resolution_sources).
    • Binding- or Object.freeze-substituted exposures project resolution_sources and staticInferenceEvidence (operation: "resolve-context-bridge-constant-api").
  • Intentionally out of scope:
    • Cross-module preload object reconstruction, general Object.assign folding, or dynamic runtime property synthesis.

Follow the contribution scope.

Contract and boundary impact

  • Semantic owner and earliest changed stage:
    src/domain/javascript/ (javascriptSemanticObjectFreeze.ts, javascriptSemanticMemberMutations.ts, electronStaticContextBridge.ts, electronStaticAnalysisValues.ts, electronStaticAnalysisBrowser.ts, javascriptSymbolicBindings.ts, electronWrappedCallPaths.ts), consumed by src/javascript/analysis/JavaScriptAnalysisWorkerSchemas.ts and src/application/javascript/ElectronBoundaryGraphWindows.ts.
  • Contribution scope fit and linked maintainer decision:
    Not applicable — ordinary static-analysis accuracy fix within existing JavaScript/Electron read-only static reconstruction boundaries.
  • CLI and MCP/tool-catalog contract:
    No CLI flag or MCP tool-input schema changes. JavaScript static analysis and application-graph context-bridge-api observations may report api_status: "function" and resolution_sources when constant/frozen bindings are resolved.
  • Provider, bridge, target-format, or platform compatibility:
    Platform-neutral Babel AST and semantic analysis over CommonJS, ESM, and TypeScript-annotated Electron preload sources.
  • Evidence, artifact, provenance, or reconstruction contract:
    Direct inline AST observations remain state: "observed" (authority: "ast-static-analysis", operation: "observe-context-bridge-api"), whereas constant-binding and Object.freeze substitutions emit state: "inferred" (authority: "static-relationship-inference", operation: "resolve-context-bridge-constant-api") with resolution_sources ranges. Uncertain or mutable bindings remain api_status: "dynamic" with explicit unknown_members counts.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable):
    Not applicable — pure static AST analysis; never executes target JavaScript.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs and skills/; edit authored instructions in .agents/skills/reverse-engineer-anything/ and never commit build outputs):
    None; docs/guides/javascript/javascript-artifact-reconstruction.md updated to document const/Object.freeze/callable contextBridge resolution.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • 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 (executed):
    • src/domain/javascript/electronContextBridgeBindings.test.ts: hoisted const, Object.freeze, pre-frozen const, nested const DAGs, as const / satisfies / ! wrappers in exposeInMainWorld and exposeInIsolatedWorld; inline, const, Object.freeze, and FunctionDeclaration callable exposures with ESM/CJS IPC call_paths; nested member expressions (bag.sub) via symbolic fallback, unknown nested leaves, and duplicate-key overwrite order; source-order preservation; soundness negative cases (let, var, reassigned binding, property mutation, escaped binding, Object.assign mutation, mutated callable, shadowed/overwritten Object.freeze, cyclic const aliases, self-referential/mutually recursive const objects, shallow Object.freeze nested mutations/escapes, TDZ read-before-init, uninvoked parameters, shadowed bindings, classic-script global function overwrite, unknown external identifier); shared expose(key, value) helper regression.
    • src/application/javascript/JavaScriptArtifactGraphElectronCoverage.test.ts: end-to-end application graph test verifying context_bridge_apis, exposed_api_members, paired_renderer_transmissions, join-electron-wrapper-paths (invokes and sends edges), resolution_sources, and observe-context-bridge-api vs resolve-context-bridge-constant-api evidence separation.
    • src/javascript/analysis/JavaScriptAnalysisWorkerSchemas.test.ts: worker transfer schema round-trip validation for api_status: "function" and resolution_sources.
  • Base reproduction or other evidence:
    Executed against synthetic fixtures above; on base 88cf49803, hoisted const, Object.freeze, and callable contextBridge exposures fail with api_status: "dynamic", members: [], unknown_members: 1, and missing ESM call_paths.
  • User-visible CLI/MCP output (if applicable):
    Representative context-bridge-api node observation properties in JavaScriptApplicationGraph:
    {
      "api_status": "object-literal",
      "members": ["nested", "nested.notify"],
      "unknown_members": 0,
      "resolution_sources": [
        { "kind": "source-range", "source": "preload.js", "start": { "line": 3, "column": 36 }, "end": { "line": 3, "column": 54 } },
        { "kind": "source-range", "source": "preload.js", "start": { "line": 2, "column": 18 }, "end": { "line": 2, "column": 73 } }
      ]
    }
  • Remaining proof gaps:
    Cross-module preload object imports remain conservative (api_status: "dynamic") by design.

Boundary regressions covered:

  • Worker IPC transfer schema compatibility (JavaScriptAnalysisWorkerSchemas.test.ts) for api_status: "function" and resolution_sources.
  • Application-graph reconstruction provenance boundary (JavaScriptArtifactGraphElectronCoverage.test.ts) keeping ast-static-analysis (observed) distinct from static-relationship-inference (inferred) and joining preload wrapper paths to ipcMain handlers.

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

  • npx oxfmt . && npx oxfmt --check . — passed (All matched files use the correct format across 7,234 files)
  • npm run build:cached — passed (metadata:check, compile, artifacts:skills: 3/3 tasks succeeded)
  • npm run check:fast — passed (typecheck and lint + verify:module-boundaries: 2/2 tasks succeeded, 0 errors)
  • npm run verify:architecture-guards && npm run verify:test-discovery && npm run scan:todos && npm run metadata:check && npm run mcp-catalog:check && npm run docs:check — passed (2,550 source files, 3,197 test files discovered once, 0 tech-debt markers, package/MCP metadata and 9/9 docs checks clean)
  • npm run jscpd && npm run knip && npm run knip:production && npm run lint:typed — passed (3.45% duplicated lines, Knip clean, lint:typed 0 errors)
  • Cross-Node Vitest matrix (v22.23.4, v24.22.1, v26.13.0) across electronContextBridgeBindings.test.ts, JavaScriptArtifactGraphElectronCoverage.test.ts, JavaScriptAnalysisWorkerSchemas.test.ts, electronStaticAnalysisOptions.test.ts, electronStaticAnalysisIdentity.test.ts, electronModuleInterop.test.ts, and electronWrappedCallPaths.test.ts — passed (all 7 suites passed on each runtime, including 6,000-alias and 125,000-member stress cases)
  • End-to-end CLI (rea analyze-javascript-application --format json) and stdio MCP (analyze_javascript_application) parity probe on hoisted const + Object.freeze + nested const preload fixture — passed (context_bridge_apis: 1, exposed_api_members: 3, ipc.paired_renderer_transmissions: 1)

Compatibility, safety, and release

  • Breaking changes or migration steps:
    None. ElectronContextBridgeFinding.api_status adds "function" alongside "object-literal" | "dynamic" | "missing" and optional resolution_sources ranges; exposed_api_members continues counting dotted object members (0 for direct bare callables).
  • Real Hopper/Ghidra, browser, or OS coverage:
    Not applicable — pure TypeScript static JavaScript/Electron AST and semantic analysis.
  • Package or release metadata impact:
    None.
  • Security, privacy, process, or containment review:
    Read-only static analysis over parsed ASTs; no target code execution, process attachment, or network access. Soundness invariants keep mutable, escaped, shadowed, or overwritten bindings "dynamic" rather than over-claiming exposed API surfaces.

Author readiness

Human owner: @saariuslystoned

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T00:29:31.278927Z 6b3f5ab 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.

@greptile-apps

greptile-apps Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[High impact] The changes reach shared JavaScript analysis as well as Electron preload reconstruction.

The PR should not merge until callback scope handling stops hiding real Electron method overwrites.

Findings

  1. P1 Blocks hide method overwrites ▶
Fix with agent prompt
### Issue 1
src/domain/javascript/javascriptSemanticAnalysis.ts:4438-4444
`evaluateGroupByStatements` copies the environment for every block, but `var` belongs to the whole function. For example:

```js
Object.groupBy([ipcRenderer], () => {
  var key = "skip";
  { var key = "all"; }
  return key;
}).all[0].invoke = replacement;
```

This replaces the real `ipcRenderer.invoke`. The evaluator instead puts the item under `"skip"`, so the caller drops the `"all"` write without taking its conservative fallback. Later calls can still appear as genuine IPC.

Use binding-aware evaluation, or fall back when the callback contains declarations or effects this evaluator cannot safely model.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Recovers constant-bound, frozen, nested, and callable Electron contextBridge APIs.

  • Electron preload analysis follows stable API bindings into nested objects.
  • Exposed preload functions now produce paths to their Electron IPC calls.
  • Mechanical import and fixture edits leave behavior unchanged.

Review was source-based; no runtime reproduction was performed. Supersession could not be checked because GitHub authentication was unavailable.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Parsed exposure] --> B[Direct shape collection]
  A --> C[Deferred binding and mutation checks]
  C --> D[Resolved shape and source ranges]
  B --> E[Symbolic fallback and callable tracing]
  D --> E
  E --> F[Worker transfer]
  F --> G[Boundary graph and IPC paths]
Loading

Reviews (11) · Last reviewed commit: "fix(javascript): scope groupBy blocks an..." · 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: ff01d982a1

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

@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: 8bba9dbf8f

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

@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: ccd5ed3a89

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

@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: 370d0d3bb1

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

@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: fb60a208af

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

…on snapshots, and track frozen Electron writes

@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: 1c6c71f757

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

@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: 58f06ebef1

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

@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: efb1e2305d

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

@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: a23f2d653e

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

@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: 8c538e041a

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

@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: a31ccf9180

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

@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: b9bb37f42e

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

@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: 3ad484486d

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

@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: 1d44642ed4

ℹ️ 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 +5730 to +5731
} else if (t.isNewExpression(node)) {
enqueueOpaqueInvocationArguments(node.arguments, current, pending);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve fresh-instance identity for resolved constructors

In a CommonJS preload containing class Box { constructor(ipc) { this.ipc = ipc; } } const local = new Box(ipcRenderer); local.invoke = () => 0;, the assignment changes only the fresh instance. This branch nevertheless treats constructor arguments as possible result identities, attributing the assignment to electron.ipcRenderer.invoke. Consequently, intactExport suppresses subsequent genuine IPC endpoints and bridge forwarding paths that the parent revision retained. Resolve known constructor return/instance facts before applying the opaque argument-alias fallback; storing an argument on an instance does not make the instance that argument.

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

Useful? React with 👍 / 👎.

Comment on lines +4413 to +4414
if (t.isBlockStatement(stmt)) {
const inner = evaluateGroupByStatements(stmt.body, env, ctx, depth + 1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Respect block scope when evaluating groupBy callbacks

For Object.groupBy([{}, ipcRenderer], (_item, i) => { const key = "all"; if (i === 0) { const key = "skip"; } return key; }), both native callback results are "all". The new evaluator instead shares this name-keyed environment across nested blocks, leaking the inner const and producing skip: [0], all: [1]. A subsequent g.all[0].invoke = () => 0 therefore gets attributed to Electron even though it only modifies the first, fresh object, suppressing genuine downstream IPC endpoints. Preserve lexical binding identities/scopes in callback evaluation, or leave the partition unresolved when those facts cannot be established.

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

Useful? React with 👍 / 👎.

ctx.pending.push({
...ctx.current,
node: target,
suffix: ["__proto__", ...ctx.current.suffix],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Separate prototype identity from proto property reads

In a CommonJS preload, const obj = { __proto__: {}, ["__proto__"]: ipcRenderer }; const p = Object.getPrototypeOf(obj); p.invoke = () => 0; modifies the fresh prototype object, not Electron. Translating getPrototypeOf into an ordinary "__proto__" property selection instead follows the unrelated own data property. The write index consequently invalidates electron.ipcRenderer.invoke and removes subsequent genuine IPC endpoints and bridge paths. Preserve an internal prototype-selection fact distinct from user-defined property lookup; the shared branch also affects Reflect.getPrototypeOf.

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

Useful? React with 👍 / 👎.

saariuslystoned and others added 2 commits November 10, 2026 19:17
…tbridge-const-bindings

Keep main's wrapper-depth budget and alias-selection precision, and retain shared contextBridge member budgets and returned-reference frames.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Nested groupBy callback blocks no longer leak const bindings into the outer key. Alias expansion uses semantic precision after main removed the fixed cap, and the contextBridge budget type stays with analysis state so the semantic modules do not form a new import cycle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@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: 6b3f5ab84d

ℹ️ 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 +4003 to +4004
callArgs[1],
new Set<string>(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve own-property shadowing in setPrototypeOf result lookups

For a CommonJS preload using the native intrinsic, const v = Object.setPrototypeOf({ ipc: {} }, { ipc: ipcRenderer }); v.ipc.invoke = () => 0; only changes the fresh own ipc object. Passing an empty shadowed-key set nevertheless adds the prototype's ipcRenderer as a write target, so electronMemberWriteExports records an electron.ipcRenderer.invoke overwrite and intactExport suppresses subsequent genuine IPC endpoints and bridge paths. Resolve the target's effective own properties before following its prototype, as the adjacent Object.create handling already does for descriptor-defined slots.

AGENTS.md reference: AGENTS.md:L27-L27

Useful? React with 👍 / 👎.

Comment on lines +4418 to +4421
const last = expr.expressions.at(-1);
return last === undefined
? undefined
: evaluateGroupByExpression(last, env, ctx, depth + 1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Reject effectful sequence prefixes in groupBy partitioning

For a CommonJS preload with native Object.groupBy, const g = Object.groupBy([{}, ipcRenderer], (_x, i) => (i = 1, i === 0 ? "skip" : "all")); g.all[0].invoke = () => 0; only mutates the first fresh object, because both callback invocations return "all". Evaluating only the final comma operand ignores i = 1 and constructs the exact partition skip: [0], all: [1]; the downstream write is therefore attributed to ipcRenderer.invoke, suppressing genuine endpoints and forwarding paths. Consume the value/effect owner's facts, or leave the partition unresolved when preceding expressions can mutate callback bindings.

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

Useful? React with 👍 / 👎.

@saariuslystoned

Copy link
Copy Markdown
Contributor Author

Closing this. At about 10k lines with findings still open after many review rounds (constructor instance identity, __proto__ handling), it is not converging as one PR. If contextBridge const-binding recovery is still wanted, I'll split out a small, focused fix. ☁️

Comment on lines +4438 to +4444
if (t.isBlockStatement(stmt)) {
const inner = evaluateGroupByStatements(
stmt.body,
new Map(env),
ctx,
depth + 1,
);

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 Blocks hide method overwrites

evaluateGroupByStatements copies the environment for every block, but var belongs to the whole function. For example:

Object.groupBy([ipcRenderer], () => {
  var key = "skip";
  { var key = "all"; }
  return key;
}).all[0].invoke = replacement;

This replaces the real ipcRenderer.invoke. The evaluator instead puts the item under "skip", so the caller drops the "all" write without taking its conservative fallback. Later calls can still appear as genuine IPC.

Use binding-aware evaluation, or fall back when the callback contains declarations or effects this evaluator cannot safely model.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptSemanticAnalysis.ts
Line: 4438-4444

Comment:
**Blocks hide method overwrites**

`evaluateGroupByStatements` copies the environment for every block, but `var` belongs to the whole function. For example:

```js
Object.groupBy([ipcRenderer], () => {
  var key = "skip";
  { var key = "all"; }
  return key;
}).all[0].invoke = replacement;
```

This replaces the real `ipcRenderer.invoke`. The evaluator instead puts the item under `"skip"`, so the caller drops the `"all"` write without taking its conservative fallback. Later calls can still appear as genuine IPC.

Use binding-aware evaluation, or fall back when the callback contains declarations or effects this evaluator cannot safely model.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

@morluto morluto added bug Something isn't working provider: electron Analysis provider / engine: electron labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working provider: electron Analysis provider / engine: electron

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants