SiteTidy
HomeGuidesConfiguring Content Security Policy (Part 10): Production Hardening and Maintenance
Security

Configuring Content Security Policy (Part 10): Production Hardening and Maintenance

Keep CSP strong after launch. Build regression tests, monitor policy drift, review third-party permissions, validate strict CSP, maintain reporting and use a practical production hardening checklist.

Published on August 15, 2026Updated August 31, 2026
Configuring Content Security Policy (Part 10): Production Hardening and Maintenance

Getting a strong Content Security Policy into production is not the end of the job.

It is the point where the maintenance job starts.

A policy can be excellent on launch day and quietly degrade over the next year. A new analytics vendor adds three origins. A framework upgrade changes how styles are injected. Somebody restores 'unsafe-inline' during an incident and never removes it. An old payment domain remains trusted after the integration was replaced. Reporting stops because the endpoint moved. The CDN begins appending a second policy. A route introduced by a new service ships with no CSP at all.

None of those failures require a dramatic security mistake.

They happen because CSP is living application policy, and living policy drifts unless somebody owns it.

This final part turns the previous nine guides into an operational model: how to keep CSP understandable, testable and genuinely useful after the initial rollout.

A strong CSP is an application invariant

Teams often treat security headers as infrastructure configuration:

set it once
forget it

A better model is to treat important CSP properties as invariants.

For example:

Production pages must have an enforcing CSP.
Script trust must be nonce/hash based.
Production must not require unsafe-eval.
Object embeds must remain disabled.
Framing policy must remain explicit.
CSP violations must remain observable.

Those are requirements you can test.

Once they are expressed as requirements, regression becomes visible instead of accidental.

Define what “good” means for your application

There is no universal perfect CSP string.

But your application can have an explicit target architecture.

For a dynamic SaaS application that might be:

Script model       -> per-response nonce + strict-dynamic
Inline handlers    -> none
Eval                -> none in production
Object/embed        -> none
Base URI            -> none
Framing             -> none except documented embed routes
Forms               -> self + explicit identity/payment endpoints
Workers             -> self, blob only where documented
Third-party JS      -> owned, reviewed, route-limited
Reporting           -> enabled and monitored
Trusted Types       -> enforced on supported application surfaces

Now a pull request adding 'unsafe-inline' has to explain why the architecture changed.

Without a target model, policy review becomes “does the page still load?”

Put the policy in source control

Avoid building the canonical CSP through a sequence of manual CDN-dashboard edits.

Keep the authoritative policy in something reviewable:

  • application configuration;
  • Infrastructure as Code;
  • versioned reverse-proxy config;
  • deployment templates;
  • a dedicated policy module.

Then every change gets:

history
review
ownership
rollback

If emergency production changes are possible through a dashboard, reconcile them back into source immediately afterwards.

Configuration that exists only in a vendor UI is where undocumented security drift begins.

Give CSP a clear owner

“Security owns CSP” can be just as unhelpful as “developers own CSP” if neither statement identifies a person or team responsible for operational health.

A practical ownership model might be:

Application team
  -> application resource behaviour
  -> nonce/hash integration
  -> framework changes
  -> browser regression tests

Platform team
  -> header delivery
  -> CDN/proxy consistency
  -> reporting infrastructure

Security team
  -> policy design review
  -> dangerous exceptions
  -> threat model / periodic assurance

The exact split does not matter as much as avoiding gaps.

Somebody should know who investigates a CSP report spike on Monday morning.

Test header presence automatically

The cheapest useful CSP regression test is simply checking that the header exists where it should.

For example:

GET /
GET /login
GET /checkout
GET /account
GET /404-test

Assert:

Content-Security-Policy header exists
Expected security directives exist
Unexpected weak keywords do not appear

A simple test can catch:

  • a route deployed without middleware;
  • proxy config lost during migration;
  • CDN rule scoped incorrectly;
  • header accidentally renamed;
  • security headers missing from error pages.

Do not wait for a penetration test to discover that half the application stopped sending CSP three months ago.

Test policy semantics, not only header presence

This header exists:

Content-Security-Policy: default-src * 'unsafe-inline' 'unsafe-eval'

That does not mean you have meaningful XSS mitigation.

Add assertions around your intended model.

For example:

[ ] script-src exists
[ ] strict policy includes nonce/hash trust
[ ] unsafe-eval absent in production
[ ] object-src 'none'
[ ] base-uri explicitly restricted
[ ] frame-ancestors explicitly restricted
[ ] form-action explicitly considered

Tools such as CSP Evaluator can also help identify weak allowlists and common bypass patterns. The CSP Evaluator project itself is explicit that it is an aid rather than a proof of security, so use automated evaluation as another signal, not as a substitute for application understanding.

Run browser journeys under enforcement

Static policy analysis cannot tell you whether a real checkout works.

Your browser tests should exercise the routes that use unusual permissions.

For example:

Login
  -> identity redirect works

Dashboard
  -> API calls work
  -> WebSocket connects
  -> worker starts

Checkout
  -> provider script loads
  -> payment iframe loads
  -> challenge flow works

Upload
  -> blob preview works
  -> storage upload completes

Collect browser console errors and fail on unexpected CSP violations.

This is especially useful after dependency or framework upgrades.

Test nonces as a security property

For a nonce-based site, do more than confirm a nonce attribute exists.

Test that:

Response 1 nonce != Response 2 nonce
CSP nonce == trusted script nonce within each response
Attacker/untrusted markup does not automatically receive nonce
Cached pages do not reuse a fixed nonce

A fixed nonce can make the header look strict while destroying the property that makes the nonce valuable.

If a CDN caches HTML, test from the public edge — not only the origin server.

Hash-based CSP belongs in the build pipeline

For static sites, hash maintenance should be automated.

A robust flow looks like:

Build final HTML
      │
      ▼
Apply minification/transforms
      │
      ▼
Calculate hashes from final inline bytes
      │
      ▼
Generate CSP
      │
      ▼
Deploy HTML + matching policy together

Do not manually copy hashes into configuration after every release.

That guarantees somebody will eventually forget.

If a CDN modifies HTML after hash generation, include that transform in the build/policy calculation path or stop modifying hashed inline content at the edge.

Keep Report-Only active for future policy versions

One of the best long-term uses of Content-Security-Policy-Report-Only is testing the next policy while the current one remains enforced.

For example:

Content-Security-Policy:
  <current-production-policy>

Content-Security-Policy-Report-Only:
  <proposed-stricter-policy>; report-to csp

This lets you continuously move forward without risking the current protection.

Perhaps the current policy still allows one legacy host. The report-only policy removes it. Once reports show that nothing legitimate needs it, promote the stricter version.

CSP can improve incrementally rather than through rare rewrite projects.

Keep violation reporting useful

A CSP reporting system should answer questions such as:

Did violations increase after release X?
Which directive is producing the most app-originated violations?
Which route is affected?
Did a third-party vendor start using a new origin?
Are Trusted Types violations trending down?
Are there repeated attack-like payloads worth investigating?

It should not be a warehouse of millions of unclassified JSON documents.

Aggregate and trend.

Keep enough raw data for investigation, but separate operational signal from browser-extension noise.

Monitor reporting itself

Telemetry can fail silently.

Track basic reporting-pipeline health:

requests received
valid reports parsed
rejected/oversized requests
queue lag
storage errors
last report timestamp

If a site with millions of visits suddenly produces exactly zero reports for a month, you should know whether the policy became perfect or the collector broke.

Usually it is worth checking the collector.

Do not let reporting become an attack surface

The report endpoint is internet-facing and the payload is untrusted.

Maintain:

  • body-size limits;
  • rate limiting/abuse controls;
  • safe JSON parsing;
  • output encoding in dashboards;
  • retention policies;
  • access control;
  • sensitive-field redaction.

Do not render blocked-uri or script-sample directly into an admin page as trusted HTML.

Security telemetry should not create the next injection vulnerability.

Review third-party sources periodically

Every third-party permission should have an owner and purpose.

Maintain an inventory like:

Source/vendor         Purpose           Owner        Routes        Reviewed
----------------------------------------------------------------------------
ExamplePay            Payments          Payments     checkout      2026-08
ExampleMetrics        Analytics         Product      public/app    2026-08
ExampleChat           Support           CX           /app only     2026-08

Then periodically ask:

Do we still use it?
Does it still need JavaScript?
Can it be isolated in an iframe?
Did vendor CSP guidance change?
Can the source permission become narrower?
Does it still need to run on every route?

Removing an integration should include removing its CSP permission.

Old trust should not survive the dependency it belonged to.

Watch for wildcard creep

Policies often degrade one convenience at a time:

https://api.vendor.example

becomes:

https://*.vendor.example

then:

https:

because another endpoint appears.

Every expansion deserves a review.

Ask whether strict nonce/hash trust, route-specific loading or a different integration pattern avoids broad host trust.

A short policy is not automatically stronger, but broad wildcards are often a sign that nobody wants to understand the dependency graph anymore.

Treat 'unsafe-inline' as an exception requiring a reason

There are nuanced compatibility cases where 'unsafe-inline' can appear alongside modern strict-CSP fallback patterns without weakening CSP3 browsers as much as the string suggests.

But in a normal production policy, seeing:

'unsafe-inline'

should trigger a question.

For script-src, ask exactly which code requires arbitrary inline execution and why nonce/hash/refactoring cannot solve it.

For style-src, assess whether runtime styling genuinely requires the broader permission or whether nonces/build-time extraction are available.

Do not allow weak keywords to become invisible through familiarity.

Treat 'unsafe-eval' as an even louder exception

Production applications generally should not require arbitrary JavaScript string evaluation.

If 'unsafe-eval' appears after a framework upgrade, investigate before accepting it.

Possible causes:

  • dev configuration leaked into prod;
  • JIT/template compilation enabled accidentally;
  • legacy dependency;
  • experimentation tool;
  • code editor runtime;
  • incorrect WebAssembly workaround.

If only WebAssembly compilation is required, 'wasm-unsafe-eval' may be the narrower option on supporting clients.

Track the exception with an owner and removal plan.

Framework upgrades should trigger CSP regression testing

A framework upgrade may change:

  • runtime script injection;
  • inline styles;
  • hydration data;
  • chunk loader behaviour;
  • module preload output;
  • Service Worker tooling;
  • source-map/debug implementation;
  • official nonce support.

That means CSP belongs in upgrade QA.

For example, Astro 6 introduced stable built-in CSP support. Angular’s security tooling now has explicit CSP/Trusted Types mechanisms. Next.js nonce handling directly affects dynamic/static rendering.

Do not carry a three-year-old workaround forward if the framework now has a first-class solution.

Browser platform changes should trigger freshness reviews too

The web platform changes underneath long-lived policies.

Examples relevant in 2026 include:

  • Trusted Types moving into the modern cross-browser Baseline set;
  • block-all-mixed-content becoming obsolete/deprecated;
  • Reporting API guidance moving toward Reporting-Endpoints + report-to;
  • framework support for nonce/hash policies improving.

A CSP article — or production policy — can become technically stale without changing a line of code.

Schedule a periodic standards/docs review for security controls, even if the application itself is stable.

Verify production from the outside

Your regression tests prove what you intended to deploy. SiteTidy gives you an independent check of what the public endpoint is actually serving after proxies, CDNs and hosting rules have had their say.

Run Free Audit →

Check the final response at every delivery layer

A useful security-header path looks like:

Application
    │
    ▼
Web server
    │
    ▼
Reverse proxy / ingress
    │
    ▼
WAF
    │
    ▼
CDN / edge
    │
    ▼
Browser

Any layer may:

  • remove a header;
  • replace it;
  • append a second policy;
  • apply different rules by route;
  • cache mismatched nonce-bearing HTML.

Your authoritative truth is the response the browser receives.

Test that response automatically from outside the origin network where possible.

Include redirects, errors and non-HTML routes in the audit

Security-header checks focused only on HTTP 200 homepage responses miss a lot.

Inspect:

200 normal pages
301/302 redirects
404 pages
500/error pages
auth callbacks
maintenance pages
edge-generated responses
admin routes
embedded routes with different frame policy

Not every response needs an identical CSP — an API JSON response may not benefit in the same way as an HTML document — but differences should be intentional.

Keep route-specific policies understandable

Some applications genuinely need different policies.

For example:

Marketing     -> analytics allowed
Dashboard     -> WebSocket + worker
Checkout      -> payment frame
Embed route   -> permitted partner frame-ancestors
Admin         -> no third-party JS

Route-specific CSP can reduce unnecessary trust.

It can also become an operational nightmare if you have 80 subtly different policy strings.

Prefer shared policy building blocks with explicit variations rather than copy-pasted independent headers.

Version policy changes in deployment history

When CSP changes, record it as part of the release.

Useful metadata:

Application version: 4.18.2
CSP policy version: strict-v6
Change: removed old analytics host
Deployment: 2026-08-31 14:32

If reports spike or a workflow breaks, you can connect the symptom to a specific policy change quickly.

This is especially useful when application code and edge configuration deploy independently.

Security exceptions need expiry dates

Suppose a legacy vendor requires:

style-src 'unsafe-inline'

and replacing it cannot happen this sprint.

Document:

Exception: unsafe-inline style
Reason: LegacyVendor v2
Owner: Billing team
Created: 2026-08-31
Review/expiry: 2026-11-30
Replacement: Vendor v3 nonce support

Without an expiry/review date, temporary security exceptions become architecture.

This idea works for:

  • wildcard hosts;
  • unsafe-eval;
  • broad frame sources;
  • Trusted Types default policies;
  • legacy reporting directives;
  • route exclusions.

CSP review belongs in third-party procurement

It is much easier to reject a CSP-hostile vendor before integration than after the business depends on it.

Ask prospective frontend vendors:

Do you support CSP nonces?
Do you require unsafe-inline?
Do you require unsafe-eval?
Can the product run in an iframe?
Do you publish required CSP origins/directives?
Can assets be pinned with SRI?
Does the loader dynamically execute customer-supplied HTML/JS?
How are tag/config changes controlled?

Security architecture is part of product selection.

Add CSP to your Definition of Done for frontend dependencies

When a developer adds a browser dependency, the change should not be complete until its CSP impact is understood.

That might mean:

New dependency introduced
      │
      ├── no CSP change needed -> fine
      ├── additional connect-src -> document/review
      ├── new frame-src -> route-limit/review
      ├── runtime style nonce needed -> implement
      └── asks for unsafe-eval -> security/design review

This prevents the policy from becoming a cleanup project performed months after each feature ships.

Use a small policy generator instead of string concatenation everywhere

For a complex application, consider representing CSP as structured configuration:

const policy = {
  defaultSrc: ["'none'"],
  scriptSrc: [`'nonce-${nonce}'`, "'strict-dynamic'"],
  styleSrc: ["'self'"],
  connectSrc: ["'self'", apiOrigin],
  objectSrc: ["'none'"],
  baseUri: ["'none'"],
  frameAncestors: ["'none'"]
};

then serialise it in one tested place.

Benefits:

  • easier review;
  • fewer syntax mistakes;
  • explicit environment differences;
  • easier route variants;
  • automated assertions.

Do not build a huge home-grown CSP framework. A small, boring policy builder is enough.

Validate syntax and security separately

A syntactically valid CSP can still be weak.

A useful validation stack is:

1. Browser parser / DevTools
   -> does the policy parse?

2. CSP evaluation tool
   -> obvious bypass/weakness patterns?

3. Automated browser journeys
   -> does the application work?

4. Security review
   -> are the trust decisions actually defensible?

5. Production reporting
   -> what happens in the real world?

No one layer answers every question.

CSP Evaluator is useful, not authoritative

Google’s CSP Evaluator project checks policies for common bypass patterns and weaknesses, particularly around allowlists.

That is valuable.

But its own documentation makes clear that the built-in bypass list is not complete and the tool does not guarantee security.

Use it to catch things you missed.

Do not turn “CSP Evaluator is green” into a security certification.

Your application logic, Trusted Types policies, third-party scripts and allowed sources still need human understanding.

Run a periodic policy-diff review

Once a month or quarter depending on change rate, compare the current policy with an earlier known-good version.

Look for trust expansion:

-script-src 'nonce-...' 'strict-dynamic'
+script-src 'nonce-...' 'strict-dynamic' https://new-vendor.example

-connect-src 'self' https://api.example
+connect-src 'self' https://api.example https://*.metrics-vendor.example

For every expansion ask:

Why was this added?
Is it still needed?
Could it be narrower?
Who owns it?

Security drift becomes much easier to see as a diff than as one giant current-state header.

Remove dead CSP permissions aggressively

Permissions accumulate because removing them feels risky.

Report-only mode gives you a safe removal workflow.

Suppose you suspect:

https://old-cdn.example

is unused.

Deploy a proposed report-only policy without it while the current enforcing policy remains unchanged.

Observe real traffic.

If no legitimate violations appear across the required traffic cycle, remove the source from enforcement.

This is CSP garbage collection.

Maintain a small set of high-value alarms

Do not alert on every report.

Useful conditions might include:

  • sudden surge in application-originated script violations after deployment;
  • Trusted Types violations introduced by a new release;
  • critical route producing new frame/connect/form violations;
  • enforcing policy disappearing from a monitored route;
  • policy unexpectedly containing a forbidden weak keyword;
  • reporting pipeline silent unexpectedly.

Alert on actionable conditions, not raw browser noise.

The complete production hardening checklist

Before calling a CSP mature, review this end to end:

DESIGN
[ ] CSP target architecture documented
[ ] Strict nonce/hash script trust used where practical
[ ] object-src disabled unless genuinely required
[ ] base-uri explicit
[ ] frame-ancestors explicit
[ ] form-action explicit
[ ] third-party JS minimised and owned

NONCES / HASHES
[ ] Nonces cryptographically random
[ ] Nonces unique per response
[ ] CDN does not cache/reuse nonce-bearing HTML incorrectly
[ ] Hashes generated from final delivered bytes
[ ] SRI used where appropriate for immutable third-party assets

APPLICATION
[ ] Inline event handlers removed/refactored
[ ] Production does not depend on unsafe-eval without documented exception
[ ] Framework raw-HTML escape hatches reviewed
[ ] Runtime styling handled intentionally
[ ] Workers, frames, WebSockets and blobs tested
[ ] Trusted Types considered/enforced where appropriate

DEPLOYMENT
[ ] Policy version controlled
[ ] Header present on all intended HTML routes
[ ] Redirect/error/edge pages reviewed
[ ] No accidental duplicate enforcing policies
[ ] Public edge response verified
[ ] CSP changes have rollback path

REPORTING
[ ] Reporting-Endpoints/report-to configured
[ ] Legacy report-uri retained only where compatibility requires it
[ ] Collector treats reports as untrusted input
[ ] Reports aggregated and classified
[ ] Reporting pipeline itself monitored
[ ] Privacy/retention rules defined

TESTING
[ ] Browser E2E journeys run under enforcement
[ ] Unexpected CSP console violations fail tests
[ ] Nonce freshness tested
[ ] Policy semantics tested, not only header existence
[ ] CSP evaluation/scanning included as supporting signal

MAINTENANCE
[ ] CSP owner defined
[ ] Third-party permissions reviewed periodically
[ ] Temporary exceptions have expiry dates
[ ] Framework/browser changes trigger freshness review
[ ] Dead sources removed through report-only testing
[ ] Policy trust expansion reviewed as diffs

You do not need every advanced control on day one.

You do need to know which ones you have consciously deferred.

The annual CSP question is the wrong question

Do not ask once a year, “Is our CSP still okay?” Build enough automated checks and ownership into normal delivery that you know when it changes. Periodic review should confirm the system, not rediscover it.

Browse SiteTidy's security tools

The CSP model from this ten-part series

Across the series, the complete approach looks like this:

Understand XSS/browser trust
      │
      ▼
Inventory real application behaviour
      │
      ▼
Choose nonce or hash strict CSP
      │
      ├── explicit resource directives
      ├── strict-dynamic where useful
      ├── framing/form/worker controls
      └── Trusted Types where appropriate
      │
      ▼
Integrate with framework and third parties
      │
      ▼
Deploy in Report-Only
      │
      ├── collect real violations
      ├── separate noise
      └── fix application incompatibilities
      │
      ▼
Enforce progressively
      │
      ▼
Automated regression tests + reporting
      │
      ▼
Review drift and tighten over time

That is a much stronger model than “paste these twelve hostnames into script-src”.

Final thought

A good Content Security Policy is not impressive because it is long.

It is impressive because it is explainable.

A developer should be able to look at a permission and tell you what application behaviour requires it. A security reviewer should be able to identify the few places where trust is created. A deployment test should tell you when the policy disappears or weakens. A report should lead back to a route, release and feature. A third-party source should have an owner. A temporary exception should have an end date.

When CSP reaches that state, it stops being a fragile header everyone is afraid to touch.

It becomes what it should have been all along: a maintained browser security boundary that evolves with the application while continuing to make unintended code execution substantially harder.

Ready to audit your site?

Put this guide into practice immediately using our free tools.

Browse 180+ Free Tools