Security headers and a Content-Security-Policy for your store
Response headers are the cheapest hardening a store can get: a handful of lines that stop browsers from guessing file types, stop other sites framing your checkout, keep referrer data private and, with a Content-Security-Policy, limit where scripts may load from. TitanCart gives you the first three with one switch. The Content-Security-Policy it deliberately leaves to you and your host, because a correct policy has to list every outside service your store uses, and getting that wrong blocks checkout. This article covers the switch, what the plugin needs from a policy, every outside origin TitanCart and the Prism theme load, a baseline policy to start from in report-only mode, and how to add headers on Apache, nginx and Plesk.
1. The built-in switch
Open TitanCart → Settings → General Settings → Security and find the Security Headers group (it is in Lite and Pro).
- Send recommended security headers — off by default. The hint explains: “Adds safe, content-independent HTTP response headers that harden the store against clickjacking and MIME-type sniffing. Off by default — enable to apply the recommended set below. If your host or another plugin already sends one of these headers, TitanCart leaves the existing value untouched.”
- X-Content-Type-Options: nosniff — on. Browsers must trust the declared content type instead of sniffing the body.
- X-Frame-Options: SAMEORIGIN — on. Other sites cannot put your store in a frame (the clickjacking defence). Turn it off only if you deliberately embed the storefront in an iframe on another domain.
- Referrer-Policy: strict-origin-when-cross-origin — on. Same-site requests get the full referring URL; other sites only get your bare origin.
- Apply headers to — Storefront and admin (default), Storefront only or Admin only. WordPress already frames-protects wp-admin on its own, which is why the hint says the admin panel benefits “regardless of this choice”.
Tick the master switch, leave the three headers on and save. Nothing on the page can break: these three headers do not depend on what the page contains. TitanCart adds them to every front-end and admin response (not to cron or AJAX calls) and skips any header that PHP has already set, so a security plugin that sends its own X-Frame-Options wins. Headers added by the web server itself are not visible to that check, so pick one place for each header: the switch, or the server configuration in section 5, not both.
Independently of the switch, protected downloadable files are always delivered with nosniff, and the two SSL / Secure Connections settings above this group redirect plain-HTTP visits to HTTPS. TitanCart sends no HSTS, no Content-Security-Policy and no Permissions-Policy header; those belong to the server (sections 4 and 5).
2. Check what you are sending
Run this from any terminal against a storefront page and look for the three lines:
curl -sI https://your-store.com/shop/ | grep -i -E "x-content-type|x-frame|referrer-policy"
Repeat for /wp-admin/ (expect a redirect to the login page, with the headers on it). Then run your domain through Mozilla’s HTTP Observatory at developer.mozilla.org/en-US/observatory for a scored report; the three headers plus HTTPS already lift the grade, and the remaining findings are the CSP and HSTS items below.
3. Why the Content-Security-Policy is yours, not the plugin’s
A CSP tells the browser which origins may supply scripts, styles, frames, images and connections for a page. Anything not listed is blocked. The list depends on things only you know: your theme, your other plugins, your analytics, and above all your payment gateway, whose card fields are scripts and frames from the gateway’s own domain. A policy shipped inside TitanCart that was strict enough to be worth having would block the gateway for some stores, so TitanCart does not send one, exactly as WordPress itself does not. What TitanCart does is tell you precisely what it needs (this section) so you can write the policy once.
What TitanCart’s own pages need:
'unsafe-inline'for bothscript-srcandstyle-src. The storefront templates carry inline scripts and inline styles (as does WordPress admin), and this release has no nonce support to replace that keyword. A policy without it breaks the cart, checkout and account pages.- No
'unsafe-eval': TitanCart’s JavaScript, including the admin app, never evaluates strings as code. If a tool reports thatevalis needed, another plugin or script is the source. - Images, fonts and scripts come from your own domain (
'self'). Icons are a self-hosted font. Product images are in your Media Library unless you offload uploads to a CDN, in which case add that host toimg-src.
Outside origins, by feature. Only what you use needs listing; each row loads on the page only under the condition shown.
| Feature (when it loads) | Origin | Directive |
|---|---|---|
| Stripe (a Stripe method with a publishable key; checkout page) | https://js.stripe.com |
script-src; Stripe’s guide also asks for frame-src https://js.stripe.com https://hooks.stripe.com and connect-src https://api.stripe.com |
| Authorize.net (Pro; login ID and public client key set) | https://js.authorize.net, and https://jstest.authorize.net while in sandbox |
script-src |
| Square (Pro; application and location ID set) | https://web.squarecdn.com, and https://sandbox.web.squarecdn.com in sandbox |
script-src; the card field is a Square frame, so Square’s guide lists the same hosts under frame-src and its API hosts under connect-src |
| Venmo (Pro; a Venmo method with a client ID) | https://www.paypal.com |
script-src, plus PayPal’s frame-src and connect-src hosts from its guide. Standard PayPal needs nothing: the buyer is sent to PayPal and back |
| Google reCAPTCHA (Bot Protection extension on with Provider set to reCAPTCHA v2 or v3, on pages that show a protected form) | https://www.google.com, https://www.gstatic.com |
script-src; frame-src https://www.google.com for the widget |
| Cloudflare Turnstile (Bot Protection extension on with Provider set to Cloudflare Turnstile, on pages that show a protected form; 0.2.78 and later) | https://challenges.cloudflare.com |
script-src and frame-src, per Cloudflare’s own CSP guidance. Only the selected provider’s script loads, so a Turnstile store does not need the Google hosts and vice versa |
| Address autocomplete (Checkout setting on, with an API key; checkout and account pages) | https://maps.googleapis.com |
script-src; Google’s guide adds its maps and places hosts under connect-src and img-src |
| Google and Facebook sign-in (Pro Social Login, My Account page) | https://accounts.google.com, https://connect.facebook.net |
script-src; each provider’s guide adds its frame-src and connect-src hosts |
| Product videos (a product with a video) | https://www.youtube.com, https://player.vimeo.com; thumbnails from https://img.youtube.com |
frame-src; img-src for the thumbnail. A self-hosted or other-CDN video URL goes straight into the player frame, so list that host too |
| TitanCart Prism theme (every page) | https://cdn.jsdelivr.net (Bootstrap, Bootstrap Icons, Swiper), https://fonts.googleapis.com, https://fonts.gstatic.com, https://placehold.co (fallback images on the default homepage until you set your own) |
script-src and style-src for jsdelivr; style-src for Google Fonts; font-src for fonts.gstatic.com and jsdelivr; img-src for placehold.co |
| Admin app (Pro; the Extensions Marketplace tab) | https://market.titancart.io |
connect-src, for the wp-admin policy only |
Rows marked “guide” refer to each provider’s own CSP documentation: TitanCart loads the script origin shown, and the provider’s script then opens frames and connections to further hosts of theirs that only their documentation lists authoritatively. Confirm those against the provider before you enforce. Your own additions (analytics, chat widgets, a CDN, other plugins) come on top; TitanCart itself loads no analytics.
4. A baseline policy, in report-only mode first
Start with Content-Security-Policy-Report-Only. The browser evaluates the policy and logs what it would block to the developer console without blocking anything, so you can shop, pay and sign in on the live store and fix the list before enforcing. Below is a baseline for a Pro store running the Prism theme with Stripe, Google reCAPTCHA and YouTube videos; delete the rows you do not use and add your own. If your bot-protection provider is Cloudflare Turnstile, put https://challenges.cloudflare.com in script-src and frame-src in place of the two Google hosts.
Content-Security-Policy-Report-Only:
default-src 'self';
script-src 'self' 'unsafe-inline' https://js.stripe.com https://www.google.com https://www.gstatic.com https://cdn.jsdelivr.net;
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://cdn.jsdelivr.net;
font-src 'self' https://fonts.gstatic.com https://cdn.jsdelivr.net;
img-src 'self' data: https://img.youtube.com https://placehold.co;
frame-src https://js.stripe.com https://hooks.stripe.com https://www.google.com https://www.youtube.com https://player.vimeo.com;
connect-src 'self' https://api.stripe.com;
object-src 'none';
base-uri 'self';
form-action 'self';
frame-ancestors 'self';
upgrade-insecure-requests
Notes on the lines:
frame-ancestors 'self'is the modern form of X-Frame-Options and overrides it where both are present. If you embed the storefront elsewhere, list that site here.form-action 'self'is right for Stripe, Square and Authorize.net, which post from scripts. For standard PayPal and any other redirect gateway, keep it but expect the redirect itself to be allowed: form-action governs form submissions, not script-driven navigation. Watch the console on a PayPal test order.- Keep
'unsafe-inline'on both script and style lines (section 3). Do not add'unsafe-eval'unless a report names it. - Add a
report-toorreport-uriline if you use a reporting service; otherwise the browser console is enough while you tune.
Walk the store with the console open: home, a category, a product with a video, add to cart, checkout with a test card (see Going live: switching gateways from test to live for test mode), sign in with Google if you offer it, and the admin product editor. Each red “Refused to load” line names the directive and the origin to add. When a full test order goes through with no reports, rename the header to Content-Security-Policy.
HSTS (Strict-Transport-Security) is worth adding at the same time, once every page of the site is HTTPS and you are sure it will stay that way: start with max-age=300 for a week, then raise it. A long max-age on a site that later needs plain HTTP locks visitors out.
5. Where to put the headers
Headers live in the web server’s configuration. Which file depends on the host.
Apache (.htaccess). Add to the .htaccess in your WordPress root, outside the WordPress block:
<IfModule mod_headers.c>
Header always set Content-Security-Policy-Report-Only "default-src 'self'; ..."
Header always set Strict-Transport-Security "max-age=300"
</IfModule>
nginx. In the server block (add_header lines are not inherited by a location block that has its own, so put them where the PHP location can see them):
add_header Content-Security-Policy-Report-Only "default-src 'self'; ..." always;
add_header Strict-Transport-Security "max-age=300" always;
Plesk. Open the domain, then Apache & nginx Settings, and paste the add_header lines into Additional nginx directives. Use nginx here even though the site also has an .htaccess: on Plesk, nginx serves images, CSS and JavaScript directly and only proxies PHP to Apache, so a header set in .htaccess appears on pages but not on static files. nginx directives cover both.
If you set X-Frame-Options, nosniff or Referrer-Policy at the server, leave TitanCart’s switch off, or you will see each header twice (the plugin cannot see server-added headers). Either place is fine; one of them.
Troubleshooting
- The headers do not appear after enabling the switch. Clear any page cache or CDN cache; the headers are added by PHP and a cached copy predates them. Then check a page that is not cached, such as
/cart/. - The headers appear twice. They are set in two places (the switch and the server, or two plugins). Remove one.
- Card fields vanished after enforcing a CSP. The gateway’s script or frame origin is missing. Switch back to report-only, open the console on the checkout page and add what it names.
- The storefront looks unstyled with the Prism theme.
cdn.jsdelivr.netandfonts.googleapis.comare missing from style-src, orfonts.gstatic.comfrom font-src. - reCAPTCHA shows an empty box. Add
https://www.google.comto frame-src. - The Turnstile widget is empty or shows an error code. Add
https://challenges.cloudflare.comto both script-src and frame-src. TitanCart does not add it for you. - Observatory still marks X-Frame-Options. If your CSP has
frame-ancestors, that finding is informational; browsers follow the CSP.