CentralCSP
APIPolicy Builder

Build a recommended CSP

Builds a Content-Security-Policy from the website's CSP violation reports over the period (last 7 days by default, up to 30), starting from your policy or the CentralCSP baseline. Browser extensions and other noise are left out, and a nonce comes back as 'nonce-{RANDOM}'.

Send reportingEndpoints as the Reporting-Endpoints header with it, or Chrome and Edge send no reports. Anyone can send reports to the endpoint, so review new sources before deploying.

Limited to 10 requests a minute for each person, after which it answers 429 with a Retry-After header.

Requires the viewer role on the website and the report:csp-violation plan feature.

POST
/v1/workspaces/{workspaceId}/websites/{websiteId}/csp/recommended-policy

Authorization

headerAuthorizationBearer <JWT>

An OpenID Connect access token from signing in to CentralCSP, acting as the signed-in user.

Path Parameters

workspaceId*string

The workspace's id.

websiteId*string

The website's id.

Request Body

application/json
  1. body

The period of reports to learn from and, optionally, the policy to start from.

range?string

How far back to read reports, counted from now. Defaults to 7d and is ignored when from and to are given.

Value in"24h""7d""14d""30d"
from?string

Start of a calendar period instead of range. It must fall within the last 30 days and comes with to.

Formatdate-time
to?string

End of the calendar period, exclusive. It comes with from.

Formatdate-time
policy?string

The policy to start from, as a Content-Security-Policy header value without the header name. Leave it out to start from the CentralCSP baseline.

Length1 <= length <= 65536

Response Body

A policy built from the website's CSP reports, ready to deploy.

application/json
  1. response
policy*string

The recommended Content-Security-Policy header value, without the header name. It reports to the website's endpoint.

reportingEndpoints*string

The Reporting-Endpoints header value to send alongside the policy, without the header name. It declares the centralcsp group the policy reports to.

Example Request
curl -X POST 'https://api.centralcsp.com/v1/workspaces/01936b7a-6f2e-7c31-9a4d-2f8e1c5b7d90/websites/01936b7a-6f2e-7c31-9a4d-2f8e1c5b7d90/csp/recommended-policy' \  -H 'Content-Type: application/json' \  -d '{}'
Example Response200
{  "policy": "default-src 'self'; script-src 'self' 'report-sample' 'report-sha256'; script-src-elem 'self' 'report-sample' 'report-sha256' https://cdn.example.com; style-src 'self' 'report-sample'; object-src 'none'; form-action 'self'; frame-ancestors 'none'; base-uri 'self'; upgrade-insecure-requests; report-uri https://e0123456789abcdef0123.report.centralcsp.com; report-to centralcsp",  "reportingEndpoints": "centralcsp=\"https://e0123456789abcdef0123.report.centralcsp.com\", default=\"https://e0123456789abcdef0123.report.centralcsp.com\""}