Implementing Content Security Policy with CspBuilder wizard

2013-05-22 00:00:00 +0100

Exactly for this purpose I have written that consumes the Content Security Policy violation reports generated by browsers and turns them into a working CSP header. Using CSP report-only mode and CspBuilder it’s possible to build a working policy in a few iterations. How this works?

  1. Go to Obtain your unique report URL (e.g. and policy analysis URL (e.g. For convenience, the service will also provide a complete CSP header in its most restrictive form but report-only mode, so that nothing is blocked really.
  2. Place this header on your website and open it in a browser. Google Chrome is recommended because it has most mature CSP implementation of all browsers now on market. Firefox will not send reports to external pages, which kills the whole purpose of CspBuilder (see bug #847069).
  3. Go to your CSP policy analysis URL. You will see all received block reports and proposed new policy header. Copy it to your website and refresh your website, testing all pages and features. Repeat the process until you see no new CSP reports. </ol> CspBuilder greatly simplifies the whole process, but it won't be able to make all decisions for you. The builder will by default allow anything that was reported as blocked (or would be in enforcement mode). As result, you might end up with a policy that looks like this:
    Content-Security-Policy-Report-Only: frame-src ; img-src 'self' ; style-src 'unsafe-inline' 'self' ; report-uri /report/9018643792216450862/ ;
    Google, Facebook or Twitter should be allowed on any site that uses Google Analytics, AdSense or social plugins. But what are all these domains like,,, doing there? I guess they serve advertisements on behalf of Google AdSense, as part of specific client campaigns. Do you want to allow them? It's important decision you have to make.