Skip to content

Field Notes

Security Headers That Matter—and How Not to Break Production

Learn how to deploy CSP, HSTS, frame protection, Referrer-Policy, Permissions-Policy and other HTTP security headers safely.

EmailLinkedIn
Security-header response pathBrowserCDNLoad balancerNGINXApplicationFinal response
Security-header response path
Header area Controls Rollout caution
HSTS Future HTTPS use Validate subdomains before includeSubDomains or preload
CSP Allowed resource locations and embedding Use report-only before enforcement
Ownership Which layer sets the policy Avoid duplicate CDN, proxy and app values
On this page

Environment covered: Public HTTP applications behind CDN, reverse proxy, NGINX, WordPress, Drupal or application routing layers

Security headers change browser behavior. The useful deployment question is which threat a policy controls and which application workflows that control can affect.

A short MIME-type baseline, an enforced CSP and cross-origin isolation need different validation. Treating them as one scanner checklist makes it easy to deploy a strict-looking response that breaks authentication or editing without demonstrating the intended protection.

The CMS rollout used here is hypothetical. Its duplicate policies, blocked editor script and login popup illustrate deployment risks; they are not observations from a customer incident.

Give the enforced policy one owner

In this scenario, the CDN adds a baseline Content Security Policy while the application adds a route-specific one. Each team inspects its own configuration and sees a reasonable policy. The browser receives both.

Multiple CSP policies are enforced together. The application cannot relax an edge policy merely by sending another header that allows more sources. A script allowed by one can still be blocked by the other. The effective behavior is more restrictive than either team’s isolated test suggested.

Before changing a directive, capture the response that the browser actually renders. Follow the redirects deliberately, compare the final HTML document with the immediate response, and include cached and uncached routes in the review.

curl -sS -o /dev/null -D - 'https://www.example.com/login/'
curl -sS -L --max-redirs 5 -o /dev/null -D - \
  'https://www.example.com/login/'

These are documentation-domain examples. A header on a redirect is not necessarily the policy on the final document. Error pages, static assets and API responses may follow other paths through the proxy configuration.

CSP: investigate the dependency before adding an exception

The browser console identifies a script blocked by script-src. That is stronger evidence than guessing which plugin the policy might dislike. Trace whether the script is expected, who serves it and which route needs it.

For a CMS, the answer may involve inline initialization, an editor plugin, consent controls or a third-party integration. A single global allowlist is often too crude. The application is usually the better place to generate per-response nonces or attach hashes to exact inline content because it knows what it rendered.

A nonce must be unpredictable and newly generated for the response. Copying a fixed nonce into a reverse-proxy snippet does not create that property. A hash is tied to exact content, so a build or plugin update can invalidate it. Shared HTML caching also needs to be designed consistently with nonce generation; cached markup and a freshly generated header must not disagree.

Use report-only to learn before blocking

Content-Security-Policy-Report-Only allows observation without enforcement. Use that window to exercise the actual editor, login, uploads, forms and embedded resources. Classify reports instead of adding every reported source to the allowlist: extensions, stale pages and unexpected scripts can all produce noise.

Report-only is preparation, not protection. Move a reviewed policy into enforcement with a route-specific rollback plan. For important transactions, test the failure path too: a form that renders correctly may still be unable to submit because form-action is wrong.

MIME and referrer controls: verify the actual responses

Not every header requires the same rollout. Correct MIME types and nosniff are a different operational decision from a nonce-based CSP or cross-origin isolation.

# Illustrative baseline inside a reviewed NGINX context.
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;

If JavaScript then fails because it is served as plain text, repair the asset’s declared type rather than removing nosniff. A stricter browser exposed an existing response error.

NGINX inheritance is another place a small local change can have a large effect. Under the default model, defining add_header in a location changes what it inherits from a parent. Newer versions also provide add_header_inherit; inspect the installed version and generated configuration instead of applying a remembered rule blindly. nginx -t checks syntax, not the final headers on every response code.

HSTS: commit only to HTTPS coverage you can maintain

HSTS tells supporting browsers to use HTTPS after they have learned a valid policy for the host. It does not make an invalid certificate valid, and it is not a substitute for covering the first hostname a user contacts.

Start with a deliberately short lifetime while verifying coverage. includeSubDomains broadens the commitment to subdomains that may have different owners and older services. Preload adds another distribution and removal process. Neither belongs in a release merely because a scanner offers more points for it.

A response change can stop renewing a policy, but it cannot instantly erase a long lifetime already stored in every client. Review forgotten hosts and renewal ownership before making that commitment. There is no useful universal max-age for a domain inventory nobody has checked.

Embedding, browser capabilities and cross-origin isolation

Frame restrictions address embedding and clickjacking. frame-ancestors can express approved ancestors; X-Frame-Options remains relevant for simpler compatibility needs. An application that must be embedded by an approved partner needs an intentional exception, not an indiscriminate removal of frame protection.

Permissions Policy restricts selected browser capabilities. A site with no camera or geolocation use has different requirements from a conferencing application. Check current directive support and the behavior of embedded frames before deploying an expansive deny policy.

COOP, COEP and CORP address browsing-context isolation and cross-origin resource use. They are not interchangeable with CORS, and they are not a general badge to attach to every page. A login popup can depend on a cross-origin relationship that a new isolation policy changes.

Obsolete controls deserve the same scrutiny. Adding X-XSS-Protection, HPKP or other historical headers for a score is not a modern security strategy. A header should earn its place by changing a browser behavior the team intends to control.

Keep enforcement and rollback observable

For the hypothetical CSP conflict, remove the unintended duplicate at its source, then verify the final browser policy. The application owns nonce generation for the markup it renders; the proxy and CDN need a compatible contract for caching and response headers.

Retain the previous policy and representative response captures. Exercise login, editor save, uploads, forms and approved embeds before enforcement, then monitor both browser violations and failed transactions. Rollback should restore a known policy for the affected route, rather than remove unrelated protections across the site.

A header scan can identify absence or an obvious configuration mistake. The release evidence must also show that the reviewed security control is enforced and the dependent workflows still complete.

Sources and further investigation

References support the protocol and product behavior discussed here; they are not evidence that the illustrative scenario occurred.

Continue the investigation

Need a second set of eyes?

Working through a similar production issue?

Discuss the technical context