Remediation guides

Fixing Missing Security Headers in Nginx, Apache and Applications

Configure HTTP security headers in Nginx and Apache, introduce CSP safely and verify redirects, error responses and proxy behaviour after deployment.

A missing security header finding needs a response that fits the application. Headers can reduce browser exposure, but a universal block copied into every server can break embedded content, sign-in flows or third-party scripts. Identify the intended protection before choosing the policy.

Review the final responses received by the browser. A header configured at the origin can be removed, replaced or duplicated by a reverse proxy, CDN or application framework.

Choose the protection you need

ControlPurposeDeployment consideration
Content-Security-PolicyRestricts permitted content and browser capabilities.Derive allowed sources from actual application behaviour.
Strict-Transport-SecurityTells the browser to use HTTPS for future connections.Enable after HTTPS works reliably; review subdomains separately.
X-Content-Type-OptionsPrevents MIME sniffing for relevant resource types.Send accurate Content-Type values alongside nosniff.
Referrer-PolicyLimits referrer information sent on navigation.Choose a policy compatible with required integrations.
CSP frame-ancestorsControls who can embed the page.Enumerate legitimate parent origins if embedding is required.

Security-sensitive cookies also need suitable Secure, HttpOnly and SameSite settings. These are application session decisions rather than replacements for the response headers above.

Add baseline headers in Nginx

The example belongs inside an HTTPS server block. It illustrates baseline response controls, not a complete TLS or application configuration.

add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Strict-Transport-Security "max-age=31536000" always;
add_header Content-Security-Policy-Report-Only
    "default-src 'self'; object-src 'none'; base-uri 'self'; frame-ancestors 'none'" always;

Check the inheritance behaviour of the deployed Nginx version and configuration. A location that declares its own header directives can change what it inherits. Inspect successful responses, login pages, redirects and error responses rather than assuming the server-level block reaches everything.

Configure Apache response headers

With mod_headers enabled, the equivalent baseline can be set in the HTTPS virtual host:

Header always set X-Content-Type-Options "nosniff"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Header always set Strict-Transport-Security "max-age=31536000"
Header always set Content-Security-Policy-Report-Only "default-src 'self'; object-src 'none'; base-uri 'self'; frame-ancestors 'none'"

Use one deliberate ownership point for each header. If a backend already supplies it, check Apache's header tables and proxy behaviour to avoid conflicting values. Do not add HSTS to a general HTTP virtual host as a substitute for redirecting to HTTPS.

Move CSP from observation to enforcement

Report-only CSP does not enforce the policy. Exercise normal journeys and inspect browser console violations; configure an appropriate reporting endpoint if central collection is required. Include sign-in, payments, uploads, embedded tools and failure states.

Replace the report-only header with an enforced Content-Security-Policy after the allowed sources and script handling have been reviewed. Applications that require inline scripts should consider unpredictable per-response nonces or maintained hashes. Adding broad wildcards or unsafe-inline simply to silence reports weakens the resulting control.

Verify the result

Use a GET request to inspect the real response, for example curl -sS -D - -o /dev/null https://example.com/login. Check each relevant route at the public edge and, where authorised, at the origin. Test legitimate embedding and confirm an unapproved parent cannot frame the page.

Retain response evidence, browser test results and the deployed configuration. Schedule a further review when integrations or hosting change. Headers should evolve with the service rather than remain an unexamined one-off fix.

Further reading: OWASP HTTP headers guidance and Nginx headers module.

Read our testing methodology or discuss your assessment.

See your first test report this week.

Book a 30 minute demo. We will verify one of your targets with you and run a test against it, so you can judge the results on your own systems.

Book a demo