fix(scan): capture every chunk in next.js build manifest arrays - #345
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #345 +/- ##
=======================================
Coverage ? 64.78%
=======================================
Files ? 86
Lines ? 7630
Branches ? 0
=======================================
Hits ? 4943
Misses ? 2303
Partials ? 384 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
pr summary2 files changed (+91 -4)
|
the manifest maps each route to an array of chunk paths, but the regex anchored on the opening bracket so only the first .js literal per array was captured, dropping the remaining chunks from the script list. match each quoted chunk path instead, scoped to the relative static/ shape (literal or escaped slash) so non-chunk .js strings such as __rewrites destinations, which can be attacker-controlled absolute urls, are not pulled into the fetch list.
vmfunc
left a comment
There was a problem hiding this comment.
good catch on the anchor bug. per-chunk match is the right move, and requiring the "static prefix instead of a bare quoted-.js keeps the __rewrites absolute url out of the fetch list. the realistic fixture with the IIFE-arg shared chunks + decoys pins exactly that.
one loose end: the separator takes lowercase / via [fF], but the ReplaceAll on line 74 only normalizes uppercase /, so a lowercase-escaped manifest would leave a literal / in the path. next emits uppercase so it's theoretical, fine to leave or just make the replace case-insensitive. in either way.
# Conflicts: # internal/scan/js/frameworks/next_test.go
|
rebased onto current main to clear the conflict. no content change to the fix |
the pages-router build manifest regex anchored on the opening bracket of each route's chunk array, so it only ever captured the first chunk and silently dropped the rest whenever a route referenced more than one. tightened the regex to match every relative static/ chunk path instead of anchoring on the array boundary, without loosening it to a bare quoted-.js match, which would also pull in non-chunk strings such as __rewrites destinations (potentially an attacker-controlled absolute url). adds a realistic manifest fixture with shared IIFE-arg chunks and rewrite/sortedPages decoys to pin both the fix and the anti-fp behavior.