experimental.sri does not add integrity to inline flight scripts (self.__next_f.push), breaking strict CSP without 'unsafe-inline'
Link to the code that reproduces this issue
https://github.com/bearpong/nextjs-sri-inline-csp-repro
To Reproduce
git clone https://github.com/bearpong/nextjs-sri-inline-csp-repro && cd nextjs-sri-inline-csp-repronpm installnpm run build(SRI is enabled viaexperimental.sri, strict CSP set viaheaders()—script-src 'self', no'unsafe-inline', no nonce)npm start— must be a production build;next devmasks it- Open http://localhost:3000 and open the browser console
The repo is a bare App Router app: one client component (app/counter.tsx) to force inline flight scripts + hydration, and the SRI + strict CSP config in next.config.ts.
Current vs. Expected behavior
Current: every inline flight script is blocked, so the page never hydrates (the counter button stays at count is 0 and never increments). Console shows repeated:
Executing inline script violates the following Content Security Policy directive 'script-src 'self''.
Either the 'unsafe-inline' keyword, a hash ('sha256-…'), or a nonce ('nonce-…') is required to enable inline execution.
The action has been blocked.
The blocked scripts are the inline flight payload (self.__next_f.push). Inspecting the served HTML: external <script src> tags carry integrity="sha256-…" (from SRI), but the inline flight scripts carry none.
You can confirm without a browser:
curl -s http://localhost:3000/ | grep -oE '<script[^>]*>' | grep -c 'integrity=' # external: > 0
# inline self.__next_f.push scripts: several, none with integrity
Expected: with experimental.sri enabled, the framework's own inline flight scripts should be trusted under a strict CSP without 'unsafe-inline' — e.g. by attaching an integrity attribute to each inline flight script the same way external scripts are handled. Since these scripts are generated server-side, their hash is knowable at emit time.
Root cause (traced in [email protected], matches canary)
Next splits scripts into two paths:
- External
<script src>getintegrityfrom the SRI manifest, keyed by filename:next/dist/server/app-render/required-scripts.js→bootstrapScript.integrity = SRIManifest[files[0]]app-render.jspolyfills →integrity: subresourceIntegrityManifest?.[polyfill]
- Inline flight scripts (
self.__next_f.push) — the tag is built with only anonce(if present), never anintegrity:next/dist/server/app-render/use-flight-response.js→const startScriptTag = nonce ? \Owner
Other Repo Issues