Skip to content

fix(javascript): preserve loader authority for exact suffixes - #9477

Merged
morluto merged 49 commits into
mainfrom
codex/javascript-loader-authority-followup
Nov 9, 2026
Merged

morluto merged 49 commits into
mainfrom
codex/javascript-loader-authority-followup

Conversation

@morluto

@morluto morluto commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fixes #8973; relates to #9446. An uppercase .MJS filename does not establish Node's lowercase .mjs loader, but REA could infer a module or a CommonJS wrapper from the filename. Preserve unknown-host loader observations as candidates instead of reporting proven, resolved dependencies. Apply package and preload loader context only to exact lowercase .js and .ts suffixes as appropriate; uppercase spellings keep candidate dependencies. Case-variant suffixes also keep runtime mode unknown when the source combines ESM syntax and a possible CommonJS request; both syntax observations remain available. The same rule applies to dotfiles such as .MJS, whose suffix is not returned by path.extname. Reference-source classification uses the same JavaScript syntax admission for suffix-only dotfiles, retaining their language and candidate relationships.

This change continues ShuaixinHuang's #9428 and retains its original commits and authorship. It also addresses three review findings: aliases retain conditional loader authority, writes to child properties do not by themselves replace the parent callable, and TypeScript-wrapped call/apply invocations still check callable mutation.

Scope and evidence

The existing static JavaScript analysis owns loader mode, provenance and invocation effects; CLI and MCP consume those facts. The change does not add target execution. Candidate references and graph Evidence carry uncertainty instead of claiming a proven loader. No operation names or input schemas change.

The three review examples failed against #9428's fc98a0653c head and pass through both CLI and stdio MCP with this follow-up. Shadowed and reassigned alias controls also pass. A related consecutive-method case also failed because receiver-escape tracking treated a later effect as preceding a proven native resolver. The ambient-effect owner now uses source-order proof while keeping repeated, deferred, and otherwise uncertain execution conservative. Both dependencies are retained through CLI and stdio MCP; prior opaque calls and repeated function execution remain unknown. A nested-alias follow-up also checks callable mutation after selecting the loader value: replacing box.load.call no longer invents a dependency, while writes to a child property remain valid. Conditional constructor calls now retain literal requests through direct and aliased loaders; shadowed and replaced constructors stay local. Reference-source import also retains constructor requests, normalizes TypeScript-wrapped callees, and follows nested loader aliases using the selected callable path. Unknown-host resolution stays unknown; replaced or shadowed loaders are rejected. Both consumers use the same selected-callable mutation rule. Shared graph projections keep conditional built-in node markers, relation resolution and Evidence together across configuration, request, resource, timer and child-process operations; operation-specific properties remain local. Graph acceptance checks require the expected relations and their candidate or proven Evidence.

TypeScript-wrapped unknown-host require.resolve calls retain their resolver operation in the shared call fact, with deferred mutation checks using the normalized callee. Mixed ESM and unknown-loader alternatives for the same built-in now retain the operation as conditional. The shared identity and receiver checks consider equivalent origins and their mutations; different modules and CommonJS default slots remain distinct. Nested receivers such as selected.promises.readFile use the same origin and mutation rules, including replacement of the selected object or method.

Validation performed

  • Three parser and loader suites: 126 tests passed on the dotfile follow-up.
  • npm run test:focused -- tests/boundary/filesystem/referenceSourceLoaderConstructors.test.ts tests/boundary/filesystem/referenceSourceImport.test.ts tests/boundary/filesystem/referenceSourceShadowedRequire.test.ts tests/acceptance/applications/javascriptPackageSuffixCase.test.ts — 34 tests passed, including reference-source and CLI/stdio MCP workflows; the reorganized constructor boundary assertions were rerun separately. The public import-reference-source CLI and the constructor boundary test also passed together for suffix-only dotfiles. A Node 24.22.1 control successfully ran the CommonJS-package .MJS mixed-syntax fixture; the module-package control failed at require.
  • Six JavaScript effect and resource source suites: 85 tests passed, including both branch orders, nested receiver selection and replacement controls. npm run test:focused -- tests/acceptance/applications/javascriptConditionalBuiltinEffects.test.ts passed through CLI and stdio MCP.
  • Three loader invocation, iteration and mutation suites: 91 tests passed. npm run test:focused -- tests/acceptance/applications/unboundRequires.test.ts passed all 11 tests, including CLI and stdio MCP.
  • npm run test:focused -- tests/boundary/filesystem/javascript-applications/electronApplicationAnalysis.test.ts — 10 passed against the built worker with Node 24.22.1. Restoring the old fixture filenames reproduced all three CI failures; the fixtures now declare CommonJS with .cjs because the selected inventory has no package manifest establishing a .js loader. The native-loader source suite passed 14 tests, including the ESM control.
  • npm run format:check passed after formatting the files reported by CI.
  • npm run check:fast — typecheck and lint passed.
  • The earlier fix(javascript): require exact loader suffix case #9428 CI run contains canceled shards; CI for the latest push and review of the full inherited diff remain outstanding. Windows and real external-application coverage were not run for this follow-up.

Maintainer follow-up

Candidate Electron windows were being treated as proof that their preloads execute with CommonJS authority. The preload context owner now requires a proven window; candidate evidence remains candidate, with a positive proven-window control retained. Filename handling now uses the shared Node extension interpretation instead of suffix matching: extensionless dotfiles named .mjs/.cjs/.js/.ts/.json/.node cannot establish a loader without route evidence. Existing normal-extension, shadowed/replaced resolver, and wrapped receiver controls remain covered.

At d389477, the new negative controls failed before repair and pass afterward. The final checks passed 135 domain tests and 25 built CLI/MCP/reference-source/Electron boundary tests, plus uncached check:fast and full format:check. Node 24.22.1 probes confirm that suffix-only names differ by load route; no real Electron application qualification was performed. Current-head CI and Greptile review remain required before merge.
Fixed in 2540713. The helper previously converted an absent source module into undefined/empty facts, allowing negative assertions to pass without preload evidence. Every helper caller requires a source module, so sourceRequireFacts now fails explicitly if that module is absent. The regression also requires a BrowserWindow with loader_authority: "candidate" and checks that the preload module format is "unknown" before checking the unresolved dependency. Removing preload.js from the fixture made this test fail with the missing-source-module error; after restoring it, all 12 acceptance tests passed. Full format:check and uncached check:fast also passed. No further cleanup for this finding remains; current-head CI and automated review are still required before merge.
Follow-up on the outside-diff finding: the reported child-property behavior was already fixed by 8c3af19. On the current branch, real reference-source imports after require.call.extra, require.apply.extra, and require.resolve.extra writes all resolve internally. The final guard also protects a distinct case: deleting it falsely resolves a directly replaced box.load() alias as internal. It therefore remains in place. Test-only commit 1c1485f adds these positive cases and direct/deferred alias-replacement controls. The 32-test reference-source boundary run, targeted formatting check, and diff check passed. The reported example passed before this test-only follow-up; the deletion negative control failed as described. No production redesign was needed.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

ShuaixinHuang and others added 26 commits November 5, 2026 14:41
…58-loader-origin-fix

# Conflicts:
#	src/application/javascript/JavaScriptArtifactGraphBuilder.ts
@morluto
morluto marked this pull request as ready for review November 8, 2026 18:51
@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-09T05:18:45.352842Z 1c1485f 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.

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

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

@morluto

morluto commented Nov 9, 2026

Copy link
Copy Markdown
Owner Author

Follow-up on the outside-diff finding: the reported child-property behavior was already fixed by 8c3af19. On the current branch, real reference-source imports after require.call.extra, require.apply.extra, and require.resolve.extra writes all resolve internally. The final guard also protects a distinct case: deleting it falsely resolves a directly replaced box.load() alias as internal. It therefore remains in place. Test-only commit 1c1485f adds these positive cases and direct/deferred alias-replacement controls. The 32-test reference-source boundary run, targeted formatting check, and diff check passed. The reported example passed before this test-only follow-up; the deletion negative control failed as described. No production redesign was needed.

@morluto
morluto merged commit b46f4fc into main Nov 9, 2026
14 of 24 checks passed
@morluto
morluto deleted the codex/javascript-loader-authority-followup branch November 9, 2026 05:21
2SinceJuly added a commit to 2SinceJuly/rea that referenced this pull request Nov 9, 2026
main renamed the Electron loader-authority handling in morluto#9477, so the merge only needed the summary count to keep both sides: main's proven-finding filters for the seven existing fact families plus this branch's dynamic_code family.

The domain fixture now parses as CommonJS because a .js fixture resolves as ESM and every require keeps only candidate loader authority, which hid the cache path from the unit test while the real .cjs boundary test already passed.
pedrocormann added a commit to pedrocormann/rea that referenced this pull request Nov 13, 2026
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 bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Nov 22, 2026
morluto added a commit that referenced this pull request Nov 26, 2026
…mplates (#9538)

* fix(electron): trace IPC channels and bridge keys spelled as exact templates

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

* test(electron): declare CommonJS in the exact-template CLI fixture

Since #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]>

* refactor(electron): read switch case literals through the exact-literal owner

* fix(electron): keep non-finite numeric switch cases as selection predicates

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: morluto <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] JavaScript analysis treats uppercase loader suffixes as explicit module modes

2 participants