Drupal Commerce Security: CSP and Payment Compliance

About the Author

Mohammad Al-Fayoumi

Lead Software Engineer

Mohammed is a triple-certified Acquia engineer who specializes in continuous growth and delivery solutions for enterprise Drupal platforms. He helps organizations release changes frequently and safely, building the automated pipelines, test coverage, and observability that keep mission-critical platforms reliable as they scale.

FAQs

PCI DSS 4.0 does not name CSP by name, but it requires you to authorize every script on payment pages, ensure script integrity, and maintain an inventory of scripts (Requirements 6.4.3 and 11.6.1). A properly configured Content Security Policy header is the most practical way to meet these client-side security requirements, which is why it has become standard for compliant e-commerce sites.

Use Drupal's Security Kit (SecKit) module, which lets you configure CSP headers from the admin interface without custom code. It can add nonces to scripts automatically, define directives such as script-src and frame-ancestors, and send violation reports to an endpoint. For payment pages, apply a stricter policy that whitelists only your payment gateway and blocks object-src.

The critical directives are script-src (controls which scripts can run and protects cardholder data from injection), frame-ancestors (prevents clickjacking by controlling who can embed your page), object-src set to 'none' (blocks legacy plugin attacks), connect-src (stops data exfiltration to untrusted servers), and report-uri (logs violations for monitoring).

A nonce is a random value generated for each page request and attached to trusted inline scripts, so the browser runs only scripts carrying the correct nonce. PCI DSS requires verifying script integrity on payment pages, and nonces (or hashes) provide that assurance while letting you avoid the insecure 'unsafe-inline' setting.

A nonce authorizes specific inline scripts you control. strict-dynamic extends that trust: any script loaded by an already-trusted, nonce-carrying script is allowed to run without its own nonce. Combining 'nonce-{value}' with 'strict-dynamic' keeps payment pages secure while supporting modern scripts that load other scripts dynamically.

Join the conversation +