CSP and HSTS Without Breaking the Site: A Staged Security-Header Rollout
Security headers can reduce certain browser-side risks, but a poor rollout can block scripts, styles, fonts, analytics, forms or whole parts of a website. Content Security Policy (CSP) and HTTP Strict Transport Security (HSTS) should therefore not be introduced by copying someone else’s configuration and immediately enabling the strictest values.
A staged workflow inventories real dependencies, uses CSP in report-only mode, investigates unexpected sources, introduces enforcement in controlled steps and considers HSTS only after HTTPS readiness has been confirmed. The W3C CSP Level 3 specification explains enforcement and report-only behaviour, while RFC 6797 defines HSTS behaviour.
1. Inventory resources and routes before writing a policy
Review the home page, articles, contact form, login, payment if present, administration and every localisation. Record where scripts, styles, images, fonts, frames and network requests come from. Include your own subdomains, content delivery networks, analytics and third-party services that load only after consent or another user action.
An inventory is not permission at any cost. Every external source needs an owner and reason. If you do not know why a domain appears, investigate before allowing it. Identify inline scripts and styles too, because broad values such as unsafe-inline reduce the policy’s value. Do not remove them blindly in production; plan a nonce, hash or implementation change and test it.
| Stage | Evidence before continuing |
|---|---|
| Inventory | Known sources for key routes and functions |
| CSP Report-Only | Reports received and classified |
| CSP enforcement | Key functions work without unexpected blocking |
| HSTS | HTTPS, certificates and covered subdomains verified |
2. Introduce CSP Report-Only first
The Content-Security-Policy-Report-Only header lets a browser report policy violations without enforcing the policy. The W3C specification states that report-only policy monitors behaviour but does not block resources, enabling iterative deployment. It is not protection by itself and must not be presented as a finished security state.
Start with a policy reflecting known dependencies and send reports to a controlled endpoint. Consider privacy and report volume. Deduplicate repeats, separate extensions and bots from real traffic, and connect every allowed source to a function and route. Report-only behaviour cannot be reliably substituted with a meta element; deliver it as an HTTP header.

3. Turn real dependencies into a narrow CSP
Directives separate resource types: script-src for scripts, style-src for styles, img-src for images, font-src for fonts, connect-src for network requests and frame-src for frames. default-src can provide a baseline while explicit directives describe exceptions. The policy should be narrow enough to block the unexpected while matching the site’s actual architecture.
For scripts, prefer a nonce or hash supported by a controlled build and rendering process. Adding a domain does not imply trust in every piece of content it can serve. Avoid wildcards and broad schemes unless necessary. If a function requires a problematic source, document the risk and remediation plan instead of silently widening the entire policy.
4. Move to enforcement by route and directive
Do not jump from a broad report-only policy to strict enforcement across the whole site. Choose a lower-impact route or begin with directives whose resources are well understood. Keep a stricter report-only policy as the trial for the next step while the active policy protects the scope already verified.
For each stage, save the exact header, change time, tested routes and known exceptions. Test login, forms, submission, search, language links, video, maps, analytics and consent management. An automated HTTP-header check is not enough; inspect the rendered interface and browser console as well.
5. Enable HSTS only when HTTPS is genuinely ready
HSTS tells the browser to use HTTPS for a host during the max-age period. Under RFC 6797, a header received over insecure HTTP transport must be ignored. Correct HTTPS delivery and a valid certificate must therefore exist before HSTS can perform its role.
includeSubDomains covers subdomains and must not be added until every relevant subdomain is HTTPS-ready. Preload is a separate, longer-lived decision, not a starting step. Begin with a short max-age only after verification and increase it after monitoring confirms stability. A securely received max-age=0 can remove a known policy, but existing cache and preload status can make rapid rollback difficult.
6. Prepare verification and rollback for every stage
Before changing anything, save the current headers and configuration. Define one authoritative place for the policy so rules are not duplicated across a CDN, server and application. The rollback plan should remove only the new stage and restore the previously verified value. HSTS rollback is not immediate for browsers that already remember the policy, making caution before activation especially important.
After each stage, check uncached responses, several browsers, mobile and desktop rendering, the console, reports, key conversions and rarely visited pages. Do not treat an absence of reports as proof that everything works; the report endpoint itself may be broken. Verify the reporting channel with a controlled test.
- Save existing headers and inventory dependencies by route.
- Deploy CSP Report-Only and confirm that reports actually arrive.
- Classify violations; do not allow an unknown source without a reason.
- Enforce on limited scope and test real functions.
- Verify HTTPS and certificates for the host and every covered subdomain.
- Increase HSTS max-age in stages and preserve evidence for each step.
7. Frequently asked questions
Does CSP Report-Only protect the site?
No. It reports violations without blocking and supports measurement before an enforced policy.
Can I copy CSP from another site?
Not without analysis. Dependencies, routes, inline code and third-party services differ between sites.
Does HSTS automatically redirect the first HTTP request?
Only after the browser has securely received and remembered the policy; first contact and preload have separate constraints.
When should includeSubDomains be used?
Only when every relevant subdomain has valid HTTPS and is ready for mandatory enforcement.
Does a security scanner prove that the site works?
No. It checks part of the configuration; functionality, localisations and user journeys need separate tests.
What should stop a rollout stage?
A blocked key function, unexplained dependency, broken reporting channel or unverified HTTPS coverage.
8. Conclusion
CSP and HSTS are controlled changes, not one copied configuration line. Inventory dependencies, confirm report-only measurement, narrow the policy using evidence, enforce in stages and test every function. Consider HSTS only when HTTPS, certificates and covered subdomains are stable, recognising that rollback can be slower than an ordinary header change.
Sources: W3C: Content Security Policy Level 3, RFC 6797: HTTP Strict Transport Security, OWASP Secure Headers Project. Accessed 17 November 2026.
Send us the site address and key functions for an assessment of a safe, staged header rollout.