nextjs - 💡(How to fix) Fix Docs: Applying content security policy with middleware breaks if Chrome preloads page [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#84249Fetched 2026-04-08 02:20:14
View on GitHub
Comments
2
Participants
2
Timeline
8
Reactions
0
Assignees
Timeline (top)
commented ×2labeled ×2assigned ×1issue_type_added ×1

Code Example

missing: [
        { type: 'header', key: 'next-router-prefetch' },
        { type: 'header', key: 'purpose', value: 'prefetch' },
      ],
RAW_BUFFERClick to expand / collapse

What is the documentation issue?

The docs here recommend a matcher that causes the middleware to not run, and therefore CSP to not be applied, if Chrome preloads the page.

Is there any context that might help us understand?

      missing: [
        { type: 'header', key: 'next-router-prefetch' },
        { type: 'header', key: 'purpose', value: 'prefetch' },
      ],

Does the docs page already exist? Please link to it.

https://nextjs.org/docs/app/guides/content-security-policy

extent analysis

TL;DR

  • Update the matcher in the documentation to correctly handle Chrome's page preloading.

Guidance

  • Review the next-router-prefetch and purpose header configurations to ensure they are correctly set for preloaded pages.
  • Verify that the Content Security Policy (CSP) is being applied as expected when pages are preloaded by Chrome.
  • Check the Next.js documentation on Content Security Policy for any updates or recommendations on handling preloaded pages.
  • Consider testing the middleware with different preload scenarios to identify any potential issues.

Example

No code snippet is provided as the issue does not contain sufficient code context.

Notes

  • The solution may depend on the specific version of Next.js being used, as well as any custom configurations or middleware implementations.
  • Further investigation into the next-router-prefetch and purpose headers may be necessary to determine the root cause of the issue.

Recommendation

  • Apply workaround: Update the matcher configuration to handle preloaded pages correctly, as the current documentation may be outdated or incorrect.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING