Repository navigation
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
…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]>
c5d60cf to
339865d
Compare
…mplate-literal-module-imports # Conflicts: # src/browser/WebSourceMapFetcher.ts
|
Merged current The pre-commit formatter also rewrapped 3 lines in Validation after the merge: |
|
Notes on the 4 failing checks in run 38435668108. None of them reaches code changed in this PR:
I have not pushed changes for these, to keep this PR scoped to its fix. Happy to rebase or merge |
|
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. |
Summary
Fixes #2841
Fixes #2599
Captured-bundle chunk edges (
analyze_web_bundle) and source-map original module edges only accepted quoted string literals asimport()/require()specifiers. Bundlers such as rolldown emit plain constants as expression-free template literals (import(`./chunk.js`)), so statically known dependencies were dropped whilecompleteness.statusstayedcomplete. On OWASP Juice Shop v20.3.0 this hid every lazy-loaded chunk.Problem and expected behavior
Smallest trigger:
import(`./lazy.js`)yields nodynamic_importedge, whileimport("./lazy.js")does. In an original source returned by a source map,import(`./dep.js`)andrequire(`./common.cjs`)yield nooriginal_module_edgesentry (#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 narrowert.isStringLiteralcheck.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
src/domain/webBundleAnalyzerInspection.ts: theImportExpressionchunk edge reads its specifier throughstringValue, which is already imported there for call-argument specifiers.src/browser/WebSourceMapFetcher.ts(originalDependency):import()andrequire()specifiers read throughstringValue.requireis included because it is the same function and the same brittleness, and captured-bundlerequirecalls already usestringValue.path/routeproperties and WebMCPobjectString, which [Bug] analyze_web_bundle misses routes declared with template literals (path:x) #2805 / fix(browser): extract web bundle routes declared with template literals #2823 cover. The two PRs touch different hunks.Contribution scope: ordinary fix within existing static-analysis boundaries; maintainer decision not applicable.
Contract and boundary impact
webBundleAnalyzerInspection.ts) and source-map original dependency extraction (WebSourceMapFetcher.ts).chunks.edgesandsource_maps.items[].original_module_edgescan contain additional entries.Expected effects:
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, includingresolved_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 forimport()andrequire(), computed controls,resolved_source, and retained original text and mappings.Base reproduction: with the test changes applied to
48a683ac8and 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_importedges48a683ac8hacking-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:
Validation performed
Windows 11, Node.js 24.18.0, npm 11.16.0, rebased on
mainat6e25cc3c7: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 on48a683ac8) 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-boundariesandoxfmt --checkon changed files: passed.Compatibility, safety, and release
Before merge
type(scope): outcome.🤖 Generated with Claude Code