Skip to content

fix(electron): trace IPC channels and bridge keys spelled as exact templates - #9538

Merged
morluto merged 6 commits into
morluto:mainfrom
pedrocormann:ipc-exact-channel-seeds
Nov 26, 2026
Merged

morluto merged 6 commits into
morluto:mainfrom
pedrocormann:ipc-exact-channel-seeds

Conversation

@pedrocormann

@pedrocormann pedrocormann commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Electron call-path tracing starts only at calls whose first argument is an
exact string, then evaluates channels and contextBridge keys symbolically.
Both steps recognized a string only as a StringLiteral node, so a template
without substitutions, such as `app:template`, stayed dynamic there. The
syntax pass already reads that spelling as a literal channel
(electronStaticValue uses readExactJavaScriptLiteral), and the
reconstruction guide states that direct string literals and cooked templates
without substitutions use the same normalization boundary. On this trigger,
electron.ipc has no app:template registration:

const { ipcMain } = require("electron");
function register(channel, handler) { ipcMain.handle(channel, handler); }
register("app:quoted", () => 1);
register(`app:template`, () => 2);

With this change the trace reads exact strings through
readExactJavaScriptLiteral, so the second call registers app:template the
way the first registers app:quoted. Templates with substitutions stay
dynamic.

No issue is linked: the trigger is self-contained, and the failure and the fix
are both shown below.

Problem and expected behavior

Violated invariant: an exact string has one meaning whatever its spelling. On
base (c78c8aed4), an exact template had these effects:

  • A wrapper invocation with an exact template channel is never traced. Its
    registration is missing, and the wrapper's own unresolved site does not get
    invocation_channels: "literal", so renderer sends and invokes beside it
    stay ambiguous instead of pairing.
  • A direct ipcMain.on(`app:copy`, handler) or
    contextBridge.exposeInMainWorld(`desktop`, api) gets no call paths. The
    channel or key itself is already reported by the syntax pass.
  • A contextBridge helper invoked as expose(`one`) beside
    expose("two") reports only the two API: the traced quoted call replaces
    the site's own observation, and the template call is lost.
  • A case `win32`: label loses its selection condition, as a dynamic case
    expression does.

Source: seed in electronWrappedCallPaths.ts checked
t.isStringLiteral(node.arguments[0]). JavaScriptSymbolicBindings#evaluate
had no TemplateLiteral case and returned unsupported TemplateLiteral.
switchCaseContext admitted only string, numeric, boolean, null and BigInt
literal case tests. #8120 describes the seed rule: seeds start only at calls
whose first argument is a string literal. #4511 is a precedent for reading
exact templates without substitutions as exact strings in another producer.

Change and scope

  • electronWrappedCallPaths.ts: seed starts a trace when
    exactStringArgument reads an exact string first argument through
    readExactJavaScriptLiteral. That reader also looks through type-only
    wrappers, which evaluate already removes, so
    register("app:typed" as const, fn) now starts a trace too (tested).
    switchCaseContext accepts an exact template case label. Its predicate text
    is the source label, for example ((process.platform) === (`win32`)).
  • javascriptSymbolicBindings.ts: #evaluate returns the cooked string of an
    exact template through readExactJavaScriptLiteral. A template with
    substitutions still returns unsupported TemplateLiteral. The other literal
    branches are unchanged: sending them through the same reader would also
    change non-finite and signed numeric literals, which is outside this fix.
  • Not included:
  • Overlap with open PRs, source-derived from their diffs and not run: fix(electron): resolve const object and function bindings in contextBridge exposures #9503
    lets an exact template through the same seed check inside a larger
    contextBridge change, but does not change #evaluate, so a wrapper's
    template channel stays unresolved there. feat(javascript): fold constant values and recover Electron boundaries through wrappers #2094 reads exact literals in
    #evaluate inside a broader constant-folding change. Whichever lands second
    has a small textual conflict at the seed check.
  • Docs: no change. The reconstruction guide already describes literal channels
    and literal switch cases, and states that direct string literals and cooked
    templates without substitutions use the same normalization boundary.

Follow the contribution scope.
Unresolved scope, authority, side effects, or required verification block
integration. Link the required maintainer scope decision for new providers or
capabilities involving target execution, injection, mutation, or protection
recovery; ordinary fixes within existing boundaries may state "not applicable".
Draft PRs may leave the scope decision pending and the readiness and merge checklists
unchecked. Maintainers can help resolve open questions.

Scope decision: not applicable; this is a fix within the existing static
analysis boundary.

Contract and boundary impact

  • Semantic owner and earliest changed stage: readExactJavaScriptLiteral in
    javascriptAstValues.ts owns exact-literal reading. The call-path trace in
    electronWrappedCallPaths.ts (seed check and switch labels) and its
    evaluator JavaScriptSymbolicBindings, whose only consumer is that trace,
    now use it instead of testing for StringLiteral. Affected outputs:
    electron.ipc, electron.call_paths, electron.context_bridge_apis, and
    the application graph's IPC channel, handler, call-path and pairing facts
    built from them. No superseded path remains.
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract: no schema or catalog change. For exact
    templates, existing fields gain the facts that quoted strings already
    produce: wrapper-substitution IPC findings, call paths, resolved bridge
    exposures, invocation_channels: "literal" when every wrapper invocation is
    exact, and renderer transmissions that pair.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: the new facts
    carry the same inferred evidence as their quoted-string equivalents. Each
    site's observed syntax observation is unchanged.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

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

Evidence is executed unless marked source-derived.

  • Tests added or updated:

    • src/domain/javascript/electronWrappedCallPaths.test.ts: wrapper channels
      spelled quoted, as an exact template and as "app:typed" as const each
      substitute. When another invocation passes a template with a substitution,
      that call stays dynamic and the wrapper's site keeps no
      invocation_channels (negative case). Call paths start from a direct
      handler channel and a contextBridge key spelled as exact templates. A
      contextBridge helper invoked with an exact template key resolves beside a
      quoted key. An exact template case keeps its selection condition.
    • tests/boundary/cli/electronWrappedCallPaths.test.ts: through the public
      CLI, a wrapper registration on an exact template channel and a
      template-keyed contextBridge exposure give the app:template main
      channel, both bridge call paths, and 2 paired renderer invokes with none
      ambiguous.
  • Base reproduction or other evidence: with the new tests and the base source,
    all 6 new module tests fail (Tests 6 failed | 194 passed (200)), and the
    new CLI test fails against a base build. Abridged:

    × substitutes every exact spelling of a wrapper channel when every invocation is exact
      expected [ [ null, 'channel', …(2) ], …(1) ] to deeply equal [ [ null, 'channel', …(2) ], …(3) ]
      -   "literal"     (invocation_channels of the wrapper's site; received null)
      -   "app:template", "app:typed" rows (missing)
    × traces call paths from a direct handler's channel spelled as an exact template
      expected [] to deep equally contain ObjectContaining{…}
    × binds an exact template key like a quoted key
      expected [ { api_key: 'two', …(4) } ] to deeply equal [ { api_key: 'one', …(4) }, …(1) ]
    × retains switch selection for an exact template case
      expected [] to deeply equal [ ObjectContaining{…} ]
    × pairs renderer invokes with wrapper registrations on exact template channels through the public CLI
      expected [ 'app:quoted inferred', …(1) ] to deeply equal [ 'app:quoted inferred', …(2) ]
    
  • User-visible CLI/MCP output (if applicable): the fixture below, analyzed with
    rea analyze-javascript-application <dir> --format json after
    npm run build:cached on base and on this branch. Rows are graph nodes
    selected with the jq filter below, then sort -u; the last line of each
    block is from summary.ipc.

    # base (c78c8aed4)
    main.js:3 ipc-channel main handle "app:quoted" inferred
    main.js:3 ipc-channel main handle null observed
    main.js:3 ipc-handler main handle null observed
    main.js:4 ipc-handler main handle "app:quoted" inferred
    preload.js:2 context-bridge-api desktop members=quoted,template unknown=0 observed
    preload.js:3 ipc-channel renderer invoke "app:quoted" observed
    preload.js:4 ipc-channel renderer invoke "app:template" observed
    paired_renderer_transmissions=0 ambiguous_renderer_transmissions=2
    # this branch
    main.js:3 ipc-channel main handle "app:quoted" inferred
    main.js:3 ipc-channel main handle "app:template" inferred
    main.js:3 ipc-channel main handle null observed
    main.js:3 ipc-handler main handle null observed
    main.js:4 ipc-handler main handle "app:quoted" inferred
    main.js:5 ipc-handler main handle "app:template" inferred
    preload.js:2 context-bridge-api desktop members=quoted,template unknown=0 observed
    preload.js:3 ipc-channel renderer invoke "app:quoted" observed
    preload.js:3 javascript-expression desktop.quoted -> "app:quoted" inferred
    preload.js:4 ipc-channel renderer invoke "app:template" observed
    preload.js:4 javascript-expression desktop.template -> "app:template" inferred
    paired_renderer_transmissions=2 ambiguous_renderer_transmissions=0
    
    Fixture and jq filter

    package.json: {"name":"ipc-templates","version":"1.0.0","main":"main.js"}

    main.js:

    "use strict";
    const { ipcMain } = require("electron");
    function register(channel, handler) { ipcMain.handle(channel, handler); }
    register("app:quoted", () => 1);
    register(`app:template`, () => 2);

    preload.js:

    const { contextBridge, ipcRenderer } = require("electron");
    contextBridge.exposeInMainWorld(`desktop`, {
      quoted: () => ipcRenderer.invoke("app:quoted"),
      template: () => ipcRenderer.invoke("app:template"),
    });
    .normalized_result.graph.nodes[] | .kind as $k | .observations[] as $o | $o.properties as $p
    | select($k == "ipc-channel" or $k == "ipc-handler" or $k == "context-bridge-api"
        or ($k == "javascript-expression" and $p.entry != null and $p.step_kind == "terminal"))
    | "\($o.evidence.location.value.source):\($o.evidence.location.value.start.line) \($k) "
      + (if $k == "context-bridge-api" then "\($p.api_key) members=\($p.members | join(",")) unknown=\($p.unknown_members)"
         elif $k == "javascript-expression" then "\($p.entry) -> \($p.channel | tojson)"
         else "\($p.side) \($p.mode) \($p.channel | tojson)" end)
      + " \($o.evidence.state)"
  • Remaining proof gaps:

    • The CLI test covers the CLI surface only; stdio MCP was not run for this
      case. The rest of tests/boundary/cli/electronWrappedCallPaths.test.ts ran
      only on the merged tree (27 passed); the other boundary suites were not run.
    • No packaged Electron application was analyzed, and how often shipped
      bundles spell channels as exact templates was not measured.
    • Performance was not measured. The seed check now admits calls whose first
      argument is an exact template or a type-wrapped string, which is the work
      the trace already does for the quoted spelling of the same source; the
      existing visit budget still bounds it.

For boundary fixes, identify the applicable boundary regressions
and lifecycle regressions
covered by the evidence above, and explain relevant gaps.

Boundary regressions covered: raw identity and normalization. Spellings that
normalize to one exact string give the same facts, and a template with a
substitution stays dynamic instead of becoming a guessed value. No resource
ownership or lifecycle stage changes, so no lifecycle regression applies.

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

Run on macOS arm64 with Node 24.22.2 (.nvmrc pins 24.22.1) and dependencies
installed from the unchanged lockfile.

  • npm run test:local -- src/domain/javascript/electronWrappedCallPaths.test.ts src/domain/javascript/javascriptSymbolicBindings.test.ts
    — Test Files 2 passed (2), Tests 289 passed (289).
  • The same command for electronWrappedCallPaths.test.ts with the two
    changed source files restored to base — Tests 6 failed | 194 passed (200);
    the 6 failures are the new tests.
  • npm run test:local -- on the neighbouring Electron suites
    electronBundledRequireIdentity, javascriptStaticCoverage,
    JavaScriptSemanticGraphElectronProjection, electronStaticAnalysisScopedIpc,
    electronStaticAnalysisIdentity and electronCallPathBlockPrefixes —
    Test Files 6 passed (6), Tests 163 passed (163).
  • npm run build:cached, then
    node scripts/run-exact-tests.mjs run tests/boundary/cli/electronWrappedCallPaths.test.ts -t "exact template"
    (the runner test:focused uses) — Tests 1 passed | 24 skipped (25).
    With a build of the base source: Tests 1 failed | 24 skipped (25).
  • The CLI run of the fixture above, on a base build and on this branch's build
    — output as shown.
  • npm run check:fast — passed (typecheck and lint).
  • npx oxfmt --check on the four changed files — formatted.
  • After merging origin/main (cdc4541ef) into this branch, on the merged tree:
    npm run test:local -- src/domain/javascript/electronWrappedCallPaths.test.ts src/domain/javascript/javascriptSymbolicBindings.test.ts
    — Test Files 2 passed (2), Tests 326 passed (326);
    npm run test:focused -- tests/boundary/cli/electronWrappedCallPaths.test.ts
    built the artifacts, then
    npx vitest run tests/boundary/cli/electronWrappedCallPaths.test.ts —
    Tests 27 passed (27); npm run check:fast — passed. Since fix(javascript): preserve loader authority for exact suffixes #9477, main
    proves an Electron finding only in modules declared CommonJS, so the
    exact-template fixture now names its files .cjs; the expectations are
    unchanged.
  • Not run: npm run check, npm run check:pr, the full test suite, the other
    CLI/MCP boundary suites, and npm run docs:check and
    npm run verify:test-discovery (no docs or test files added).

Compatibility, safety, and release

  • Breaking changes or migration steps: none. For exact templates, results gain
    the facts that the quoted spelling already produces.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; static
    JavaScript analysis only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no analyzed source is
    executed, and no file, process or network effect is added.

Author readiness

Human owner: @pedrocormann

  • 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

…mplates

Electron call-path tracing started only at calls whose first argument
was a quoted string literal, and its symbolic evaluator had no case for
template literals. A template without substitutions, such as
`app:template`, therefore stayed dynamic in the trace while the syntax
pass already reads it as a literal channel through
readExactJavaScriptLiteral. Wrapper registrations on such channels were
missing, direct handlers and contextBridge exposures keyed that way got
no call paths, and exact template switch cases lost their selection
condition.

The seed check, the evaluator and the switch-case label check now read
exact strings through readExactJavaScriptLiteral. Templates with
substitutions stay dynamic.

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

greptile-apps Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; no blocking issue remains.RetriggerView in GreptileConfidence Score: 5/5

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

Summary

The PR makes Electron tracing treat exact templates like quoted strings for channels, bridge keys, and switch labels.

  • Exact template strings now trace through Electron IPC and bridge calls.
  • Exact template case labels now keep their switch conditions.

Reviews (5) · Last reviewed commit: "fix(electron): keep non-finite numeric s..." · Reviewed by Greptile

@pedrocormann
pedrocormann marked this pull request as ready for review November 9, 2026 02:09
@chatgpt-codex-connector

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

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-26T15:49:46.118883Z
We couldn’t complete this review. Comment @codex review to try again.
71b6470 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.

pedrocormann and others added 2 commits November 13, 2026 15:18
Since morluto#9477, main counts an Electron finding as proven only in modules
declared CommonJS. The exact-template fixture used .js files without a
package.json, so after merging main the wrapper registrations stayed
unpaired (paired_renderer_transmissions 0) and the wrapper's own call
changed to inferred. The change under test still works: with .cjs files
the original expectations hold.

Name the fixture files .cjs, like the neighbouring fixtures in this file.

Validation: npx vitest run tests/boundary/cli/electronWrappedCallPaths.test.ts
- Tests 27 passed (27) on the built merged tree; npm run test:local on
electronWrappedCallPaths.test.ts and javascriptSymbolicBindings.test.ts -
Tests 326 passed (326).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@morluto morluto added area: bridge Hopper bridge (Python) related changes bug Something isn't working provider: electron Analysis provider / engine: electron labels Nov 22, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@morluto
morluto enabled auto-merge (squash) November 26, 2026 16:37
@morluto
morluto merged commit 7cf0f35 into morluto:main Nov 26, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: bridge Hopper bridge (Python) related changes 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