web.config file or IIS ManagerAdd a custom header to your site's web.config file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Content-Security-Policy-Report-Only"
value="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; report-uri https://cspwarden.com/api/v1/csp-report/YOUR-DOMAIN-TOKEN/; report-to csp-endpoint" />
<!-- Companion header: maps the "csp-endpoint" group named by report-to to your report URL -->
<add name="Reporting-Endpoints"
value="csp-endpoint="https://cspwarden.com/api/v1/csp-report/YOUR-DOMAIN-TOKEN/"" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>Ship both headers together: report-to names a reporting group (csp-endpoint), and the Reporting-Endpoints header maps that name to the actual HTTPS URL (" is the XML escape for the inner quotes the structured header needs). The legacy report-uri keeps older browsers working.
If you prefer the GUI approach:
Content-Security-Policy-Report-Onlyreport-uri https://cspwarden.com/api/v1/csp-report/YOUR-DOMAIN-TOKEN/; report-to csp-endpointReporting-Endpoints with value csp-endpoint="https://cspwarden.com/api/v1/csp-report/YOUR-DOMAIN-TOKEN/" so report-to can deliver reports (the IIS Manager value field takes the quotes literally)After reviewing violations in your CSP Warden dashboard, change the header name fromContent-Security-Policy-Report-Only toContent-Security-Policy:
<customHeaders>
<add name="Content-Security-Policy"
value="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; report-uri https://cspwarden.com/api/v1/csp-report/YOUR-DOMAIN-TOKEN/; report-to csp-endpoint" />
<add name="Reporting-Endpoints"
value="csp-endpoint="https://cspwarden.com/api/v1/csp-report/YOUR-DOMAIN-TOKEN/"" />
</customHeaders>You can also configure the header programmatically with PowerShell:
# Add CSP Report-Only header
Import-Module WebAdministration
$siteName = "Default Web Site"
$headerName = "Content-Security-Policy-Report-Only"
$headerValue = "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; report-uri https://cspwarden.com/api/v1/csp-report/YOUR-DOMAIN-TOKEN/; report-to csp-endpoint"
Add-WebConfigurationProperty -PSPath "IIS:\Sites\$siteName" `
-Filter "system.webServer/httpProtocol/customHeaders" `
-Name "." `
-Value @{name=$headerName; value=$headerValue}
# Companion header: maps the "csp-endpoint" group named by report-to to your report URL
# Single-quoted so the inner double quotes stay literal
$reportingValue = 'csp-endpoint="https://cspwarden.com/api/v1/csp-report/YOUR-DOMAIN-TOKEN/"'
Add-WebConfigurationProperty -PSPath "IIS:\Sites\$siteName" `
-Filter "system.webServer/httpProtocol/customHeaders" `
-Name "." `
-Value @{name="Reporting-Endpoints"; value=$reportingValue}web.config is in the root directory of your IIS site and the XML is valid.web.config. IIS is strict about well-formed XML.web.config or your application code.