Next.js 16.4.4 Fixes PPR CSP Nonces: Verify the Backport
Next.js 16.4.4 shipped a backported fix that puts the CSP nonce on the Partial Prerendering (PPR) resume bootstrap, the small inline script that wakes up the dynamic part of a prerendered page. If you run a strict, nonce
Next.js 16.4.4 shipped a backported fix that puts the CSP nonce on the Partial Prerendering (PPR) resume bootstrap, the small inline script that wakes up the dynamic part of a prerendered page. If you run a strict, nonce based Content Security Policy on top of PPR, that script has to carry the nonce your policy expects, or the browser is supposed to block it. Here's how I'd reproduce the problem on your current version, prove the patch fixes it on yours, and wire a check into CI so it never sneaks back.
TL;DR
- 16.4.4 is a patch release with two backports: a Turbopack startup CSS update fix and the CSP nonce fix for the PPR resume bootstrap. It is not the canary feature set, so don't upgrade expecting anything else.
- A nonce only protects you if every script the framework emits carries it. Verify that against the raw HTML and in a real browser, not by reading the release note.
- Put a two part check in CI: every executable script in the HTML has the response nonce, and a headless browser reports zero CSP violations on your PPR routes.
What changed and what is actually available
The Next.js 16.4.4 release notes list two backports: one for Turbopack startup CSS updates and one described as a CSP nonce fix for the PPR resume bootstrap. That's the whole verified surface. The release explicitly does not bring in everything that's on canary, so if a feature you saw in a canary changelog isn't in that note, assume it isn't in 16.4.4.
Quick refresher on why one script matters. A nonce is a random value your server generates for every request. It goes into the Content-Security-Policy header (script-src 'nonce-<value>') and onto each <script> tag, and the browser only runs scripts whose nonce matches. MDN's practical CSP implementation guide recommends exactly this, nonce based strict CSP for dynamically generated content, hashes for static content, and strict-dynamic where appropriate.
PPR adds a twist. The static shell of a route is prerendered, and the dynamic holes are filled in at request time. Something has to kick off that resume step in the browser, and that something is an inline bootstrap script. The release note calls the fix a nonce fix for that bootstrap, so the practical question for you is simple: on your current version, does that script carry your nonce, and on 16.4.4, does it?
You want a clean repro app for this, separate from your real one, so nothing else in your config muddies the result. If you're setting one up on a fresh machine, my walkthrough on installing Next.js on Windows, Mac and Linux covers the toolchain. After that, create the app and pin the exact version you run in production today.
Implementation details and limits
Here is the nonce wiring I'd use for the repro. It mints a nonce per request, sends the policy on the response, and also passes it on the request headers, because that's where Next.js reads it from when it stamps its own scripts.
// proxy.ts (Next.js 16). On apps still using middleware.ts, export the same function as `middleware`.
import { NextResponse, type NextRequest } from "next/server";
export function proxy(request: NextRequest) {
const nonce = btoa(crypto.randomUUID());
const isDev = process.env.NODE_ENV === "development";
const csp = [
`default-src 'self'`,
`script-src 'self' 'nonce-${nonce}' 'strict-dynamic'${isDev ? " 'unsafe-eval'" : ""}`,
`style-src 'self' 'nonce-${nonce}'`,
`img-src 'self' blob: data:`,
`object-src 'none'`,
`base-uri 'self'`,
`frame-ancestors 'none'`,
].join("; ");
const requestHeaders = new Headers(request.headers);
requestHeaders.set("x-nonce", nonce);
requestHeaders.set("Content-Security-Policy", csp);
const response = NextResponse.next({ request: { headers: requestHeaders } });
response.headers.set("Content-Security-Policy", csp);
return response;
}
export const config = {
matcher: [
{
source: "/((?!api|_next/static|_next/image|favicon.ico).*)",
missing: [
{ type: "header", key: "next-router-prefetch" },
{ type: "header", key: "purpose", value: "prefetch" },
],
},
],
};
Then a route that actually exercises PPR: a static heading in the shell and one component that reads cookies, so it can only render at request time.
// app/ppr-check/page.tsx
import { Suspense } from "react";
import { cookies } from "next/headers";
async function Personalized() {
const store = await cookies();
const theme = store.get("theme")?.value ?? "default";
return <p data-testid="dynamic-hole">Theme from cookie: {theme}</p>;
}
export default function Page() {
return (
<main>
<h1>Static shell</h1>
<Suspense fallback={<p>Loading the personalized part</p>}>
<Personalized />
</Suspense>
</main>
);
}
Three limits worth knowing before you trust any result:
-
Test the production build. Run
next buildandnext start. The dev server needs'unsafe-eval'and behaves differently enough that a clean dev run proves nothing. - Nonces need request time HTML. A per request value can't live inside HTML that was generated once at build time. For pages that are fully static, MDN's advice is hashes, not nonces.
-
The spec is still moving. W3C's latest CSP Level 3 document is a Working Draft, not a final Recommendation, so how browsers treat
strict-dynamicand friends follows what they've implemented. Test in the browsers you actually support.
Evidence and verification checklist
Don't take the release note as the test. Run the same checks on your current version and on 16.4.4 and compare.
Check 1: the raw HTML. This script fetches a route, pulls the nonce out of the response header and fails if any executable <script> tag doesn't carry it. Because res.text() waits for the whole streamed response, it also sees the scripts that arrive with the dynamic part.
// verify-nonce.mjs
// usage: node verify-nonce.mjs http://localhost:3000/ppr-check
const url = process.argv[2] ?? "http://localhost:3000/ppr-check";
const res = await fetch(url, { headers: { accept: "text/html" } });
const csp = res.headers.get("content-security-policy") ?? "";
const match = csp.match(/'nonce-([^']+)'/);
if (!match) {
console.error("FAIL: no nonce in the Content-Security-Policy header");
process.exit(1);
}
const nonce = match[1];
const html = await res.text();
const dataTypes = /type="application\/(ld\+)?json"/i;
const scripts = [...html.matchAll(/<script\b[^>]*>/gi)]
.map((m) => m[0])
.filter((tag) => !dataTypes.test(tag));
const missing = scripts.filter((tag) => {
const found = tag.match(/\bnonce="([^"]*)"/);
return !found || found[1] !== nonce;
});
console.log(JSON.stringify({ url, scripts: scripts.length, missing: missing.length }, null, 2));
if (missing.length > 0) {
for (const tag of missing) console.error("MISSING NONCE:", tag.slice(0, 160));
process.exit(1);
}
console.log("PASS: every executable script carries the response nonce");
Check 2: a real browser. The HTML check tells you what was sent. The browser tells you what was blocked. This Playwright spec listens for securitypolicyviolation events and also asserts that the dynamic hole actually rendered.
// tests/csp.spec.ts
import { test, expect } from "@playwright/test";
test("PPR route renders with zero CSP violations", async ({ page }) => {
const violations: string[] = [];
page.on("console", (msg) => {
if (msg.type() === "error" && msg.text().startsWith("CSP_VIOLATION")) {
violations.push(msg.text());
}
});
await page.addInitScript(() => {
document.addEventListener("securitypolicyviolation", (event) => {
console.error(`CSP_VIOLATION ${event.violatedDirective} ${event.blockedURI}`);
});
});
await page.goto("/ppr-check");
await expect(page.getByTestId("dynamic-hole")).toBeVisible();
await page.waitForLoadState("networkidle");
expect(violations).toEqual([]);
});
Check 3: compare versions. Same app, two installs:
# baseline: the 16.4.x you run today
npm install next@"$CURRENT_NEXT" && npx next build && (npx next start -p 3000 &) && sleep 5
node verify-nonce.mjs http://localhost:3000/ppr-check; npx playwright test tests/csp.spec.ts
kill %1 2>/dev/null || pkill -f "next start"
# patched
npm install [email protected] && npx next build && (npx next start -p 3000 &) && sleep 5
node verify-nonce.mjs http://localhost:3000/ppr-check; npx playwright test tests/csp.spec.ts
If the baseline already passes both checks, your setup wasn't hitting that path, which is good to know, and the upgrade is still a cheap patch bump. If the baseline fails and 16.4.4 passes, you've reproduced the bug and verified the backport in one go.
Where rollout or governance fails
The patch is the easy part. These are the ways I'd expect a CSP rollout to go wrong anyway:
- One app upgraded, the rest forgotten. In a monorepo it's easy to bump the app you tested and leave three others on the old 16.4 patch. Check every lockfile, not just the one in front of you.
-
'unsafe-inline'as a quick fix. When a script gets blocked, adding it feels like progress. It quietly undoes the reason you have a nonce. Fix the script, don't widen the policy. - A CDN caching nonce HTML. If a shared cache stores the HTML, every visitor gets the same nonce, and a "number used once" becomes a constant. HTML that carries a nonce shouldn't be shared cached.
-
Report only, forever.
Content-Security-Policy-Report-Onlyis the right way to start, so you see violations without breaking pages. It is the wrong place to stay. Put a date on flipping to enforce.
My take: treat the CSP check like a type check. It's boring, it runs on every PR, and the day it fails is the day it pays for itself.
| Situation | Reach for | Why |
|---|---|---|
| HTML rendered per request (SSR, PPR dynamic holes) | Nonce plus strict-dynamic
|
MDN recommends nonces for dynamically generated content |
| Fully static page whose inline scripts never change | Hashes | No per request value exists to put in the HTML |
| Third party script loaded by your own trusted script | strict-dynamic |
Trust flows from the nonce'd loader to what it loads |
| Brand new policy on a busy site | Report only first, then enforce | You see violations before users do |
Actionable next steps
- Bump to
[email protected]in every app that combines PPR with a nonce based CSP. - Add a small
/ppr-checkroute with one Suspense wrapped dynamic component. - Run
verify-nonce.mjsagainst a production build in CI. - Add the Playwright spec so blocked scripts fail the PR, not your users.
- If the policy is new, ship it report only, read the reports, then enforce.
FAQ
How does Next.js 16.4.4 CSP nonce PPR work?
Your proxy generates a nonce per request and sends it in the Content-Security-Policy header. Next.js reads it from the request headers and stamps it on the scripts it renders. With PPR, the static shell is prerendered and an inline resume bootstrap fills the dynamic holes at request time. 16.4.4 backports a fix so that bootstrap gets the nonce too.
When should developers adopt Next.js 16.4.4 CSP nonce PPR?
Now, if you run PPR with a strict nonce CSP. It's a patch release, so the risk is low, but verify it with the two checks above instead of assuming it.
Does 16.4.4 include the canary features?
No. The release notes say it carries specific backports and does not include everything on canary.
Is CSP Level 3 final?
Not yet. W3C's latest CSP Level 3 publication is a Working Draft, not a Recommendation.
Related reading: Next.js rendering patterns from CSR and SSR to Partial Prerendering and Next.js security hardening with middleware, Server Actions and CSP.
If you want a deeper look at how PPR splits a page into a static shell and dynamic holes, the rendering patterns piece above goes much further than this post.
If you want a Next.js app with streaming, a strict CSP and AI features wired up end to end, that is exactly the kind of Next.js work for AI products I take on.
Drop a comment if your setup looks different. I'm curious what CSP setups people are running with PPR in production.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.


