Cluster 11 · PCI DSS 6.4.3 · Next.js · App Router Middleware

Next.js App Router Checkout PCI DSS 6.4.3 & 11.6.1: Dynamic CSP Nonce & Script SRI

Eliminate 'unsafe-inline' from Next.js App Router /checkout routes using per-request crypto.randomUUID() CSP nonces in middleware.ts, next/script strategies, and static SRI.

Zero Telemetry · Strict CSP (connect-src 'none') · WebCrypto

Checkout HTML & CSP Header Linter

PCI DSS v4.0.1 Req. 6.4.3 & 11.6.1
Compliance Note: Automated engineering & preparation guidance for PCI DSS v4.0.1 Req. 6.4.3 & 11.6.1 — verify final SAQ/ROC scope with your QSA or acquiring bank.
PCI DSS 6.4.3 & 11.6.1 Readiness Score
100 / 100 (A)
PCI 6.4.3 / 11.6.1 READY
External Scripts
2
Missing SRI/Pin
0
Evergreen PSPs
1
CSP Header
STRICT
Extracted Payment Page Script Inventory
Script / Block Category Status Required Control (SRI vs CSP/Nonce)
https://js.stripe.com/v3/ Evergreen PSP (Stripe.js v3) PASS
Evergreen PSP properly omits static SRI; enforce via strict CSP + Req. 11.6.1 header monitoring.
/_next/static/chunks/checkout-page.js First-Party Script ('self') PASS
Covered by first-party origin / nonce policy.
PCI-643-PSP-OK: 1 evergreen PSP loader(s) classified for CSP/nonce PASS
Detected Stripe.js v3 — correctly distinguished from static CDN SRI.
PCI-1161-REPORT-OK: CSP violation reporting directive present PASS
Supports continuous script-injection anomaly telemetry.
PCI-CSP-ALLOW-OK: All extracted HTML <script> origins match strict CSP script-src PASS
Zero unauthorized or unallowlisted script hosts.
Generated Strict Checkout CSP Template
default-src 'self'; script-src 'self' 'nonce-REPLACE_PER_REQUEST' https://js.stripe.com; style-src 'self'; img-src 'self' data: https:; connect-src 'self' https://api.stripe.com https://r.stripe.com; frame-src 'self' https://js.stripe.com https://hooks.stripe.com; object-src 'none'; base-uri 'self'; frame-ancestors 'none'; form-action 'self'; report-uri https://app.example.com/__csp-report
PCI DSS v4.0.1 Req. 6.4.3 Script Justification Matrix (CSV)
"Merchant Origin","Script Location / Tag","Category","Authorization Status","Required Control (SRI vs CSP/Nonce)","Current Integrity / Nonce","Business Justification (PCI DSS v4.0.1 Req 6.4.3)","Req 11.6.1 Monitoring Cadence"
"app.example.com","https://js.stripe.com/v3/","Evergreen PSP (Stripe.js v3)","Authorized","Strict CSP script-src host + 'nonce-...' + Req. 6.4.3 justification (Do NOT add static SRI)","nonce=nextNonce123","Core card tokenization and 3DS2 iframe loader (Stripe.js v3). Evergreen endpoint; SRI unsupported by Stripe — authorize via strict CSP script-src + nonce and monitor via Req. 11.6.1.","Automated weekly or continuous HTTP header + script hash check via CheckoutShield PCI (https://pci.runglab.dev)"
"app.example.com","/_next/static/chunks/checkout-page.js","First-Party Script ('self')","Authorized","CSP 'self' / 'nonce-...' (add SRI if served via CDN)","nonce=nextNonce123","First-party application checkout bundle hosted on merchant origin.","Automated weekly or continuous HTTP header + script hash check via CheckoutShield PCI (https://pci.runglab.dev)"
CheckoutShield PCI · Live Audit $49 PCI Compliance Pack

Monitor Live Checkout Scripts & Ship QSA-Ready Req. 6.4.3 + 11.6.1 Evidence

Need automated HTTP header + script tampering alerts (PCI DSS v4.0.1 Req. 11.6.1) or a tailored CSP, nonce middleware & script justification bundle? Run a free live scan on CheckoutShield PCI (https://pci.runglab.dev), order the $49 CheckoutShield PCI Pack via Creem, or request a PayPal invoice via [email protected].

Platform PCI DSS v4.0.1 Specifications & Controls

Control / Origin Hardened Pattern Req. 6.4.3 & 11.6.1 Rationale
Per-Request Nonce middleware.ts + headers().get('x-nonce') Eliminates 'unsafe-inline' on Next.js hydration scripts during SSR
Dynamic Rendering export const dynamic = 'force-dynamic' Required on /checkout so each request gets a fresh cryptographic nonce
External Utility Scripts <Script src=... integrity="sha384-..." crossOrigin="anonymous" /> Applies SRI to static external dependencies outside Stripe/PayPal
Stripe Evergreen Loader Load via @stripe/stripe-js or <Script nonce={nonce}> Never attach static integrity= to js.stripe.com/v3/

Next.js App Router — Per-Request Checkout Nonce Middleware (middleware.ts)

middleware.ts
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";

export function middleware(request: NextRequest) {
  const nonce = Buffer.from(crypto.randomUUID()).toString("base64");
  const csp = [
    "default-src 'self'",
    `script-src 'self' 'nonce-${nonce}' 'strict-dynamic' https://js.stripe.com`,
    "style-src 'self'",
    "img-src 'self' data: https:",
    "connect-src 'self' https://api.stripe.com https://r.stripe.com",
    "frame-src 'self' https://js.stripe.com https://hooks.stripe.com",
    "object-src 'none'",
    "base-uri 'self'",
    "frame-ancestors 'none'",
    "report-uri /api/csp-report"
  ].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: ["/checkout/:path*", "/billing/:path*"]
};

Next.js App Router Checkout Layout Passing Nonce to <Script>

app/checkout/layout.tsx
import { headers } from "next/headers";
import Script from "next/script";

export const dynamic = "force-dynamic";

export default async function CheckoutLayout({ children }: { children: React.ReactNode }) {
  const nonce = (await headers()).get("x-nonce") ?? undefined;
  return (
    <>
      {children}
      <Script src="https://js.stripe.com/v3/" nonce={nonce} strategy="afterInteractive" />
    </>
  );
}

Step-by-Step Hardening & Key Insights

  1. Create middleware.ts scoped to /checkout/:path* and /billing/:path* generating a fresh random Base64 nonce per request.
  2. Read x-nonce via headers() inside your dynamic checkout Server Component layout and pass it to <Script>.
  3. Avoid loading analytics/tag managers in the /checkout layout tree entirely.
  4. Verify zero 'unsafe-inline' or 'unsafe-eval' directives in the live response using CheckoutShield PCI.
  • Static next.config.mjs headers cannot rotate nonces per request; Next.js requires Middleware + force-dynamic rendering on checkout routes for strict nonce-based CSP.
  • Using 'strict-dynamic' alongside 'nonce-...' lets trusted Next.js chunk loaders fetch dynamic webpack/turbopack chunks without whitelisting broad CDNs.
  • Keep checkout pages in a separate Next.js route group without global analytics wrappers so marketing tags cannot accidentally render alongside card elements.

Common Checkout Audit Pitfalls to Avoid

  • Reusing a static cached HTML page with an old nonce — browsers block hydration scripts if cached HTML nonce mismatches the response CSP header.
  • Keeping Google Tag Manager inside RootLayout instead of conditionally excluding it from /checkout.
  • Using 'unsafe-eval' in production (only needed in Next.js dev mode, never production builds).

More PCI DSS v4.0.1 & SRI Checkout Guides

← Back to PCI & SRI Checker Hub · Cluster 4: Security Headers & CSP → · Cluster 7B: Stripe/Creem Webhook HMAC → · CheckoutShield PCI Live Scan → · $49 PCI Compliance Pack →

Frequently Asked Questions

Does Next.js support experimental Subresource Integrity (SRI) on self-hosted chunks?

Next.js webpack experimental.sri.algorithm = 'sha384' can sign static chunks, while dynamic App Router nonces in middleware.ts cover both inline hydration and dynamic chunks cleanly.

Why does 'strict-dynamic' work well with Next.js checkout pages?

Once the initial bootstrap script carries the matching per-request nonce, 'strict-dynamic' authorizes dynamically imported _next/static chunks loaded by Next.js itself while ignoring host allowlists and 'unsafe-inline'.

How do I test my deployed Next.js checkout headers for Req. 11.6.1?

Scan your live checkout URL on CheckoutShield PCI (https://pci.runglab.dev) or paste your rendered HTML + CSP header into the linter above.