Content Security Policy for Checkout Page: 6 Mistakes

Content Security Policy for Checkout Page: 6 Mistakes

A content security policy for a checkout page is not an anti-XSS measure. It can be one, and most guides stop there, but on a live payment page the adversary is rarely someone injecting a script tag through a query string. The adversary is a script you already asked for, from a supplier you already trust, modified at source. Policies that pass an audit, break nothing and still let a skimmer run are common. Six of them turn up again and again.

What a checkout page policy actually has to block

Three routes put skimmer code on a payment page. A third-party supplier is compromised and its script changes under you. First-party code on the payment path is edited, usually after someone gets admin or server access. Or the platform itself is unpatched and the injection is done at scale by a script that does not care who you are. Sansec reported in September 2020 that roughly 2,000 Magento 1 stores were skimmed over a single weekend, after support for that version ended. No header fixes that third route. Say so out loud before anyone treats CSP as the whole answer.

Advice written around cross-site scripting misses the first route entirely. Ticketmaster UK, June 2018, is the reference case: the skimmer arrived inside a compromised chat supplier’s JavaScript, hosted on a domain the site had every reason to list. The ICO fined Ticketmaster £1.25m in November 2020. A host allowlist naming that supplier would have let the script execute without a single warning. British Airways the same year went the other way, with code already on the payment path quietly modified. Two routes in, neither of them a reflected payload.

So a payment-page policy has two jobs. Control what executes. Control where data can be sent. Most policies do the first and forget the second.

Keep expectations honest about the rest of the stack. Subresource Integrity pins the content of a named file. Hosted payment fields move the card inputs out of your page altogether. Change detection watches the page for modification. CSP is the enforcement layer under all three, not a replacement for any of them. If you are starting from nothing, build the policy first using a working setup for a checkout page policy, then come back to the failure modes below.

Mistake 1: allowlisting a whole CDN instead of a specific file

Script-src https://cdn.jsdelivr.net permits any file any person has ever published to a public CDN. So does *.cloudfront.net, which covers every CloudFront distribution in existence, including the attacker’s. On shared infrastructure, a host allowlist is close to no policy at all.

Tighten to full paths where the supplier publishes stable URLs. Better, stop allowlisting hosts for your own scripts and move to nonces or hashes, which bind execution to the exact script rather than its address. Pair supplier scripts with integrity hashes that pin the file contents so a modified version is refused even from the right domain.

The trade-off is real and it arrives on a Tuesday morning. SRI and CSP pull against each other in practice: hash-pinning gives you certainty, and it gives you a dead checkout the moment a supplier ships a reminified build. Decide in advance where the hashes live, who gets paged when the script stops loading, and how quickly a new hash can be released. If the answer is “a fortnightly deploy train”, do not pin that script.

Before any of that, ask which third parties belong on the payment page at all. A chat widget has no business on the page where card numbers are typed. That question is also requirement 6.4.3 of PCI DSS 4.0, which wants an inventory of every script on the payment page with a written justification for each one. The shortest policy is the one with the fewest entries to justify.

Mistake 2: keeping ‘unsafe-inline’ so the theme keeps working

Themes are full of inline handlers, and the fastest way to ship a policy is to allow them. That single keyword hands an attacker who can write one line into a checkout template everything they need. The skimmer no longer has to be hosted anywhere. It runs from the page.

On server-rendered platforms, generate a fresh nonce for every response and attach it to the script tags you control. A nonce baked into a static file or reused across requests is worthless, because the attacker can read it in the markup and copy it into their own tag. Where output is cached at the edge, make sure the cache varies or the nonce is injected after the cache, or you will be serving yesterday’s nonce to everyone.

Strict-dynamic is the sensible way out of a long allowlist: trusted scripts may load their own dependencies, and host entries are ignored by browsers that understand it. Older browsers ignore strict-dynamic instead, which is why the usual pattern keeps a host allowlist and ‘unsafe-inline’ in the same policy as fallbacks, both ignored by any browser that honours the nonce.

Do the unglamorous part before enforcement day. Grep the payment templates for onclick and friends, find the analytics snippets that call eval or build functions from strings, and fix or replace them. Tag manager containers are the usual offender here, and worth auditing separately before you lock the policy down.

Mistake 3: locking down scripts and leaving the exfiltration routes open

A skimmer has to get the data out. It can POST with fetch or XHR. It can set new Image().src to a collection endpoint with the card number in the query string. It can open a WebSocket, call navigator.sendBeacon on page unload, or simply rewrite the form’s action so the browser posts the whole thing somewhere else.

Closing those routes takes directives most policies never set: connect-src for fetch, XHR, beacons and sockets, img-src for pixel exfiltration, form-action for where a form may post, base-uri to stop an injected <base> tag redirecting every relative URL on the page, and frame-src plus frame-ancestors for what you embed and who may embed you.

Here is the gap that undoes otherwise tidy policies: default-src does not fall back to form-action, base-uri, frame-ancestors or sandbox. A policy of default-src ‘self’ and nothing else leaves a form free to post to any host on the internet. The MDN reference for each directive states which ones inherit and which do not, and it is worth checking line by line rather than assuming.

For a hosted-fields checkout, the enforcement policy is short. Something close to this shape, with the provider endpoints taken from their current documentation rather than from this page:

  • Script-src ‘nonce-RANDOM’ ‘strict-dynamic’ https:
  • Connect-src ‘self’ plus the provider’s API endpoint
  • Frame-src limited to the provider’s iframe origin
  • Img-src ‘self’ data: and nothing speculative
  • Form-action ‘self’ plus the provider, if it needs a redirect
  • Base-uri ‘none’, object-src ‘none’, frame-ancestors ‘none’

Stripe and Adyen both publish the hosts their libraries need. Check them at release time; providers do move endpoints.

Mistake 4: running report-only forever with nobody reading the reports

Starting with a CSP report-only checkout header is the right call on a live payment page. It is also the easiest place to get stuck. Report-only blocks nothing. A policy that has been in report-only for eleven months is a document, not a control. Set an enforcement date when you ship the first report-only header and work backwards from it.

The reports will be noisy. Browser extensions inject scripts into every page, some mobile ISPs still rewrite content, and in-app browser wrappers generate violations against origins you have never heard of. Triage by frequency and origin: anything appearing across many sessions from a host tied to your own build is yours to fix, and the long tail of one-off extension noise is not. Expect to spend a couple of weeks on this, not an afternoon.

Use report-to with the Reporting API and keep report-uri alongside it for older browsers. Then give the queue an owner and a weekly slot, because a report endpoint nobody opens is worse than none at all: it looks like coverage.

One nuance catches assessors and engineers alike. Violation reports only fire when something breaks the policy. A supplier script you have already allowlisted, modified at source, generates exactly zero reports and runs exactly as instructed. Report collection on its own does not satisfy requirement 11.6.1, which asks for detection of unauthorised modification to the payment page. That is what hashes, integrity monitoring or one of the change-detection methods compared here are for.

Mistake 5: assuming the policy covers your payment provider’s iframe

Your header governs your page. Inside the provider’s iframe, the provider’s own origin sets its own policy, and nothing you write reaches it. This is usually a good thing, because it means card inputs sitting in hosted payment fields are out of reach of any script running on the parent page.

The parent page is still yours to defend, and still worth defending. Script on your page cannot read the iframe’s inputs, but it can remove the iframe and draw a convincing replica in its place. Customers will not notice. The fields look the same because they are the same, visually.

Three directives close that off. Pin frame-src to the provider origin so no other frame can load. Set base-uri ‘none’ so relative URLs cannot be retargeted. Restrict form-action to ‘self’ and the provider, so a counterfeit form cannot post anywhere useful even if it is drawn.

Check how the policy is delivered, too. A <meta> tag silently drops frame-ancestors, sandbox and reporting directives. CDN and edge configurations sometimes strip or overwrite response headers, so verify the header on the live checkout rather than on staging. And on a fully hosted checkout where the provider serves the page, you do not control the response at all; defend the pages that lead into it instead.

Mistake 6: treating the policy as finished once it ships

Policies rot. A marketing team adds a pixel through the tag manager, an A/B tool goes live, a partner integration lands, and none of those people have ever seen the header. Some of it breaks and gets reported. Some of it gets added to the allowlist by whoever is quickest, with no justification recorded. Six months later the payment page allows fourteen origins and nobody can say why for five of them.

Supplier rotation causes the sharper failures. A payment or chat provider moves to a new host, sometimes with short notice, and the checkout stops working until the header is updated. Know who can push a header change out of band and how long it takes. If the answer involves a change advisory board and a Thursday, write the fallback plan now.

Tie the header to the paperwork rather than keeping two lists. The PCI DSS script management requirements in 6.4.3 and 11.6.1 have been mandatory since 31 March 2025, and 6.4.3 already asks for the inventory and justification your allowlist implies. Make the policy file the inventory, with a comment per entry naming the supplier, the business reason and the owner. The PCI Security Standards Council document library holds the current text if you need the exact wording.

The review routine does not need to be elaborate. One named owner for the header. A trigger list: any new third-party script, any supplier domain change, any platform upgrade that touches the checkout template. And a pre-release check that loads the real checkout in a browser with the console open, confirms the header is present and enforcing, and confirms no new origins have appeared. Ten minutes a release.

The short version

A content security policy for a checkout page earns its place when it does two things: restricts execution to scripts you can name by nonce or hash, and restricts where data can be sent through connect-src, img-src, form-action and base-uri. Host allowlists on shared CDNs, ‘unsafe-inline’, a report-only header nobody reads, and an allowlist that drifts after launch all produce a policy that passes inspection and stops nothing. Pair it with integrity hashes and change detection, because a modified script you already permitted will never report itself.

Frequently Asked Questions

Does a content security policy on the checkout page stop Magecart skimmers?

It stops some of them. A tight policy blocks script from hosts you have not approved and blocks exfiltration to collection endpoints you have not approved, which breaks a large share of commodity skimmers. It does not stop a modified version of a script you already allowlisted, which is how the better-known incidents actually happened.

Should I start with CSP in report-only mode on a live payment page?

Yes. Content-Security-Policy-Report-Only lets you see what the policy would break without breaking anything, which matters on the page that takes the money. Set an enforcement date at the same time, because report-only blocks nothing and the half-finished state is where most of these projects die.

Which CSP directives matter most on a checkout page?

Script-src with nonces or hashes, connect-src, img-src, form-action, base-uri, frame-src and frame-ancestors, plus object-src ‘none’. The last four are the ones most often missed, and form-action, base-uri and frame-ancestors do not inherit from default-src, so they must be written out explicitly.

Do I still need CSP if my card fields sit in a payment provider’s iframe?

Yes. Hosted fields keep card data out of reach of page-level script, but the surrounding page is still yours, and script on it can replace the iframe with a convincing fake. Pinning frame-src to the provider, locking base-uri to ‘none’ and restricting form-action is what prevents the substitution.

Does a content security policy satisfy PCI DSS 6.4.3 and 11.6.1?

It contributes to both and completes neither. The allowlist supports the 6.4.3 inventory if each entry carries a justification and an owner. For 11.6.1 you need detection of unauthorised modification, and since an allowlisted script changing at source produces no violation report, that detection has to come from integrity hashes, monitoring, or one of the cheaper change-detection approaches.