The Content Security Policy (CSP) header is a critical component for achieving PCI DSS compliance, particularly for payment pages, as it helps meet requirements for authorizing and ensuring the integrity of scripts. In modern e-commerce environments, especially when using Drupal Commerce, implementing robust CSP rules is not just a best practice. It’s a requirement for maintaining customer trust and meeting security standards.
PCI DSS (Payment Card Industry Data Security Standard) is a global set of security requirements designed to ensure that all organizations handling credit card data maintain a secure environment. Version 4.0 strengthens requirements around web application security, emphasizing measures to protect against client-side attacks like cross-site scripting (XSS) and unauthorized script execution.
A Content Security Policy is an HTTP response header that controls which resources (such as JavaScript, CSS, images, or fonts) a web page is allowed to load. By defining strict rules for where scripts and other assets can originate, CSP reduces the risk of malicious content execution in browsers.
In a Drupal Commerce site handling online payments, attackers can target checkout or payment pages with injected scripts to capture sensitive payment details. PCI DSS specifically addresses this risk, requiring site owners to: Authorize all scripts running on payment pages. Ensure the integrity of these scripts through mechanisms like nonces or hashes. Implement policies that prevent unauthorized script execution. A properly configured CSP header ensures only trusted scripts are executed, blocking any unauthorized or tampered scripts. This directly supports PCI DSS requirements for protecting payment page integrity.
Drupal provides the Security Kit module, which offers a simple way to configure CSP headers directly within your site’s admin interface or via custom module code. This module supports: Adding nonces automatically to scripts. Defining CSP rules (script-src, script-src-elem, etc.). Sending violation reports to a specified endpoint.
Content-Security-Policy: script-src 'self' https://trusted-payments.example.com 'nonce-abc123';
frame-ancestors 'self' https://trusted-partner.example.com;
Purpose: Controls which sites can embed your pages in <iframe>, <frame>, <object>, etc.
PCI DSS relevance: Protects payment pages from being embedded into malicious overlays.
Best practice:
frame-ancestors 'self' https://trusted-partner.example.com;
Purpose: Restricts sources for <object>, <embed>, and <applet> elements.
PCI DSS relevance: Prevents the execution of untrusted plugins, which are a high-risk vector.
Best practice:
object-src 'none';
Purpose: Controls where scripts can connect via XHR, WebSocket, EventSource.
PCI DSS relevance: Prevents exfiltration of sensitive cardholder data to untrusted servers.
Best practice:
connect-src 'self' https://api.trusted-payments.example.com;
Purpose: Sends CSP violation reports to a specified endpoint.
PCI DSS relevance: Enables detection of policy violations and possible attacks.
Best practice:
report-uri /report-csp-violation;
script-src 'self' 'nonce-{nonce-value}'; object-src 'none';
Content-Security-Policy: script-src 'self' 'nonce-xYz123';
Content-Security-Policy: script-src 'self' 'nonce-{nonce}' https://secure.paymentgateway.com https://www.googletagmanager.com;
Content-Security-Policy: script-src 'nonce-{nonce}' 'strict-dynamic' https:;
Content-Security-Policy: script-src 'self' 'nonce-{nonce}' https://secure.paymentgateway.com; object-src 'none';
Content-Security-Policy: script-src 'nonce-{nonce}' 'self'; report-uri /csp-report-endpoint;
Content-Security-Policy: script-src 'nonce-{generated-nonce}' 'strict-dynamic' https://secure.paymentgateway.com https://www.googletagmanager.com; object-src 'none'; base-uri 'self'; frame-ancestors 'none';
Implementing CSP headers in Drupal Commerce is an essential step toward meeting PCI DSS compliance. Using Drupal’s Security Kit module, site owners can configure robust CSP rules, add nonces automatically, and protect payment pages against unauthorized scripts. By combining nonces, trusted domain whitelisting, and modern CSP directives like strict-dynamic, you can achieve strong client-side security without sacrificing site functionality.