Setting up your CSP headers
To report violations to csp-report-to.com, your site sends two HTTP response headers:
Content-Security-Policy-Report-Only: default-src 'self'; report-uri https://csp-report-to.com/r/YOUR_SITE_KEY; report-to csp
Reporting-Endpoints: csp="https://csp-report-to.com/r/YOUR_SITE_KEY"
Enter your site key in the box at the top of this page, and every example here uses your endpoint, ready to copy. When you're logged in, it's filled in for you. Replace default-src 'self' with your own policy; the examples on this page use it because it's short.
What each part does
report-uri <url>is the original way to ask for reports. The browser POSTs each violation to that URL as it happens. The CSP specification now marks it as deprecated, but every major browser supports it.report-to cspis the newer way, through the browser's Reporting API.cspis just a name. The browser looks it up in theReporting-Endpointsheader to find the URL, so the two names must match.Reporting-Endpoints: csp="<url>"defines that name. It is a separate header, not part of the policy.
Send both. Browsers don't all handle them the same way: Chromium-based browsers (Chrome, Edge, Opera and others) use report-to, while Firefox's and Safari's support for report-to differs from Chrome's, and they may only use report-uri. Under the CSP specification, a browser that supports report-to ignores report-uri when both are present, so you normally get each report once, not twice. With both, every browser has a way to reach you.
You may see older guides use a Report-To header with a JSON value. You don't need it for CSP: Reporting-Endpoints replaces it. Browsers still accept Report-To, which is what Magento sends (see Magento 2 below).
Report-only or enforced?
Content-Security-Policy-Report-Onlyblocks nothing. Browsers check the policy and report what would have been blocked. Start here: it is safe to deploy on a live site.Content-Security-Policyenforces the policy. Browsers block what it doesn't allow, and report it, as long as the policy still containsreport-uriandreport-to.
You can send both headers at once, with different policies. Browsers apply each one independently. Rolling out a new policy shows how to use that.
Use a header, not a <meta> tag
A policy set in a <meta http-equiv="Content-Security-Policy"> tag can't report to us. Browsers ignore report-uri in a <meta> tag, a <meta> tag can't make a policy report-only, and report-to needs the Reporting-Endpoints HTTP header anyway. Set the policy as an HTTP response header, as in the examples below.
HTTPS and delivery delays
- The Reporting API (
report-to) only works on pages served over HTTPS. On a plain HTTP page there is no Reporting API, and you can't count onreport-urias a fallback either: Chromium-based browsers (Chrome, Edge, Opera) ignorereport-uriwhenever the policy containsreport-to, so they may send nothing at all. Serve your site over HTTPS. If a site really is HTTP-only, leave outreport-to cspand theReporting-Endpointsheader, so browsers usereport-uri. - Reports can arrive late. Browsers that use the Reporting API collect reports and send them in batches, which can take up to a minute.
report-urireports are usually sent right away.
Examples by platform
Every example uses the endpoint from the box at the top of this page: https://csp-report-to.com/r/YOUR_SITE_KEY.
WordPress
Use our plugin instead of editing server files. It sends both headers for you.
- Download the plugin (a zip file).
- In your WordPress admin, go to Plugins → Add New Plugin, press Upload Plugin, choose the zip, then press Install Now and Activate.
- Go to Settings → CSP Reporting and paste your endpoint from your site's settings page. You can paste the two header lines instead; the plugin finds the endpoint in them.
- Leave the policy as
default-src 'self'to start, or enter your own withoutreport-uriorreport-to, which the plugin adds. To see which inline code is blocked, add'report-sample', for exampledefault-src 'self' 'report-sample'(see Troubleshooting and FAQ). Keep the mode on Report only until your reports are quiet. - Press Save Changes, then Check my home page. It loads your home page the way a visitor would and tells you whether the policy arrives.
The plugin works on any host, including shared hosting, with no .htaccess changes. By default it only adds the policy to your public pages, not to the admin area or login page, because the WordPress admin uses a lot of inline code, which uses up your report quota.
If the check says the policy isn't found, clear your caching plugin's cache and your CDN's cache. Some caches serve saved pages without the headers. If they keep dropping them, use the Apache or Nginx example below instead.
If something else on your site already sends a Content-Security-Policy, such as a security plugin or your host, both policies apply. Keep only one of them.
To update the plugin, download the zip again and upload it the same way. WordPress asks whether to replace the installed version: press Replace current with uploaded.
Magento 2 / Adobe Commerce
Magento already sends its own Content-Security-Policy, so you don't need an extension: you only tell Magento where to send the reports.
- In the Magento admin, go to Stores → Configuration → Security → Content Security Policy (CSP) and open Mode.
- Paste your endpoint,
https://csp-report-to.com/r/YOUR_SITE_KEY, into Report URI. There's a field for each area: Storefront, the One Page Checkout, Admin and Admin › Create Order. Fill in the ones you want reports for, at least Storefront. Check the Scope switcher at the top of the page: set it at Default Config, unless a website or store view overrides it. - Press Save Config, then flush the cache: System → Cache Management → Flush Magento Cache, or
bin/magento cache:flush. If the store has Varnish, Fastly or a CDN in front, purge that too. Until you do, visitors get pages with the old headers.
Keep Magento's own policy. It's built from the allow-lists of Magento and your extensions,, and replacing it with one of the examples below would break the store.
What Magento then sends:
Content-Security-Policy-Report-Only: … report-uri https://csp-report-to.com/r/YOUR_SITE_KEY; report-to report-endpoint;
Report-To: {"group":"report-endpoint","max_age":10886400,"endpoints":[{"url":"https://csp-report-to.com/r/YOUR_SITE_KEY"}]}
report-to report-endpoint names a group, and Magento defines that group in the older Report-To header instead of Reporting-Endpoints. That works: Chrome and Edge send their reports through the group, and Firefox and Safari use report-uri. If you see report-to report-endpoint in the policy but no Report-To header, Chrome and Edge send nothing at all, because they ignore report-uri when the policy has report-to. The setup check on your site's settings page spots that.
Magento's policy doesn't include 'report-sample', and the admin has no setting for it, so inline violations from a Magento store usually show just inline, without the code. The violation's page still shows the page and line where it happened.
A Magento store may report nothing at first, and that's normal. Magento's policy allows 'unsafe-inline' and 'unsafe-eval' on most pages and lists every host the store and its extensions use, so an ordinary visit breaks none of its rules. Use the live browser test (below) to prove that reports arrive. The reports become useful once you tighten the policy, for example by removing 'unsafe-inline' from script-src.
Since Magento 2.4.7, the payment pages (checkout in the storefront, Create Order in the admin) enforce the policy, to meet PCI DSS 4.0: anything not allowed there is blocked, and reported. All other pages are report-only.
Shopify
A standard Shopify store (the Online Store with a theme) can't report to us. Shopify sends the response headers itself and gives store owners no way to change them: not in the admin, not in the theme, and not through an app. Its own policy is a short one with no report-uri or report-to:
Content-Security-Policy: block-all-mixed-content; frame-ancestors 'none'; upgrade-insecure-requests;
That's why Check my site on a Shopify store says the policy has no report-uri or report-to. You can't fix that from the store.
A policy in a <meta> tag in the theme doesn't help either: browsers ignore report-uri in a <meta> tag, and a <meta> policy can't be report-only, so it blocks things on the live store straight away. A theme script that forwards the browser's securitypolicyviolation events would only work with such a blocking policy, so we don't recommend it: one missing source breaks the shop for your customers. Shopify runs the checkout pages and their payment-page script rules (PCI DSS 4.0) itself.
A headless Shopify store can. If your storefront is a Hydrogen app (on Oxygen or your own hosting) or another frontend that uses Shopify's Storefront API, your own server sends the headers, so add the reporting parts there as on any other site. In Hydrogen, the policy is built by createContentSecurityPolicy in app/entry.server.tsx (or .jsx). Keep the policy it builds and add the reporting parts where the header is set:
const {nonce, header, NonceProvider} = createContentSecurityPolicy({
shop: {
checkoutDomain: context.env.PUBLIC_CHECKOUT_DOMAIN,
storeDomain: context.env.PUBLIC_STORE_DOMAIN,
},
});
// … rendering as in your template …
responseHeaders.set(
'Content-Security-Policy',
`${header}; report-uri https://csp-report-to.com/r/YOUR_SITE_KEY; report-to csp`,
);
responseHeaders.set('Reporting-Endpoints', 'csp="https://csp-report-to.com/r/YOUR_SITE_KEY"');
Hydrogen's template enforces its policy (Content-Security-Policy), so with this change you get a report for everything it blocks. To try a stricter policy without blocking anything, send it as a second header, Content-Security-Policy-Report-Only, with the same reporting parts. Browsers apply both independently.
Nginx
Put both lines inside your server block (or a location block). always adds the headers to error pages too, not only to successful responses.
server {
# ... your existing configuration ...
add_header Content-Security-Policy-Report-Only "default-src 'self'; report-uri https://csp-report-to.com/r/YOUR_SITE_KEY; report-to csp" always;
add_header Reporting-Endpoints 'csp="https://csp-report-to.com/r/YOUR_SITE_KEY"' always;
}
Watch out: a location block that has any add_header of its own doesn't inherit the ones from server. If you add headers in a location, repeat these two lines there. Reload with nginx -t && nginx -s reload.
Apache
These lines need mod_headers (on Debian and Ubuntu: a2enmod headers). Put them in your <VirtualHost> or in .htaccess (which needs AllowOverride FileInfo). They also work on LiteSpeed, which many shared hosts run.
<IfModule mod_headers.c>
Header always set Content-Security-Policy-Report-Only "default-src 'self'; report-uri https://csp-report-to.com/r/YOUR_SITE_KEY; report-to csp"
Header always set Reporting-Endpoints "csp=\"https://csp-report-to.com/r/YOUR_SITE_KEY\""
</IfModule>
Keep the quotes exactly as shown: the Reporting-Endpoints value is wrapped in double quotes, with \" around the URL. LiteSpeed answers single-quoted values with a 500 error. If the Reporting-Endpoints line still gives a 500 error, remove it and ; report-to csp from the policy: browsers then use report-uri alone.
Caddy
In your Caddyfile, inside the site block. The backticks let the value contain double quotes.
example.com {
header {
Content-Security-Policy-Report-Only "default-src 'self'; report-uri https://csp-report-to.com/r/YOUR_SITE_KEY; report-to csp"
Reporting-Endpoints `csp="https://csp-report-to.com/r/YOUR_SITE_KEY"`
}
# ... your existing configuration ...
}
PHP
Call header() before your script sends any output (any HTML, echo or even whitespace before <?php), for example at the top of a front controller or a shared bootstrap file.
<?php
$cspEndpoint = 'https://csp-report-to.com/r/YOUR_SITE_KEY';
header("Content-Security-Policy-Report-Only: default-src 'self'; report-uri {$cspEndpoint}; report-to csp");
header('Reporting-Endpoints: csp="' . $cspEndpoint . '"');
If you use a framework, it probably has its own way to add response headers (middleware or a response object). Use that with the same two values.
Node.js with Express
A small middleware, registered before your routes:
const express = require('express');
const app = express();
const CSP_ENDPOINT = 'https://csp-report-to.com/r/YOUR_SITE_KEY';
app.use((req, res, next) => {
res.setHeader(
'Content-Security-Policy-Report-Only',
`default-src 'self'; report-uri ${CSP_ENDPOINT}; report-to csp`
);
res.setHeader('Reporting-Endpoints', `csp="${CSP_ENDPOINT}"`);
next();
});
Node.js with Express and helmet
helmet builds the policy for you. reportOnly: true sends it as Content-Security-Policy-Report-Only. helmet doesn't set Reporting-Endpoints, so add that with a small middleware.
const express = require('express');
const helmet = require('helmet');
const app = express();
const CSP_ENDPOINT = 'https://csp-report-to.com/r/YOUR_SITE_KEY';
app.use(
helmet({
contentSecurityPolicy: {
useDefaults: false, // only the directives below
reportOnly: true,
directives: {
defaultSrc: ["'self'"],
reportUri: [CSP_ENDPOINT],
reportTo: ['csp'],
},
},
})
);
app.use((req, res, next) => {
res.setHeader('Reporting-Endpoints', `csp="${CSP_ENDPOINT}"`);
next();
});
Already enforcing a policy with helmet? helmet sends one CSP header, so switching it to reportOnly: true replaces your enforced policy with a report-only one: nothing is blocked any more. To keep enforcing, leave reportOnly off and add reportUri: [CSP_ENDPOINT] and reportTo: ['csp'] to your existing directives (violations of the enforced policy are then reported). To test a stricter policy alongside it, keep helmet's enforced policy and add a second, report-only header yourself in the middleware above:
res.setHeader('Content-Security-Policy-Report-Only', `default-src 'self'; report-uri ${CSP_ENDPOINT}; report-to csp`);
Next.js
Add an async headers() function to next.config.js:
const CSP_ENDPOINT = 'https://csp-report-to.com/r/YOUR_SITE_KEY';
/** @type {import('next').NextConfig} */
const nextConfig = {
async headers() {
return [
{
source: '/:path*',
headers: [
{
key: 'Content-Security-Policy-Report-Only',
value: `default-src 'self'; report-uri ${CSP_ENDPOINT}; report-to csp`,
},
{ key: 'Reporting-Endpoints', value: `csp="${CSP_ENDPOINT}"` },
],
},
];
},
};
module.exports = nextConfig;
If your config file is next.config.mjs, end it with export default nextConfig; instead. headers() isn't applied to a static export (output: 'export'); set the headers on whatever serves the exported files instead.
Netlify
Create a file named _headers in your publish directory (the folder Netlify deploys, such as public or dist). The header lines must be indented under the path.
/*
Content-Security-Policy-Report-Only: default-src 'self'; report-uri https://csp-report-to.com/r/YOUR_SITE_KEY; report-to csp
Reporting-Endpoints: csp="https://csp-report-to.com/r/YOUR_SITE_KEY"
Vercel
Add a headers section to vercel.json in your project's root:
{
"headers": [
{
"source": "/(.*)",
"headers": [
{
"key": "Content-Security-Policy-Report-Only",
"value": "default-src 'self'; report-uri https://csp-report-to.com/r/YOUR_SITE_KEY; report-to csp"
},
{
"key": "Reporting-Endpoints",
"value": "csp=\"https://csp-report-to.com/r/YOUR_SITE_KEY\""
}
]
}
]
}
For a Next.js app on Vercel, you can use the Next.js example above instead.
Check your setup
Your site's settings page has two checks under Check your setup.
Check my site loads a page of your site from our server and checks its headers:
- a
Content-Security-PolicyorContent-Security-Policy-Report-Onlyheader is there, and which one; report-uripoints to this site's endpoint, and not to an old key (after Regenerate key) or another site's;- the group named in
report-tois defined in aReporting-EndpointsorReport-Toheader, and points to this site; - the page is served over HTTPS.
It checks one page. Pages can send different headers (Magento's checkout does, for example), so check the pages you care about. Some hosts and firewalls block requests from servers: if the check gets an error, try another page, or use the live test.
Live browser test proves the whole path in a real browser: your site sends the headers, the browser reports, and the report arrives here. Press Start live test and you get a line of JavaScript. Open a page of your site, paste the line into the browser's developer tools console and press Enter. The line asks for a script from an address your policy doesn't allow, so the console shows a Refused to load the script message and the browser sends a report. Within about a minute the settings page shows where it came from and how: report-to (Chrome, Edge) or report-uri (Firefox, Safari). Run it in a second browser to prove the other path. The test report isn't stored as a violation and doesn't count toward your quota.
If the console shows no Refused to load message, your policy allows that script, for example with https: or * in script-src or default-src. Then nothing is reported, because nothing broke the policy.
Without an account, you can do the same by hand. Check the headers with curl (replace the URL with one of your pages):
curl -sI https://example.com/ | grep -iE 'content-security-policy|reporting-endpoints|report-to'
You should see the policy with your endpoint in it. Then open the page with the developer tools console open and run:
var s = document.createElement('script'); s.src = 'https://example.org/test.js'; document.head.appendChild(s);
The console shows [Report Only] Refused to load the script 'https://example.org/test.js', and a script-src violation for https://example.org appears in your dashboard within about a minute. That one is a real report: it counts toward your quota, and you can Resolve it once you've seen it.
How the endpoint responds
- It answers every report with
204 No Content, even when it doesn't store the report (an unknown key, an unverified email or a full quota). Browsers send reports in the background, so our response never affects your pages. - The one exception: a request body over 64 KB gets
413. - One request can carry up to 100 reports. Anything beyond 100 in a single request is dropped.
- It accepts both report formats:
report-urireports (application/csp-report) and Reporting API batches (application/reports+json). Other Reporting API report types, such as deprecation or network error reports, are ignored and don't count toward your quota.