Cluster 11 · PCI DSS 6.4.3 · Cloudflare · HTMLRewriter Nonce

Cloudflare Workers PCI DSS 6.4.3 & 11.6.1: HTMLRewriter Nonce Injection & CSP Reporting

Inject per-request cryptographic nonces into legacy origin checkout HTML at the Cloudflare edge using HTMLRewriter, strip unauthorized third-party tags, and log CSP violation reports for Req. 11.6.1.

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.
https://cdn.example.com/[email protected] Static External Script PASS
Pinned static script with valid SRI hash and crossorigin="anonymous".
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-643-SRI-OK: All 1 static third-party script(s) carry valid SRI + crossorigin PASS
Cryptographic script integrity verification active.
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 https://cdn.example.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://edge-pay.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"
"edge-pay.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=cfEdgeNonce77","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)"
"edge-pay.example.com","https://cdn.example.com/[email protected]","Static External Script","Authorized","SRI (sha384) + crossorigin=""anonymous""","sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC","Pinned external script verified via Subresource Integrity (Req. 6.4.3).","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
Edge Nonce Generation crypto.getRandomValues(new Uint8Array(16)) Mints a fresh 128-bit nonce per request without modifying legacy origin backends
HTMLRewriter Script Tagging el.setAttribute('nonce', nonce) Attaches nonce to authorized scripts before streaming response to the browser
Edge Tag Stripping el.remove() on unauthorized trackers Blocks rogue marketing pixels on /checkout even if CMS admins add them
CSP Violation Collector POST /__csp-report Worker route Satisfies PCI DSS Req. 11.6.1 alerting when an unauthorized script attempts execution

Cloudflare Worker — Per-Request CSP Nonce & HTMLRewriter Guard

pci-edge-guard-worker.ts
export default {
  async fetch(request: Request): Promise<Response> {
    const url = new URL(request.url);
    if (url.pathname === "/__csp-report" && request.method === "POST") {
      // Forward to SIEM / PagerDuty / Slack webhook in production
      return new Response(null, { status: 204 });
    }

    const res = await fetch(request);
    if (!url.pathname.startsWith("/checkout") || !res.headers.get("content-type")?.includes("text/html")) {
      return res;
    }

    const bytes = new Uint8Array(16);
    crypto.getRandomValues(bytes);
    const nonce = btoa(String.fromCharCode(...bytes));

    const rewritten = new HTMLRewriter()
      .on("script", {
        element(el) {
          const src = el.getAttribute("src") || "";
          if (/googletagmanager\.com|connect\.facebook\.net/i.test(src)) {
            el.remove();
            return;
          }
          el.setAttribute("nonce", nonce);
        }
      })
      .transform(res);

    const headers = new Headers(rewritten.headers);
    headers.set(
      "Content-Security-Policy",
      [
        "default-src 'self'",
        `script-src 'self' 'nonce-${nonce}' https://js.stripe.com`,
        "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 https://${url.host}/__csp-report`
      ].join("; ")
    );
    return new Response(rewritten.body, { status: rewritten.status, headers });
  }
};

Cloudflare Pages _headers — Strict Baseline for Static Checkout Shells

_headers
/checkout/*
  Content-Security-Policy: default-src 'self'; script-src 'self' https://js.stripe.com; style-src 'self'; connect-src 'self' https://api.stripe.com; frame-src 'self' https://js.stripe.com https://hooks.stripe.com; object-src 'none'; base-uri 'self'; frame-ancestors 'none'; report-uri /__csp-report
  X-Content-Type-Options: nosniff
  X-Frame-Options: DENY
  Referrer-Policy: strict-origin-when-cross-origin

Step-by-Step Hardening & Key Insights

  1. Route /checkout* traffic through a Cloudflare Worker using HTMLRewriter when your origin CMS cannot emit dynamic nonces.
  2. Generate a 128-bit cryptographic nonce per request and inject nonce= onto authorized script tags (while removing trackers).
  3. Set a strict Content-Security-Policy header including report-uri / report-to.
  4. Schedule automated external header/script verification via CheckoutShield PCI (https://pci.runglab.dev).
  • Cloudflare HTMLRewriter lets teams retrofit strict nonce-based CSP and script allowlists onto legacy monoliths in under 50 lines of TypeScript.
  • Note: blind-attaching nonces to EVERY <script> tag on a page would authorize an attacker-injected tag from the origin! Instead, allowlist only known script srcs or attach SRI hashes on static assets and inspect origin HTML changes under Req. 11.6.1.
  • Pairing Cloudflare Page Shield with CheckoutShield PCI covers both client-side CSP telemetry and external header/DOM drift audits.

Common Checkout Audit Pitfalls to Avoid

  • Caching HTML responses that contain per-request nonces inside Cloudflare CDN cache (always set Cache-Control: private, no-store on nonced checkout HTML).
  • Attaching nonces blindly to unknown inline scripts instead of maintaining an explicit hash/src allowlist.
  • Using Cloudflare Zaraz or Auto-Minify scripts on /checkout without testing CSP/SRI interactions.

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 Cloudflare Page Shield cover everything in PCI DSS Req. 6.4.3 and 11.6.1?

Page Shield monitors scripts and CSP reports on Cloudflare-proxied sites, while you still need a documented Req. 6.4.3 script justification matrix, strict CSP/SRI enforcement, and verified header baseline.

Why must nonced checkout HTML never be cached at Cloudflare edge?

If two users receive cached HTML with an identical nonce, or if a cached CSP header mismatches the HTML nonce, either security weakens or scripts fail to run.

Can I use Cloudflare Pages _headers without a Worker?

Yes for fully static checkout shells using external hashed scripts (SRI) and zero inline scripts — use Cluster 4 (/security-headers/) plus our SRI Generator above.