Set Cross-Origin-Resource-Policy on /_next/static assets - #92682
Open
lnuvy wants to merge 1 commit into
Open
Conversation
Contributor
|
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Set
Cross-Origin-Resource-Policy: same-originon responses served from/_next/static/*inrouter-server.ts.Why
Turbopack writes
worker-entrypoint.jsto/_next/static/(added in #d23af53) and loads it withnew Worker(...). When the document setsCross-Origin-Embedder-Policy: require-corp, the browser blocks that fetch because Next.js does not send a CORP header for it. This breaks every app that enables COEP and uses a Worker on 16.2, a regression from 16.1.same-originis safe here because these are first-party build artifacts. The fix only sets the header when the user hasn't already set one viaheaders().Fixes #92676
Test plan
New e2e test at
test/e2e/app-dir/worker-coep:require-corpand asserts the worker's message arrives/_next/static/<buildId>/_buildManifest.jsresponds withcross-origin-resource-policy: same-originVerified locally in
dev/Turbopack,start/Turbopack, anddev/webpack. Without the fix, the CORP assertion fails withExpected: "same-origin" / Received: null.