Add Content-Security-Policy (CSP) in Drupal 8 Updated on September 14, 2023 by InMotion Hosting Contributor 1 Minutes, 20 Seconds to Read The Content-Security-Policy Drupal module helps you configure a Header set Content-Security-Policy header to specify what sources your website should load scripts from – (e.g. your own website, embedded YouTube video, and analytics trackers). This forces supporting web browsers to ignore other external requests to mitigate cross-site scripting (XSS) and other code injection attacks. There are three parts to adding CSP for Drupal security: Add Content-Security-Policy Module Configure Report-Only Enforce CSP Maintain high performance and security with our Managed Drupal Hosting. Configure Content-Security-Policy Login to Drupal. Install the Drupal module using the Content-Security-Policy download link. Click Enable newly added modules. At the bottom, under Other, Check the box beside Content Security Policy. Click Install at the bottom. Click Configuration at the top. Under System, Click Content Security Policy. Report-Only “Report-Only” is the safest way to configure Content Security Policy without disrupting the website. This allows you to learn what elements wouldn’t be loaded if the policy was enabled via your web browser or auto-generated reports. View your website. Open your web browser’s Inspect Element feature. Check the Console tab to see what’s being blocked by CSP. Make changes as needed until all errors are removed. Enforce CSP Enforced policies will block unspecified scripts. Once all errors are removed, in your Content Security Policy module settings, click the Enforced tab. Click Enable ‘Enforced’. Add the options from the Report-Only section there. Click Save configuration. Test your site by unchecking the Report-Only option. Make changes as needed until all errors are removed. Enable HTTP Strict Transport Security (HSTS) in your .htaccess file or CloudFlare for more security. Share this Article InMotion Hosting Contributor Content Writer InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals! More Articles by InMotion Hosting Related Articles Finding 404 page not found errors in Drupal 7 Removing the site title in Drupal 8 Content Types in Drupal 8 Disabling user images for posts and comments in Drupal 8 How to add an image in Drupal 7 How to upload your custom logo in your Drupal 7 theme Setting custom logos in your Drupal 8 theme Fixing the “An unrecoverable error occurred” error in Drupal How to Make a Duplicate Drupal Site How to Install a New Theme in Drupal