PS PrestaShop Intermediate

Security Headers: security headers and CSP for PrestaShop 8 and 9

Install and configure Security Headers 2.0: setup assistant, Report-Only observation, nonce and CSP editor, services, reports, revisions, server export, HSTS and emergency stop.

Updated Module version 2.0.0

DataFirefly Security Headers sends the HTTP security headers of your shop from PrestaShop 1.7.8, 8 and 9: Content-Security-Policy with a random nonce on every page, HSTS, X-Frame-Options, X-Content-Type-Options, Referrer-Policy, Permissions-Policy and, optionally, COOP, COEP and CORP. A setup assistant analyzes the shop, a Report-Only observation period shows what the CSP would block before anything is blocked, and the go-live is guided, with an optional safety net. Everything is in Advanced Parameters > Security headers.

Security headers module dashboard: configuration score, status and rollout steps
Security headers module dashboard: configuration score, status and rollout steps

Installation

  1. In Modules > Module Manager, click Upload a module and send the ZIP file.
  2. Open Advanced Parameters > Security headers. Nothing is sent to your visitors until the setup assistant has been completed.
  3. Upgrading from 1.0 or 1.1: settings, tokens, services, revisions and recorded reports are kept, and the assistant is marked as done.

Dashboard

The header shows the status (no header, observation, test devices only, production with the CSP in Report-Only or blocking) and an indicative configuration score computed from the headers your visitors receive in production. The Rollout card follows the four steps: analysis and services, observation, production, blocking CSP.

Headers sent in production and actionable recommendations
Headers sent in production and actionable recommendations

The Recommendations list is computed from your settings, the last analysis, the reports and your modules: each item says what to do and opens the right section. The score uses this module’s own weighting: public scanners apply their own criteria and may grade differently. It is not a certification.

Setup assistant

  1. Analysis: the assistant reads the home page as a visitor gets it in production: current headers, inline scripts, inline event handlers (onclick=...), javascript: links and the external hosts per directive. Only the shop’s own pages can be analyzed.
Setup assistant, step 1: home page analysis (scripts, inline handlers, detected services)
Setup assistant, step 1: home page analysis (scripts, inline handlers, detected services)
  1. Services: the services detected on the page or among your modules (PrestaShop Checkout, DataFirefly Google Tag Manager, Product Videos…) are pre-selected.
Assistant, step 2: third-party services, pre-selected from the shop
Assistant, step 2: third-party services, pre-selected from the shop
  1. Level: Essential filters the domains but allows inline scripts; Recommended adds a random nonce on every page so that only the scripts written by the shop and those from allowed domains run, inline event handlers stay allowed; Strict adds 'strict-dynamic' and removes 'unsafe-eval' and inline handlers. On the Classic theme, 'unsafe-eval' is kept in every level: its Bootstrap 4 alpha library uses new Function().
Assistant, step 3: CSP protection level (Essential, Recommended, Strict)
Assistant, step 3: CSP protection level (Essential, Recommended, Strict)
  1. Observation: choose 3, 7, 14 or 30 days. Every visitor receives the CSP in Report-Only (their browsers report what it would block, nothing is blocked), or nothing at all if you choose Test devices only. An alert email address can be entered.

Going live

During the observation, browse the main pages (home, category, product, cart, checkout, account) with a test device and handle the reports. Then, in the assistant, choose the CSP mode once live: Blocking (recommended) or Report-Only for now, tick the confirmation and click Go live.

Guided go-live: blocking CSP and 48-hour safety net
Guided go-live: blocking CSP and 48-hour safety net

The optional safety net watches the 48 hours that follow a switch to blocking: if at least 25 new blocks come from 3 different visitors, the CSP goes back to Report-Only by itself, a revision is stored and you are emailed. Trade-off: reports are public, so fake reports sent from several addresses could also trigger it. Back to Report-Only on the dashboard does the same by hand at any time.

Test mode and test devices

  • Test devices (IP address in the list, or browser opened with the test link): every header, the CSP blocking whatever the chosen mode, HSTS capped at 5 minutes and never with preload.
  • Other visitors: the CSP in Report-Only, or nothing (Test devices only).

The IP list accepts IPv4, IPv6 and CIDR ranges. The test link marks a browser as a test device for 24 hours, useful on a phone; open the address with ?dfsh_test=off to stop. Behind a proxy or load balancer, enter its addresses in Trusted proxies: X-Forwarded-For is only read for those addresses, from right to left, so that a visitor cannot pretend to be a test device by writing the header himself.

CSP editor and nonce

Nonce options: random nonce per page, strict-dynamic, reflection guard, inline handlers
Nonce options: random nonce per page, strict-dynamic, reflection guard, inline handlers
  • Random nonce on every page: the module adds a new value to the scripts written by the shop and to the CSP, and removes 'unsafe-inline' from script-src. The theme is not modified.
  • Scripts that get the nonce: inline scripts and scripts from allowed hosts (recommended), or every script tag. A script tag from an unknown host is left without nonce: the browser reports it and you can allow its host in one click.
  • Reflection guard: a script tag whose text comes from the URL, a form or a cookie of the request never gets the nonce.
  • strict-dynamic: scripts loaded by a trusted script (Google Tag Manager, consent manager, payment SDK) are trusted too.
  • Allow inline event handlers adds script-src-attr 'unsafe-inline': onclick attributes cannot carry a nonce.
  • Nonce on style blocks (advanced) requires the nonce on <style> blocks; it breaks the libraries that inject styles, Tarteaucitron included.
Limit: a script tag stored in the database (product description, CMS page) is part of the page and gets the nonce. Keep PrestaShop’s HTMLPurifier option on and restrict who can edit content.

Each directive is edited as a list of sources: type a source and press Enter ('self', a domain such as https://cdn.example.com or *.example.com, a scheme such as data:, a keyword). Risky sources are highlighted, the domains added by the enabled services are shown in dashed outline, and the domains recently blocked appear under the directive with a button to add them.

Visual CSP editor per directive, with risk levels and suggested blocked domains
Visual CSP editor per directive, with risk levels and suggested blocked domains

For developers: the page nonce is available in Smarty as {$dfsh_nonce} and in PHP with DfSecurityHeaders::getNonce().

Third-party services

Each service adds the domains documented by its provider, with a link to that documentation: Stripe, PayPal (JS SDK, PrestaShop Checkout), Mollie, Google Tag Manager / GA4 and its preview mode, Google Ads, Meta Pixel, TikTok, Pinterest, Microsoft Clarity, Hotjar, Tarteaucitron.js, Cookiebot, Axeptio, YouTube, Vimeo, Google Fonts, Google Maps, reCAPTCHA, image CDNs (Cloudinary, imgix, Cloudflare Images, Bunny), Trustpilot and Crisp. Notes flag the constraints: PayPal needs COOP same-origin-allow-popups, Stripe does not support COEP, Tarteaucitron needs 'unsafe-inline' in style-src, GTM custom JavaScript variables need 'unsafe-eval'. Providers change their domains from time to time: the reports show what is still missing.

Ready-made third-party services (Stripe, PayPal, GTM/GA4, YouTube…), with a link to the provider documentation
Ready-made third-party services (Stripe, PayPal, GTM/GA4, YouTube…), with a link to the provider documentation

Reports

Browsers send their reports to the module (report-uri, and report-to with Reporting-Endpoints when the shop uses https). Reports are grouped by directive and blocked source, with the hits, the hits really blocked, the number of distinct visitors, the last page and script, and the first characters of the blocked code.

Aggregated CSP reports: hits, distinct visitors, pages and an "allow this domain" suggestion
Aggregated CSP reports: hits, distinct visitors, pages and an "allow this domain" suggestion
  • Enable turns on the service matching the domain, Allow adds the source to the right directive, Ignore moves the line to the Ignored list, where it keeps being counted silently.
  • Inline code, eval, data: in scripts and plain http scripts are never allowed in one click: the hint explains the right fix.
  • Anyone can send reports: a source seen by a single visitor is marked as such. Allow only what you recognize.
  • The endpoint accepts at most 120 reports per minute and per sender, 1,500 per minute for the shop, 64 KB per request; reports about pages that are not on the shop are dropped. No IP address is stored, URLs are kept without parameters, and groups not seen for the retention period (7 to 90 days) are purged.

Revisions

Every change keeps the previous settings with the date, the employee, the action and an optional note typed in the save bar. The last 30 versions are kept. Compare with current shows the differences setting by setting, two versions can be compared, and Restore in 1 click goes back to a version; the replaced state joins the history.

Revisions: comparison with the current settings and one-click rollback
Revisions: comparison with the current settings and one-click rollback

Server export

To let Apache or nginx send the static headers, copy the block of the Server export section, then enable Headers sent by the server in Settings: the module then only sends the CSP (the nonce and the reports need PHP).

Apache and nginx configuration export, without duplicates of the headers sent by PHP
Apache and nginx configuration export, without duplicates of the headers sent by PHP
  • No duplicates: Apache removes the copy sent by PHP (Header onsuccess unset), nginx hides it (fastcgi_hide_header).
  • HSTS is only sent over https (Apache expression, nginx map).
  • Keep a backup of the file and check the syntax with apachectl -t or nginx -t before reloading. In nginx, add_header in a location block replaces those of the server block.

Scanner

Analyze current headers requests a page of the shop from the server; Preview production shows the headers every visitor will get once test mode is off. The result lists each header with its points, the information leaks (X-Powered-By, server version), duplicates and the content of the page. Only the domains and ports of the shop can be requested, redirects to another site are not followed, and on hosts where the server cannot reach its own address (Docker, NAT) the analysis is done directly on the server.

Header scanner: indicative score, per-header details and page content (shop pages only)
Header scanner: indicative score, per-header details and page content (shop pages only)

HSTS and other headers

  • HSTS is only sent over https. Start short and increase step by step: a browser keeps it for the whole duration, even if you remove it. includeSubDomains forces https on every subdomain. preload is only sent with includeSubDomains and at least 1 year, and requires a confirmation: removal from the preload list takes months.
  • X-Frame-Options SAMEORIGIN for older browsers; modern ones apply the CSP frame-ancestors directive.
  • Referrer-Policy strict-origin-when-cross-origin; no-referrer can break YouTube embeds.
  • COOP, COEP, CORP are off by default: COOP same-origin cuts payment popups, COEP blocks iframes and files that do not opt in.
  • Back office: the optional back office preset sends HSTS (https), X-Frame-Options SAMEORIGIN, nosniff and Referrer-Policy, never a CSP.
HSTS settings with preload and includeSubDomains warnings, https only
HSTS settings with preload and includeSubDomains warnings, https only

Permissions-Policy: for each feature, Blocked, This site only (plus the origins you enter and those of the enabled services) or All sites. Only features known to current browsers are listed, so that no console error is produced.

Alerts

When the CSP blocks in production, each resource really blocked for the first time is added to a digest email: at most one email per hour and 12 per day, up to 5 recipients. Send a test email checks the setup.

Digest alert email: resources newly blocked by the CSP and what to do
Digest alert email: resources newly blocked by the CSP and what to do

Emergency stop and troubleshooting

Settings and safety: emergency stop by file, constant or command line
Settings and safety: emergency stop by file, constant or command line
  • If a header breaks the shop or the back office, any of these stops every header at once, even without access to the back office: create an empty file modules/dfsecurityheaders/EMERGENCY_OFF, or add define('_DFSH_EMERGENCY_OFF_', true); to config/defines_custom.inc.php, or run php bin/console prestashop:module disable dfsecurityheaders.
  • A page no longer works: Back to Report-Only, or restore the previous revision.
  • Page cache modules that answer at the very start of the request (DataFirefly Speed Pack) serve their pages before the module. Place the module first (Settings) to give them the headers; when such a cache prints a stored page itself, the module sends the same policy without nonce for that response so that nothing breaks.
  • A browser that received HSTS refuses http until the duration expires, even after the module is disabled.
Was this page helpful?

Still stuck? Contact support