[PR #6007] [MERGED] fix(javascript): refuse Webpack loaders that can fall off the end #7117

Closed
opened 2026-11-01 21:45:30 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/6007
Author: @kaoru0822-kitauji
Created: 10/21/2026
Status: ✅ Merged
Merged: 10/21/2026
Merged by: @kaoru0822-kitauji

Base: main ← Head: fix/5958-webpack-loader-window-facts


📝 Commits (3)

  • fd259f2 fix(javascript): refuse Webpack loaders that can fall off the end
  • fa2e80f test(javascript): cover finally completion in Webpack loader proofs
  • 1a8b44a test(javascript): keep IPC checks for unresolved Webpack loader cases

📊 Changes

3 files changed (+173 additions, -34 deletions)

View changed files

📝 src/domain/javascript/electronBundledRequireIdentity.test.ts (+72 -27)
📝 src/domain/javascript/javascriptBootstrapIntegrity.ts (+39 -7)
➕ tests/acceptance/applications/webpackLoaderReturnsCli.test.ts (+62 -0)

📄 Description

What broke: A Webpack loader whose miss path falls off the end (only the cache-hit return, or no return at all) still passed the bootstrap integrity proof, so n(45840).BrowserWindow became an exact Electron window.
Fix: loaderShape now refuses the proof when the loader body can complete normally, before checking that every explicit return yields the module's exports.
Risk: Low. The check is a shallow statement walk; it makes canonical loaders (which end in return) no less accepted, and unfamiliar terminal control flow (loops, switches, labels) stays unproven rather than accepted.

Summary

Fixes #5958. analyze-javascript-application reported one exact browser-window for Webpack bootstraps whose loader returns undefined on a cache miss. Those loaders now leave the bundled-call Electron identity unresolved. The literal require("electron") reference and the rest of the analysis stay as before.

Problem and expected behavior

Trigger: a loader function n(key) { var cached = cache[key]; if (cached !== undefined) return cached.exports; var module = (cache[key] = { exports: {} }); modules[key](module, module.exports, n); }, which has no miss-path return, or the same loader with no return statements at all.

Violated invariant: proveJavaScriptBootstrapIntegrity must prove that loader(key) returns the selected factory's exports. loaderShape checked only returns.every(...) over the explicit ReturnStatements. That check passes vacuously for an empty list, and it ignores a miss path that falls off the end.

Change and scope

  • src/domain/javascript/javascriptBootstrapIntegrity.ts: adds completesNormally, which treats return and throw as non-completing and follows blocks, if/else and try/catch/finally. It treats loops, switches and labeled statements as completing, because a break there can exit the statement. loaderShape rejects the loader when its body can complete normally. The check is in the owning proof, so every consumer of the proof (javascriptBundledRequireOrigin, the external and getter mappings) inherits it, and no consumer has to repair it downstream.
  • Not included: proving that runtime guards pass, or support for new loader shapes.
  • Scope: an ordinary fix within existing static-analysis boundaries; no maintainer scope decision is needed.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the domain Webpack bootstrap integrity proof (javascriptBootstrapIntegrity.ts).

  • Contribution scope fit and linked maintainer decision: not applicable (bug fix inside the existing boundary).

  • CLI and MCP/tool-catalog contract: no schema change. Malformed loaders now report fewer bundled-call Electron observations.

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

  • Evidence, artifact, provenance, or reconstruction contract: removes false ast-static-analysis/observed/exact window observations. Source facts are preserved.

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

  • Generated metadata, package, or installation impact: none.

  • Read existing files or captured data.

Evidence and regression coverage

  • Tests added or updated:

    • tests/acceptance/applications/webpackLoaderReturnsCli.test.ts: the issue's three fixtures run through the public CLI. Canonical gives 1 window; cache-hit-only and no-returns give 0. All three still contain the require("electron") reference.
    • src/domain/javascript/electronBundledRequireIdentity.test.ts, new "completion paths" suite. Kept unresolved: cache-hit-only, no returns, a return from only one if branch, try { return … } catch {} falling through, a catch falling through past a completing finally, and a finally returning another value. Still resolved: exports returned from both if/else branches, and exports returned from a finally after a falling-through catch.
  • Base reproduction: with the fix reverted, the new CLI test fails 2 of 3 (expected 1 to be +0 for both fallthrough loaders), and the module test fails 5 of the new completion-path cases. Each finally rule has a test that fails when that rule is changed. With the fix, all pass.

  • User-visible CLI output: I re-ran the issue's script against a built checkout of this branch. Output: canonical 1, cache-hit-only 0, no-returns 0. The cache-hit-only graph keeps the {"reference_kind":"require","specifier":"electron","resolution_status":"external"} node, and coverage is complete.

  • Remaining proof gaps: MCP was not run separately (the CLI and MCP share the same domain producer). No real Electron application was analyzed. The issue's Node-vm execution comparison was not repeated.

  • Observed, derived, and inferred claims remain distinguishable.

  • Artifact identity, source provenance, and failed attempts remain preserved.

  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:local -- src/domain/javascript/electronBundledRequireIdentity.test.ts: 49 passed (base revision: 5 failed).
  • npm run test:local -- all src/domain/javascript/*.test.ts after the review follow-up: 130 files, 3368 passed.
  • npm run test:focused -- tests/acceptance/applications/webpackLoaderReturnsCli.test.ts: 3 passed (base revision: 2 failed).
  • npm run test:local -- src/domain/javascript/*.test.ts src/application/javascript/*.test.ts: 147 files, 3878 tests passed.
  • npm run test:focused -- the new CLI test, javascriptBundlerAdapters, javascriptBundlerRuntimeScopes, javascriptBundlerSelfReferences, applicationWorkflowCli, bundlerCallbackMetadataCli, electronApplicationAnalysis: 7 files, 61 tests passed.
  • npm run check:fast: passed.
  • npm run format:check: passed.
  • Issue repro script via node scripts/rea.mjs analyze-javascript-application: 1 / 0 / 0 windows, about 1.3–2.1 s wall and about 340 MB peak RSS per run. I did not compare before and after: the added check is a shallow walk over the loader's top-level statements and runs before the existing traversals.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; macOS arm64 only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no target execution; static analysis only.

Author readiness

Human owner: @kaoru0822-kitauji

  • 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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/6007 **Author:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Created:** 10/21/2026 **Status:** ✅ Merged **Merged:** 10/21/2026 **Merged by:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Base:** `main` ← **Head:** `fix/5958-webpack-loader-window-facts` --- ### 📝 Commits (3) - [`fd259f2`](https://github.com/morluto/rea/commit/fd259f27e3934158d7d6a66521e3da04c2a6e308) fix(javascript): refuse Webpack loaders that can fall off the end - [`fa2e80f`](https://github.com/morluto/rea/commit/fa2e80faabb0cd09c711d8079d6f382560a0023b) test(javascript): cover finally completion in Webpack loader proofs - [`1a8b44a`](https://github.com/morluto/rea/commit/1a8b44a4eb32fb40d9f8ecb7832ca345497b80e1) test(javascript): keep IPC checks for unresolved Webpack loader cases ### 📊 Changes **3 files changed** (+173 additions, -34 deletions) <details> <summary>View changed files</summary> 📝 `src/domain/javascript/electronBundledRequireIdentity.test.ts` (+72 -27) 📝 `src/domain/javascript/javascriptBootstrapIntegrity.ts` (+39 -7) ➕ `tests/acceptance/applications/webpackLoaderReturnsCli.test.ts` (+62 -0) </details> ### 📄 Description **What broke:** A Webpack loader whose miss path falls off the end (only the cache-hit `return`, or no `return` at all) still passed the bootstrap integrity proof, so `n(45840).BrowserWindow` became an exact Electron window. **Fix:** `loaderShape` now refuses the proof when the loader body can complete normally, before checking that every explicit return yields the module's exports. **Risk:** Low. The check is a shallow statement walk; it makes canonical loaders (which end in `return`) no less accepted, and unfamiliar terminal control flow (loops, switches, labels) stays unproven rather than accepted. ## Summary Fixes #5958. `analyze-javascript-application` reported one exact `browser-window` for Webpack bootstraps whose loader returns `undefined` on a cache miss. Those loaders now leave the bundled-call Electron identity unresolved. The literal `require("electron")` reference and the rest of the analysis stay as before. ## Problem and expected behavior Trigger: a loader `function n(key) { var cached = cache[key]; if (cached !== undefined) return cached.exports; var module = (cache[key] = { exports: {} }); modules[key](module, module.exports, n); }`, which has no miss-path return, or the same loader with no return statements at all. Violated invariant: `proveJavaScriptBootstrapIntegrity` must prove that `loader(key)` returns the selected factory's exports. `loaderShape` checked only `returns.every(...)` over the explicit `ReturnStatement`s. That check passes vacuously for an empty list, and it ignores a miss path that falls off the end. ## Change and scope - `src/domain/javascript/javascriptBootstrapIntegrity.ts`: adds `completesNormally`, which treats `return` and `throw` as non-completing and follows blocks, `if`/`else` and `try`/`catch`/`finally`. It treats loops, switches and labeled statements as completing, because a `break` there can exit the statement. `loaderShape` rejects the loader when its body can complete normally. The check is in the owning proof, so every consumer of the proof (`javascriptBundledRequireOrigin`, the external and getter mappings) inherits it, and no consumer has to repair it downstream. - Not included: proving that runtime guards pass, or support for new loader shapes. - Scope: an ordinary fix within existing static-analysis boundaries; no maintainer scope decision is needed. ## Contract and boundary impact - Semantic owner and earliest changed stage: the domain Webpack bootstrap integrity proof (`javascriptBootstrapIntegrity.ts`). - Contribution scope fit and linked maintainer decision: not applicable (bug fix inside the existing boundary). - CLI and MCP/tool-catalog contract: no schema change. Malformed loaders now report fewer bundled-call Electron observations. - Provider, bridge, target-format, or platform compatibility: none. - Evidence, artifact, provenance, or reconstruction contract: removes false `ast-static-analysis`/`observed`/`exact` window observations. Source facts are preserved. - Target selection, authority, upstream behavior, and cleanup details: not applicable. - Generated metadata, package, or installation impact: none. - [x] Read existing files or captured data. ## Evidence and regression coverage - Tests added or updated: - `tests/acceptance/applications/webpackLoaderReturnsCli.test.ts`: the issue's three fixtures run through the public CLI. Canonical gives 1 window; cache-hit-only and no-returns give 0. All three still contain the `require("electron")` reference. - `src/domain/javascript/electronBundledRequireIdentity.test.ts`, new "completion paths" suite. Kept unresolved: cache-hit-only, no returns, a return from only one `if` branch, `try { return … } catch {}` falling through, a catch falling through past a completing `finally`, and a `finally` returning another value. Still resolved: exports returned from both `if`/`else` branches, and exports returned from a `finally` after a falling-through catch. - Base reproduction: with the fix reverted, the new CLI test fails 2 of 3 (`expected 1 to be +0` for both fallthrough loaders), and the module test fails 5 of the new completion-path cases. Each `finally` rule has a test that fails when that rule is changed. With the fix, all pass. - User-visible CLI output: I re-ran the issue's script against a built checkout of this branch. Output: `canonical 1`, `cache-hit-only 0`, `no-returns 0`. The cache-hit-only graph keeps the `{"reference_kind":"require","specifier":"electron","resolution_status":"external"}` node, and coverage is `complete`. - Remaining proof gaps: MCP was not run separately (the CLI and MCP share the same domain producer). No real Electron application was analyzed. The issue's Node-vm execution comparison was not repeated. - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed - `npm run test:local -- src/domain/javascript/electronBundledRequireIdentity.test.ts`: 49 passed (base revision: 5 failed). - `npm run test:local --` all `src/domain/javascript/*.test.ts` after the review follow-up: 130 files, 3368 passed. - `npm run test:focused -- tests/acceptance/applications/webpackLoaderReturnsCli.test.ts`: 3 passed (base revision: 2 failed). - `npm run test:local -- src/domain/javascript/*.test.ts src/application/javascript/*.test.ts`: 147 files, 3878 tests passed. - `npm run test:focused --` the new CLI test, `javascriptBundlerAdapters`, `javascriptBundlerRuntimeScopes`, `javascriptBundlerSelfReferences`, `applicationWorkflowCli`, `bundlerCallbackMetadataCli`, `electronApplicationAnalysis`: 7 files, 61 tests passed. - `npm run check:fast`: passed. - `npm run format:check`: passed. - Issue repro script via `node scripts/rea.mjs analyze-javascript-application`: 1 / 0 / 0 windows, about 1.3–2.1 s wall and about 340 MB peak RSS per run. I did not compare before and after: the added check is a shallow walk over the loader's top-level statements and runs before the existing traversals. ## Compatibility, safety, and release - Breaking changes or migration steps: none. - Real Hopper/Ghidra, browser, or OS coverage: not applicable; macOS arm64 only. - Package or release metadata impact: none. - Security, privacy, process, or containment review: no target execution; static analysis only. ## Author readiness Human owner: @kaoru0822-kitauji - [x] 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. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output. - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-01 21:45:30 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#7117
No description provided.