# Content Security Policy Builder: write a CSP from your pages (`bodacious_mistral/csp-builder`) Actor

Reads a site and writes a ready-to-paste starting Content-Security-Policy to deploy as Report-Only first, with hashes for inline scripts, known third-party hosts, and server snippets.

- **URL**: https://apify.com/bodacious_mistral/csp-builder.md
- **Developed by:** [Red Center Studio](https://apify.com/bodacious_mistral) (community)
- **Features:** Limited permissions
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $10.00 / 1,000 policy built

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Content Security Policy Builder: write a CSP from your pages

Reads a site and writes a ready-to-paste starting Content-Security-Policy to deploy as Report-Only first, with hashes for inline scripts, known third-party hosts, and server snippets.

### What it does

Header checkers grade a Content Security Policy. This Actor writes one. Give it a list of websites. For each site it reads the homepage and then more pages of the same site, one for each kind of address, up to the number you set: pages linked from its menu first, then other links on the homepage, then, if there is still room, pages listed in `/sitemap.xml`. It returns one row with a ready-to-paste starting policy:

- The origins named in the pages it reads, sorted into the right directive: script-src, style-src, img-src, font-src, connect-src, frame-src, media-src, manifest-src, worker-src and form-action. It reads script, link, img, srcset, picture, video, audio, track, iframe, form, embed, object, base, and the url() and @import rules in inline CSS and in up to 10 same-origin stylesheets. From inline scripts it takes an address for connect-src only when it is written directly in a fetch, XMLHttpRequest open, sendBeacon, WebSocket, EventSource or axios call.
- A SHA-256 hash for each inline script (up to 100 different ones), so you do not need unsafe-inline for scripts. It also counts inline event handlers such as onclick, which need 'unsafe-hashes' (up to 50 hashes) or a small refactor. A warning says when either list is cut short.
- Safe defaults: object-src 'none' (unless a page that was read uses embed or object, in which case their origins are listed instead and a warning asks you to check them), base-uri 'self', frame-ancestors 'self', and upgrade-insecure-requests on https sites.
- Known third-party hosts that static HTML cannot show (see the table below), each marked with what was found on the site.
- The site's current Content-Security-Policy and Report-Only headers, and a list of what the site loads that the current policy would block.
- Snippets for a Cloudflare \_headers file, nginx, Apache, netlify.toml and an HTML meta tag.
- Warnings: eval-like code, resources loaded over http on an https site, hosts that might need a wildcard, and more.

Two modes. `compatible` (default) lists inline scripts by hash and allows `'unsafe-inline'` for styles when the site uses inline styles. `strict` lists inline scripts and style elements by hash, never allows unsafe-inline, and tells you which inline handlers and style attributes to move out of the HTML. An optional report address adds `report-uri` and `report-to`.

### Why Report-Only first

A policy written from the HTML can only be a starting point. If you enforce it straight away, anything it missed breaks for your visitors. Deploy it as `Content-Security-Policy-Report-Only` for about a week. The browser then loads everything as before and reports what the policy would have blocked. Fix or allow what is reported, then rename the header to `Content-Security-Policy` to enforce. Every row ends with this plan, and every snippet uses the Report-Only header name. The one exception is the meta tag, which can only enforce.

### Known third-party expansions

When one of these is found as a script, frame or other resource, or its address is written inside an inline script, the hosts it is known to need at run time are added. Each addition appears in `expansionsAdded` as "added because ..." with the reason. The table is short on purpose and lists only hosts the vendors document.

| Service | Found by | Added |
| --- | --- | --- |
| Google Tag Manager and gtag.js | www.googletagmanager.com | script-src and frame-src googletagmanager.com; connect-src www.google-analytics.com, analytics.google.com, region1.google-analytics.com; img-src googletagmanager.com and google-analytics.com |
| Google Analytics (analytics.js) | www.google-analytics.com | script-src and img-src www.google-analytics.com; the same connect-src hosts |
| Google Fonts | fonts.googleapis.com or fonts.gstatic.com | style-src fonts.googleapis.com; font-src fonts.gstatic.com |
| Stripe.js | js.stripe.com | script-src js.stripe.com; frame-src js.stripe.com and hooks.stripe.com; connect-src api.stripe.com |
| YouTube embeds | www.youtube.com/embed, iframe_api, youtube-nocookie.com/embed | frame-src www.youtube.com and www.youtube-nocookie.com |
| Vimeo embeds | player.vimeo.com | frame-src and script-src player.vimeo.com; img-src i.vimeocdn.com |
| Cloudflare Turnstile | challenges.cloudflare.com | script-src and frame-src challenges.cloudflare.com |
| Google reCAPTCHA | www.google.com/recaptcha, www.gstatic.com/recaptcha | script-src and frame-src for the recaptcha paths on www.google.com, www.gstatic.com and recaptcha.google.com |
| Intercom messenger | widget.intercom.io, js.intercomcdn.com | script, connect, img, font and frame hosts from Intercom's own list; check its guide for your region |
| HubSpot tracking and forms | js.hs-scripts.com, js.hsforms.net, js.hs-analytics.net | connect-src api.hubapi.com, forms.hsforms.com, forms.hubspot.com |
| Hotjar | static.hotjar.com, script.hotjar.com | script, connect, img, font and frame hosts, with the wildcards Hotjar itself recommends |
| Meta Pixel | connect.facebook.net | script-src connect.facebook.net; img-src www.facebook.com; connect-src www.facebook.com and connect.facebook.net |
| jsDelivr, unpkg, cdnjs | cdn.jsdelivr.net, unpkg.com, cdnjs.cloudflare.com | Nothing extra. A warning explains that these hosts serve every package, so pin versions with Subresource Integrity or serve the file yourself |

### Who it is for

Site owners, agencies and developers who know they should have a Content Security Policy but do not want to write one by hand, security reviewers who want a first draft to check, and AI agents that need a policy as a tool call.

### Input

Run it from the Console, the API, or as an agent tool. Minimal input:

```json
{
  "sites": [
    "redcenterstudio.com"
  ]
}
```

Every field is described in the input form. Free to run: you pay only for the policy built you get back.

### Output

One row per input item. Rows with `status: "ok"` are results. Rows with `status: "error"` explain what went wrong and are never charged. A run summary is stored in the `OUTPUT` record.

Real output from a live run:

```json
{
  "status": "ok",
  "inputRef": "https://redcenterstudio.com",
  "auditedAt": "2026-12-05T21:48:49.913Z",
  "site": "https://redcenterstudio.com",
  "pagesRead": 2,
  "strictness": "compatible",
  "currentPolicy": "frame-ancestors 'self'",
  "currentPolicyReportOnly": null,
  "currentPolicyBlocks": [],
  "policy": "Content-Security-Policy: default-src 'self'; script-src 'self' 'sha256-/aDReTAQHvEjUmWEz8w+2g+emwe9QJjCkVkz6gR+ZJg=' 'sha256-/JL7W434DOf+BR1hMCmV7MzdZCrm5BrTQYgEUlL9m0I=' 'sha256-1dxj2NxRdM48qy5hgGrrhkppVhHs9qiJCfDKQafNcNQ=' 'sha256-6pUD4bKj2gbiBWaQm14KvnBBbFjKzColP0L1/zloE8c=' 'sha256-dV1yD2YPKEWmvKrOwH5ILhof9S3QwwtBY8woQ9WiOX0=' 'sha256-FTGS5SHbnCp9EcZUsGop4kdUgDGr6UVHozQ0WaaOYx0=' 'sha256-IAkXtx+FpVPot5ykBpTumvyDLyuzTPjIA+CQalxAkM8=' 'sha256-LH+G+Jk0QPTlFYRchCPtaEBJn4LvqX8lyiRmY1dkScc=' 'sha256-n0nPi43hIgExAHPInZDLmViO5Vlm6tR2G5YwDR7Z7co=' 'sha256-pI8rdgSRUPP1zJbnn/voH6ZAf+fJWddwsnbpvaEhB60=' 'sha256-raQOI/r9YhZyKQuM5fFsatn755FJe6ByLx4cs7cghKg=' 'sha256-uR+ZdfomG8dL1OQPr4ewAMLm6s/4TiHQ7fh6S4VMt2U='; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'self'; upgrade-insecure-requests",
  "policyReportOnly": "Content-Security-Policy-Report-Only: default-src 'self'; script-src 'self' 'sha256-/aDReTAQHvEjUmWEz8w+2g+emwe9QJjCkVkz6gR+ZJg=' 'sha256-/JL7W434DOf+BR1hMCmV7MzdZCrm5BrTQYgEUlL9m0I=' 'sha256-1dxj2NxRdM48qy5hgGrrhkppVhHs9qiJCfDKQafNcNQ=' 'sha256-6pUD4bKj2gbiBWaQm14KvnBBbFjKzColP0L1/zloE8c=' 'sha256-dV1yD2YPKEWmvKrOwH5ILhof9S3QwwtBY8woQ9WiOX0=' 'sha256-FTGS5SHbnCp9EcZUsGop4kdUgDGr6UVHozQ0WaaOYx0=' 'sha256-IAkXtx+FpVPot5ykBpTumvyDLyuzTPjIA+CQalxAkM8=' 'sha256-LH+G+Jk0QPTlFYRchCPtaEBJn4LvqX8lyiRmY1dkScc=' 'sha256-n0nPi43hIgExAHPInZDLmViO5Vlm6tR2G5YwDR7Z7co=' 'sha256-pI8rdgSRUPP1zJbnn/voH6ZAf+fJWddwsnbpvaEhB60=' 'sha256-raQOI/r9YhZyKQuM5fFsatn755FJe6ByLx4cs7cghKg=' 'sha256-uR+ZdfomG8dL1OQPr4ewAMLm6s/4TiHQ7fh6S4VMt2U='; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'self'; upgrade-insecure-requests",
  "directives": {
    "default-src": [
      "'self'"
    ],
    "script-src": [
      "'self'",
      "'sha256-/aDReTAQHvEjUmWEz8w+2g+emwe9QJjCkVkz6gR+ZJg='",
      "'sha256-/JL7W434DOf+BR1hMCmV7MzdZCrm5BrTQYgEUlL9m0I='",
      "'sha256-1dxj2NxRdM48qy5hgGrrhkppVhHs9qiJCfDKQafNcNQ='",
      "'sha256-6pUD4bKj2gbiBWaQm14KvnBBbFjKzColP0L1/zloE8c='",
      "'sha256-dV1yD2YPKEWmvKrOwH5ILhof9S3QwwtBY8woQ9WiOX0='",
      "'sha256-FTGS5SHbnCp9EcZUsGop4kdUgDGr6UVHozQ0WaaOYx0='",
      "'sha256-IAkXtx+FpVPot5ykBpTumvyDLyuzTPjIA+CQalxAkM8='",
      "'sha256-LH+G+Jk0QPTlFYRchCPtaEBJn4LvqX8lyiRmY1dkScc='",
      "'sha256-n0nPi43hIgExAHPInZDLmViO5Vlm6tR2G5YwDR7Z7co='",
      "'sha256-pI8rdgSRUPP1zJbnn/voH6ZAf+fJWddwsnbpvaEhB60='",
      "'sha256-raQOI/r9YhZyKQuM5fFsatn755FJe6ByLx4cs7cghKg='",
      "'sha256-uR+ZdfomG8dL1OQPr4ewAMLm6s/4TiHQ7fh6S4VMt2U='"
    ],
    "style-src": [
      "'self'",
      "'unsafe-inline'"
    ],
    "img-src": [
      "'self'",
      "data:"
    ],
    "connect-src": [
      "'self'"
    ],
    "object-src": [
      "'none'"
    ],
    "base-uri": [
      "'self'"
    ],
    "form-action": [
      "'self'"
    ],
    "frame-ancestors": [
      "'self'"
    ]
  },
  "inlineScripts": {
    "count": 12,
    "hashes": [
      "'sha256-/aDReTAQHvEjUmWEz8w+2g+emwe9QJjCkVkz6gR+ZJg='",
      "'sha256-LH+G+Jk0QPTlFYRchCPtaEBJn4LvqX8lyiRmY1dkScc='",
      "'sha256-1dxj2NxRdM48qy5hgGrrhkppVhHs9qiJCfDKQafNcNQ='",
      "'sha256-pI8rdgSRUPP1zJbnn/voH6ZAf+fJWddwsnbpvaEhB60='",
      "'sha256-uR+ZdfomG8dL1OQPr4ewAMLm6s/4TiHQ7fh6S4VMt2U='",
      "'sha256-IAkXtx+FpVPot5ykBpTumvyDLyuzTPjIA+CQalxAkM8='",
      "'sha256-raQOI/r9YhZyKQuM5fFsatn755FJe6ByLx4cs7cghKg='",
      "'sha256-dV1yD2YPKEWmvKrOwH5ILhof9S3QwwtBY8woQ9WiOX0='",
      "'sha256-/JL7W434DOf+BR1hMCmV7MzdZCrm5BrTQYgEUlL9m0I='",
      "'sha256-6pUD4bKj2gbiBWaQm14KvnBBbFjKzColP0L1/zloE8c='",
      "'sha256-n0nPi43hIgExAHPInZDLmViO5Vlm6tR2G5YwDR7Z7co='",
      "'sha256-FTGS5SHbnCp9EcZUsGop4kdUgDGr6UVHozQ0WaaOYx0='"
    ]
  },
  "inlineEventHandlers": 0,
  "inlineStyles": 47,
  "unsafeInlineNeeded": true,
  "expansionsAdded": [],
  "warnings": [
    "Many different inline scripts usually means the HTML generates them per page. A hash only matches one exact text, so use a nonce for those."
  ],
  "snippets": {
    "cloudflareHeadersFile": "/*\n  Content-Security-Policy-Report-Only: default-src 'self'; script-src 'self' 'sha256-/aDReTAQHvEjUmWEz8w+2g+emwe9QJjCkVkz6gR+ZJg=' 'sha256-/JL7W434DOf+BR1hMCmV7MzdZCrm5BrTQYgEUlL9m0I=' 'sha256-1dxj2NxRdM48qy5hgGrrhkppVhHs9qiJCfDKQafNcNQ=' 'sha256-6pUD4bKj2gbiBWaQm14KvnBBbFjKzColP0L1/zloE8c=' 'sha256-dV1yD2YPKEWmvKrOwH5ILhof9S3QwwtBY8woQ9WiOX0=' 'sha256-FTGS5SHbnCp9EcZUsGop4kdUgDGr6UVHozQ0WaaOYx0=' 'sha256-IAkXtx+FpVPot5ykBpTumvyDLyuzTPjIA+CQalxAkM8=' 'sha256-LH+G+Jk0QPTlFYRchCPtaEBJn4LvqX8lyiRmY1dkScc=' 'sha256-n0nPi43hIgExAHPInZDLmViO5Vlm6tR2G5YwDR7Z7co=' 'sha256-pI8rdgSRUPP1zJbnn/voH6ZAf+fJWddwsnbpvaEhB60=' 'sha256-raQOI/r9YhZyKQuM5fFsatn755FJe6ByLx4cs7cghKg=' 'sha256-uR+ZdfomG8dL1OQPr4ewAMLm6s/4TiHQ7fh6S4VMt2U='; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'self'; upgrade-insecure-requests",
    "nginx": "add_header Content-Security-Policy-Report-Only \"default-src 'self'; script-src 'self' 'sha256-/aDReTAQHvEjUmWEz8w+2g+emwe9QJjCkVkz6gR+ZJg=' 'sha256-/JL7W434DOf+BR1hMCmV7MzdZCrm5BrTQYgEUlL9m0I=' 'sha256-1dxj2NxRdM48qy5hgGrrhkppVhHs9qiJCfDKQafNcNQ=' 'sha256-6pUD4bKj2gbiBWaQm14KvnBBbFjKzColP0L1/zloE8c=' 'sha256-dV1yD2YPKEWmvKrOwH5ILhof9S3QwwtBY8woQ9WiOX0=' 'sha256-FTGS5SHbnCp9EcZUsGop4kdUgDGr6UVHozQ0WaaOYx0=' 'sha256-IAkXtx+FpVPot5ykBpTumvyDLyuzTPjIA+CQalxAkM8=' 'sha256-LH+G+Jk0QPTlFYRchCPtaEBJn4LvqX8lyiRmY1dkScc=' 'sha256-n0nPi43hIgExAHPInZDLmViO5Vlm6tR2G5YwDR7Z7co=' 'sha256-pI8rdgSRUPP1zJbnn/voH6ZAf+fJWddwsnbpvaEhB60=' 'sha256-raQOI/r9YhZyKQuM5fFsatn755FJe6ByLx4cs7cghKg=' 'sha256-uR+ZdfomG8dL1OQPr4ewAMLm6s/4TiHQ7fh6S4VMt2U='; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'self'; upgrade-insecure-requests\" always;",
    "apache": "Header always set Content-Security-Policy-Report-Only \"default-src 'self'; script-src 'self' 'sha256-/aDReTAQHvEjUmWEz8w+2g+emwe9QJjCkVkz6gR+ZJg=' 'sha256-/JL7W434DOf+BR1hMCmV7MzdZCrm5BrTQYgEUlL9m0I=' 'sha256-1dxj2NxRdM48qy5hgGrrhkppVhHs9qiJCfDKQafNcNQ=' 'sha256-6pUD4bKj2gbiBWaQm14KvnBBbFjKzColP0L1/zloE8c=' 'sha256-dV1yD2YPKEWmvKrOwH5ILhof9S3QwwtBY8woQ9WiOX0=' 'sha256-FTGS5SHbnCp9EcZUsGop4kdUgDGr6UVHozQ0WaaOYx0=' 'sha256-IAkXtx+FpVPot5ykBpTumvyDLyuzTPjIA+CQalxAkM8=' 'sha256-LH+G+Jk0QPTlFYRchCPtaEBJn4LvqX8lyiRmY1dkScc=' 'sha256-n0nPi43hIgExAHPInZDLmViO5Vlm6tR2G5YwDR7Z7co=' 'sha256-pI8rdgSRUPP1zJbnn/voH6ZAf+fJWddwsnbpvaEhB60=' 'sha256-raQOI/r9YhZyKQuM5fFsatn755FJe6ByLx4cs7cghKg=' 'sha256-uR+ZdfomG8dL1OQPr4ewAMLm6s/4TiHQ7fh6S4VMt2U='; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'self'; upgrade-insecure-requests\"",
    "netlifyToml": "[[headers]]\n  for = \"/*\"\n  [headers.values]\n    Content-Security-Policy-Report-Only = \"default-src 'self'; script-src 'self' 'sha256-/aDReTAQHvEjUmWEz8w+2g+emwe9QJjCkVkz6gR+ZJg=' 'sha256-/JL7W434DOf+BR1hMCmV7MzdZCrm5BrTQYgEUlL9m0I=' 'sha256-1dxj2NxRdM48qy5hgGrrhkppVhHs9qiJCfDKQafNcNQ=' 'sha256-6pUD4bKj2gbiBWaQm14KvnBBbFjKzColP0L1/zloE8c=' 'sha256-dV1yD2YPKEWmvKrOwH5ILhof9S3QwwtBY8woQ9WiOX0=' 'sha256-FTGS5SHbnCp9EcZUsGop4kdUgDGr6UVHozQ0WaaOYx0=' 'sha256-IAkXtx+FpVPot5ykBpTumvyDLyuzTPjIA+CQalxAkM8=' 'sha256-LH+G+Jk0QPTlFYRchCPtaEBJn4LvqX8lyiRmY1dkScc=' 'sha256-n0nPi43hIgExAHPInZDLmViO5Vlm6tR2G5YwDR7Z7co=' 'sha256-pI8rdgSRUPP1zJbnn/voH6ZAf+fJWddwsnbpvaEhB60=' 'sha256-raQOI/r9YhZyKQuM5fFsatn755FJe6ByLx4cs7cghKg=' 'sha256-uR+ZdfomG8dL1OQPr4ewAMLm6s/4TiHQ7fh6S4VMt2U='; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'self'; upgrade-insecure-requests\"",
    "htmlMeta": "<!-- A meta tag always enforces: it cannot be Report-Only. frame-ancestors, report-uri and report-to do not work in a meta tag, so they are left out. Test with a header first. -->\n<meta http-equiv=\"Content-Security-Policy\" content=\"default-src 'self'; script-src 'self' 'sha256-/aDReTAQHvEjUmWEz8w+2g+emwe9QJjCkVkz6gR+ZJg=' 'sha256-/JL7W434DOf+BR1hMCmV7MzdZCrm5BrTQYgEUlL9m0I=' 'sha256-1dxj2NxRdM48qy5hgGrrhkppVhHs9qiJCfDKQafNcNQ=' 'sha256-6pUD4bKj2gbiBWaQm14KvnBBbFjKzColP0L1/zloE8c=' 'sha256-dV1yD2YPKEWmvKrOwH5ILhof9S3QwwtBY8woQ9WiOX0=' 'sha256-FTGS5SHbnCp9EcZUsGop4kdUgDGr6UVHozQ0WaaOYx0=' 'sha256-IAkXtx+FpVPot5ykBpTumvyDLyuzTPjIA+CQalxAkM8=' 'sha256-LH+G+Jk0QPTlFYRchCPtaEBJn4LvqX8lyiRmY1dkScc=' 'sha256-n0nPi43hIgExAHPInZDLmViO5Vlm6tR2G5YwDR7Z7co=' 'sha256-pI8rdgSRUPP1zJbnn/voH6ZAf+fJWddwsnbpvaEhB60=' 'sha256-raQOI/r9YhZyKQuM5fFsatn755FJe6ByLx4cs7cghKg=' 'sha256-uR+ZdfomG8dL1OQPr4ewAMLm6s/4TiHQ7fh6S4VMt2U='; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; upgrade-insecure-requests\">"
  },
  "nextStep": "Deploy the Report-Only header for about a week and watch the browser console for violations, or run again with a report address to collect them. Fix or allow what is reported, then switch the header name to Content-Security-Policy to enforce. Site Watch can separately tell you about domain and certificate expiry and DNS and email record changes; it does not check Content-Security-Policy or other headers: https://redcenterstudio.com/sitewatch/"
}
```

### Pricing

Pay per event. No monthly fee. The platform start event is charged automatically by Apify.

| Event | Charged when | Price |
| --- | --- | --- |
| Policy built (`policy-built`) | Charged once for each website that returns a policy row. Error rows are free. | $0.01 per policy built ($10 per 1,000) |

Set a maximum cost per run on the run options. The Actor stops cleanly when the limit is reached and never charges beyond it.

### Use with Apify MCP

AI assistants can call this Actor as a tool through the Apify MCP server:

`https://mcp.apify.com?tools=bodacious_mistral/csp-builder`

### Limits

- Static reading cannot see every runtime request. It reads the HTML and the same-origin stylesheets, never runs JavaScript and uses no browser. External script files are never downloaded or read. Anything a script loads or adds while it runs, such as a chat widget loading its own parts, is only covered when the service is in the expansions table or, for connect-src, when the address is written directly in a network call inside an inline script. The policy is a starting point, not a finished one.
- Only `/sitemap.xml` is read, not other sitemap addresses named in robots.txt, and gzip sitemap files are not read. For a sitemap index, child sitemaps are read in order until there are enough pages, at most 10 of them.
- It never changes any site. It only reads public pages with ordinary GET requests.
- Cross-origin stylesheets are not opened, so fonts and images named inside them come only from the expansions table.
- Only the homepage headers are read for the current policy. If other pages send a different policy, a warning says so.
- Hashes match one exact piece of inline text. If your server changes an inline script on every request, use a nonce instead.
- Up to 50 websites per run, 3 at a time by default, and up to 50 pages per site. Each site is limited to 60 seconds.
- Private and internal addresses are refused for safety and come back as an error row.
- A homepage that answers with a status outside 200 to 299, or with an empty body, is a free error row.

### Next step

[Watch your domain and certificate expiry with Site Watch](https://redcenterstudio.com/sitewatch/). Built by Red Center Studio. Related: [Site Watch](https://redcenterstudio.com/sitewatch/).

# Actor input Schema

## `sites` (type: `array`):

Websites to write a policy for, one per line. A bare domain or a full address. Only public pages are read and nothing on the site is changed.

## `maxPagesPerSite` (type: `integer`):

How many pages to read on each site: the homepage plus pages linked from its menu and listed in the sitemap, one page for each kind of address.

## `strictness` (type: `string`):

compatible lists inline scripts by hash and allows inline styles with unsafe-inline when the site uses them. strict lists inline scripts and style elements by hash, allows no unsafe-inline, and reports inline handlers and style attributes to refactor.

## `reportUri` (type: `string`):

Optional https address that collects violation reports. When set, the policy gets report-uri and report-to, and the snippets include the Reporting-Endpoints header. Leave empty to skip.

## `concurrency` (type: `integer`):

How many websites to read at the same time. Lower it if you read many sites on one host.

## Actor input object example

```json
{
  "sites": [
    "redcenterstudio.com"
  ],
  "maxPagesPerSite": 15,
  "strictness": "compatible",
  "reportUri": "",
  "concurrency": 3
}
```

# Actor output Schema

## `results` (type: `string`):

One row per input item.

## `summary` (type: `string`):

Totals, charged events, stop reason and the next step. Stored as the OUTPUT record.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "sites": [
        "redcenterstudio.com"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("bodacious_mistral/csp-builder").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "sites": ["redcenterstudio.com"] }

# Run the Actor and wait for it to finish
run = client.actor("bodacious_mistral/csp-builder").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "sites": [
    "redcenterstudio.com"
  ]
}' |
apify call bodacious_mistral/csp-builder --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,bodacious_mistral/csp-builder"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/O59L4BwayrC7hOBJE/builds/FJe2ryQcLiOMPgibV/openapi.json
