How to Fix Missing Content-Security-Policy Headers
Introduce CSP safely with Report-Only, then adapt Apache or Nginx to your real resources.
Start with an inventory
Content-Security-Policy is a browser-enforced policy delivered through HTTP headers. Before adding directives, list the scripts, styles, frames and services your website genuinely uses. A copied policy can break login, analytics or embedded content.
Observe before enforcing
Use Content-Security-Policy-Report-Only to test a candidate policy. It reports violations in developer tools without enforcing that policy. Report collection requires a reporting endpoint and separate configuration. Report-Only is not equivalent to an enforced CSP.
Minimal Apache example
The following example observes frame embedding restrictions only. It is not a complete script or resource policy. In Apache it requires mod_headers and permission to set headers in the relevant configuration or .htaccess.
Nginx placement matters
Set the header in the appropriate server or location block. Header inheritance and existing add_header directives matter: merge with the current configuration rather than replacing it blindly. Test the configuration and have an administrator reload the server.
Apache (mod_headers): Header always set Content-Security-Policy-Report-Only "frame-ancestors 'self'" Nginx: add_header Content-Security-Policy-Report-Only "frame-ancestors 'self'" always;
Build your real policy
Once you understand the resources, add the appropriate default-src, script-src, style-src and other directives. Nonces or hashes can help avoid broad inline script permissions, but require application integration. Do not simply add unsafe-inline or wildcard sources to silence errors.
Verify after deployment
Check the final HTTPS response and use browser developer tools on representative pages. Test forms, checkout, authentication and embedded content before enabling enforcement. The headers tool checks basic presence; it cannot prove that every directive is correct.
Recommended next step
Reference: Official documentation