Skip to content

fix(scan): capture every chunk in next.js build manifest arrays - #345

Merged
vmfunc merged 2 commits into
vmfunc:mainfrom
TBX3D:hunt/jsframe
Jul 22, 2026
Merged

fix(scan): capture every chunk in next.js build manifest arrays#345
vmfunc merged 2 commits into
vmfunc:mainfrom
TBX3D:hunt/jsframe

Conversation

@TBX3D

@TBX3D TBX3D commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

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.

@TBX3D
TBX3D requested a review from vmfunc as a code owner July 9, 2026 22:12
@github-actions github-actions Bot added size/m <200 lines changed scan changes to scan engine modules changes to scan modules tests test changes and removed size/m <200 lines changed labels Jul 9, 2026
@codecov-commenter

codecov-commenter commented Jul 9, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@a664f36). Learn more about missing BASE report.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

pr summary

2 files changed (+91 -4)

category files
go source 2
tests 1

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.
@github-actions github-actions Bot added the size/m <200 lines changed label Jul 10, 2026

@vmfunc vmfunc left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@vmfunc
vmfunc enabled auto-merge (squash) July 22, 2026 21:47
Copilot AI review requested due to automatic review settings July 22, 2026 21:47

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review is ineligible. To be eligible to request a review, you need a paid Copilot license, or your organization must enable Copilot code review.

@vmfunc
vmfunc merged commit 6500b08 into vmfunc:main Jul 22, 2026
13 checks passed
@TBX3D

TBX3D commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

rebased onto current main to clear the conflict. no content change to the fix
itself; the branch's tests needed updating to GetPagesRouterScripts' timeout
parameter, which main grew after this branch was cut.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

modules changes to scan modules scan changes to scan engine size/m <200 lines changed tests test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants