webzod
account

Add a Content-Security-Policy on Shopify

headers.csp.missing · effort: a project

Why it matters

Without a CSP the browser runs any script that ends up in your pages, so a single injection bug gives an attacker control of what visitors see and do. A policy limits where scripts, frames and plugins may load from.

Staged change. Do this in stages and check each one before the next, so a mistake does not break your site or your mail.

The fix

Not possible on Shopify. Shopify sets the response headers of an Online Store theme, and the store cannot add a Content-Security-Policy header. A meta http-equiv Content-Security-Policy tag in layout/theme.liquid is possible, but it cannot carry frame-ancestors or reporting, and apps inject scripts from many hosts, so a strict policy easily breaks the store. A Hydrogen storefront sets its policy in code, with createContentSecurityPolicy in app/entry.server.

Read the documentation (opens in a new tab)

Scan your domain to see whether this applies to you.