Content Security Policy (CSP)
Examples


Netlify Example

Here's how to add a Content-Security-Policy HTTP response header to your Netlify site.

Netlify Example CSP Header

The easiest way to add headers to your Netlify site is to add the Content-Security-Policy header to your netlify.toml file under the [[headers]] and then under [headers.values]

[[headers]]
  for = "/*"
  [headers.values]
    Content-Security-Policy = "default-src 'self';"

In the above example we are simply setting a policy:

default-src 'self';

Chances are you will need something more involved than that

What goes inside a Content Security Policy?

If you're not sure what default-src 'self'; means, then check out the Content Security Policy reference for details.

Another Option for Netlify

Instead of using netlify.toml you can instead place a file named _headers in the publish directory of your site. The syntax for that file might look like this:

/*
  Content-Security-Policy: default-src 'self';