Skip to content

fix(browser): read expression-free template literals as module specifiers - #2842

Merged
morluto merged 5 commits into
morluto:mainfrom
shubhamahuja9999:fix/web-template-literal-module-imports
Oct 13, 2026
Merged

morluto merged 5 commits into
morluto:mainfrom
shubhamahuja9999:fix/web-template-literal-module-imports

Conversation

@shubhamahuja9999

@shubhamahuja9999 shubhamahuja9999 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #2841
Fixes #2599

Captured-bundle chunk edges (analyze_web_bundle) and source-map original module edges only accepted quoted string literals as import() / require() specifiers. Bundlers such as rolldown emit plain constants as expression-free template literals (import(`./chunk.js`)), so statically known dependencies were dropped while completeness.status stayed complete. On OWASP Juice Shop v20.3.0 this hid every lazy-loaded chunk.

Problem and expected behavior

Smallest trigger: import(`./lazy.js`) yields no dynamic_import edge, while import("./lazy.js") does. In an original source returned by a source map, import(`./dep.js`) and require(`./common.cjs`) yield no original_module_edges entry (#2599).

Violated invariant: an expression-free template literal is an exact string. The canonical module-import extractor (collectWebModuleImports) and the shared exact-literal reader (stringValue / readExactJavaScriptLiteral) already treat it that way. These two dependency readers each repeated a narrower t.isStringLiteral check.

Expected: the same edge kind, specifier, resolved URL/source and location as the quoted form. Template literals with substitutions (import(`./${name}.js`)) stay unrecognized.

Change and scope

Contribution scope: ordinary fix within existing static-analysis boundaries; maintainer decision not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: captured-script static inspection (webBundleAnalyzerInspection.ts) and source-map original dependency extraction (WebSourceMapFetcher.ts).
  • Contribution scope fit and linked maintainer decision: existing read-only static analysis; not applicable.
  • CLI and MCP/tool-catalog contract: no schema change; chunks.edges and source_maps.items[].original_module_edges can contain additional entries.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: unchanged; new edges use existing kinds, locations and resolution.
  • Target selection, authority, upstream behavior, and cleanup details: not applicable.
  • Generated metadata, package, or installation impact: none.

Expected effects:

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

    • src/domain/webBundleAnalyzer.test.ts, "reads expression-free template dynamic imports as chunk edges": template, quoted and computed controls, including resolved_url.
    • tests/boundary/browser/webSourceMapFetcher.test.ts, "reads expression-free template module specifiers as literals": the fix(browser): source-map evidence omits literal template imports #2599 restoration check for import() and require(), computed controls, resolved_source, and retained original text and mappings.
  • Base reproduction: with the test changes applied to 48a683ac8 and the source fix reverted, both new tests fail (2 failed, 96 passed). With the fix, 98/98 pass.

  • User-visible output, live run on OWASP Juice Shop v20.3.0 (official release, loopback only, Chrome 155, --observation-ms 3000):

    dynamic_import edges
    upstream 48a683ac8 0
    with this change 8 (hacking-instructor, confetti, faucet.module, wallet-web3.module, web3-sandbox.module, coding-challenge-page.component, recycle.component, about.component)

    The live "with" run used an earlier local revision that also contained route-property handling, which does not affect chunk edges; the import() code was identical.

  • Remaining proof gaps: source-map edges were verified through the boundary test only, not against a live site's maps; the real-browser CI lane was not run locally.

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

Windows 11, Node.js 24.18.0, npm 11.16.0, rebased on main at 6e25cc3c7:

  • npm run test:focused -- src/domain/webBundleAnalyzer.test.ts tests/boundary/browser/webSourceMapFetcher.test.ts: both new tests failed without the source fix (2 failed, 96 passed, reproduced on 48a683ac8) and pass with it.
  • npm run test:focused -- the 12 test files referencing web bundle or source-map analysis (browser/CDP boundary, source-map fetcher/status/coordinates/cleanup, browser CLI, browser MCP, tool-schema validity, target-content provenance): 225/225 passed.
  • npm run check:fast (typecheck and lint): passed, including as the pre-push hook.
  • npm run verify:module-boundaries and oxfmt --check on changed files: passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: Windows; live Chrome 155 run against a loopback Juice Shop for captured-bundle edges.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: read-only static parsing of already captured script and source-map text; no new execution, fetch, or network behavior.

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

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge.

Summary

The PR uses stringValue to recognize expression-free template literals in captured-bundle imports and source-map dependencies.

  • Template-written module names now appear in dependency edges.

Reviews (6) · Last reviewed commit: "Merge branch 'main' into fix/web-templat..." · Reviewed by Greptile

…iers

Captured-bundle chunk edges and source-map original module edges only
accepted quoted string literals as import()/require() specifiers. Bundlers
such as rolldown emit plain constants as expression-free template literals
(import(`./chunk.js`)), so statically known dependencies were dropped while
completeness stayed complete. Read both sites through the shared exact-literal
reader (stringValue); template literals with substitutions stay unrecognized.

On OWASP Juice Shop v20.3.0 this recovers 8 lazy chunk edges (previously 0).

Fixes morluto#2841
Fixes morluto#2599

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@shubhamahuja9999
shubhamahuja9999 force-pushed the fix/web-template-literal-module-imports branch from c5d60cf to 339865d Compare October 13, 2026 14:40
@shubhamahuja9999

Copy link
Copy Markdown
Contributor Author

Merged current main (f104500) to resolve the conflict with #2886 in WebSourceMapFetcher.originalDependency. The resolution keeps both changes: optional require?.() calls and requireCallee from #2886, plus stringValue specifiers from this PR, so require(`./x.cjs`) and require?.(`./x.cjs`) both produce edges.

The pre-commit formatter also rewrapped 3 lines in scripts/lib/clean-linux-hopper-runtime.mjs. That file fails oxfmt --check on main after #2910; the change is whitespace only.

Validation after the merge: npx tsc --noEmit passed; npm run test:focused -- the 13 web-bundle/source-map test files, 233/233 passed (including the #2886 optional-require tests); npm run check:fast passed.

@shubhamahuja9999

Copy link
Copy Markdown
Contributor Author

Notes on the 4 failing checks in run 38435668108. None of them reaches code changed in this PR:

  • Test shard (6/6): 5 failures in src/domain/reconstructionVerification.functionSources.test.ts ("historical calls-only reconstruction changes"). The same file fails in Test shard (6/6) on fix: isolate Linux inventory and repair DEX schema regex #2910 at 69bd81f7f.
  • Windows capability and package lane: AssertionError [ERR_ASSERTION]: Missing expected exception from the inspection-conformance probe.mjs retry. The same lane also failed on feat(mcp): keep compact input schemas within ten nesting levels #2905.
  • web_runtime / real-web-runtime and web_source_map / real-web-source-map: both stop in CdpBrowserProvider.listTargets → CdpConnection.connect with SyntaxError: Invalid URL: undefined (no WebSocket debugger URL from the owned browser) during owned-browser startup. That is before any script or source-map parsing, so originalDependency and inspectNode never run. These lanes only ran here because the PR touches browser files, so there is no recent main result to compare against. I could not run them locally (Windows; the lane needs the Linux native build).

I have not pushed changes for these, to keep this PR scoped to its fix. Happy to rebase or merge main again once those lanes are green there.

@morluto
morluto merged commit bcb60c1 into morluto:main Oct 13, 2026
31 checks passed
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
@morluto

morluto commented Oct 20, 2026

Copy link
Copy Markdown
Owner

I appreciate #2842, @shubhamahuja9999. Recognizing expression-free template literals as exact module specifiers restores statically knowable chunk and source-map edges, and leaving interpolated templates unknown keeps the analysis appropriately bounded. Nice work fixing both readers at their shared literal boundary.

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

3 participants