Knowledge Base

Deploy a Content Security Policy

Build a policy around the resources your pages actually use, then test it before switching on enforcement.

1. Identify the required resources

Check scripts, styles, fonts, images, embedded content, API calls, and form destinations on representative pages. Include login, checkout, search, and error pages if they exist. Browser developer tools help identify which directive a resource needs.

2. Test without blocking

Content-Security-Policy-Report-Only: default-src 'self'; object-src 'none'; base-uri 'self'; frame-ancestors 'none'

This is a restrictive starting point for a site using same-origin resources, not a finished policy for every application. Report-only violations can be reviewed in the browser console. Remote collection requires a separately configured reporting endpoint and appropriate reporting directives; the header alone does not create a reporting service.

3. Handle inline code deliberately

Move simple inline scripts into external files where practical. For necessary inline scripts, use reviewed hashes or response-specific nonces. Nonces must be unpredictable and match the authorized script elements; do not copy a static sample nonce into production. Caching nonce-bearing HTML needs particular care.

A strict policy based on nonces or hashes can provide stronger script control than a long host allowlist. Avoid solving violations by allowing every HTTPS source or adding 'unsafe-inline' everywhere.

4. Enforce and verify

When the intended flows work, deploy the approved value through Content-Security-Policy. Keep a rollback plan and check the response that reaches the browser after server and CDN processing.

Assign one configuration layer to own the policy. Multiple enforcing headers apply together; a second, more permissive policy does not override the first. See Apache examples, Nginx examples, and CSP troubleshooting.

Sources

Copyright ©2026 MILAN INNOVATIONS LLC. All rights reserved.