Security headers · Practical guide
HTTP security headers: what to check first
Start with the HTML response visitors receive, then review script restrictions, HTTPS enforcement and embedding separately. A missing security header is a configuration finding, not proof of an exploitable vulnerability. Use the examples below to choose a policy, deploy it in the right place and check that the protection works while your page remains usable.
Fix a missing CSP without breaking the page
Suppose your page uses an inline script and analytics from another origin, but HeaderScan reports no enforced Content Security Policy. Immediately enforcing a self-only policy would block those scripts. Start with a candidate policy in Content-Security-Policy-Report-Only and use the browser console to find what it would block.
The example below permits same-origin resources and disallows plugins. It is a diagnostic starting point, not a finished policy for every site. It will flag inline scripts and external analytics without blocking them. No reporting endpoint is configured here: inspect violations locally in DevTools rather than expecting reports to arrive on your server. Your browser may also warn that a reporting endpoint is missing.
# Candidate response header for browser testing in staging
Content-Security-Policy-Report-Only: default-src 'self'; object-src 'none'; base-uri 'self' - Set the candidate header in the application middleware, web server or CDN rule that supplies this page. In DevTools, open Network, reload and confirm it appears on the document response.
- Open Console and test navigation, sign-in and forms. For each violation, decide whether the dependency is required, then remove it or give it a precise allowance. Use a nonce or hash for required inline scripts instead of broadly allowing inline code.
- Test the revised policy as Content-Security-Policy in staging. When required resources load and disallowed resources are blocked, deploy it and repeat the browser checks and HeaderScan scan. A Report-Only policy alone will still produce a missing-enforcement finding.
Reference: MDN: Content-Security-Policy-Report-Only
Inspect the final document response
Confirm the final URL and HTTP status before changing configuration. HeaderScan follows up to five redirects and checks the final response without signing in or running JavaScript. If it reaches a login page, error page or CDN challenge, the findings describe that response. Compare a normal page, a form and an error response separately.
In DevTools, select the document request under Network and inspect Response Headers. HeaderScan redacts full CSP values from public reports, so inspect the exact sources and nonces locally. If a header differs from your configuration, check application middleware, web server rules and CDN transformations in that order. Choose one owner for the policy and remove unintended duplicates.
This macOS/Linux command performs a GET request, follows redirects and prints each response header block. Read the last block and the final URL. It does not reproduce a signed-in browser session, and its output is not redacted. Replacing GET with curl -I would test HEAD, which can return different headers.
curl -q -sS -L --max-redirs 5 --max-time 30 \
-D - -o /dev/null \
--write-out '\nFinal: %{url_effective} (%{http_code})\n' \
'https://example.com/' Reference: curl: response headers and redirects
Repair the dependency that triggers a CSP violation
Read the violated directive and blocked resource in the browser console. script-src controls scripts; connect-src covers connections such as fetch requests; img-src and style-src cover images and styles. default-src supplies a fallback for fetch directives that you have not set. Give each required resource the narrowest suitable allowance.
For a required inline script, generate a cryptographically random nonce for each response and put the matching value in the CSP and the intended script element. Never deploy a fixed example nonce. A hash can suit fixed inline content, but must change when that content changes. Avoid adding unsafe-inline or a wildcard just to make a warning disappear.
If two layers send enforced CSP headers, the browser applies both policies. Adding a second, more permissive policy will not undo the first. HeaderScan checks selected policy patterns; browser testing is still needed to establish what loads and what is blocked.
| Browser finding | Repair to evaluate | Check after the change |
|---|---|---|
| Required external script blocked | Allow its exact trusted origin in script-src; review the code you are trusting. | The script loads and its feature works under the enforced policy. |
| Inline script blocked | Move it to an allowed script file, or use a fresh nonce or matching hash. | The intended script runs; an unapproved inline test script remains blocked in staging. |
| API connection blocked | Add the required API origin to connect-src, not only to script-src. | Submit the form and inspect the actual fetch response for errors. |
Reference: MDN: implementing Content Security Policy
Roll out HSTS and choose who may embed the page
First make HTTPS and certificate renewal reliable, and redirect the HTTP entry point to HTTPS. Send Strict-Transport-Security on HTTPS responses: browsers ignore it over HTTP. A short initial max-age lets you test before increasing the lifetime. The example lasts five minutes and is a rollout step, not a finished long-term policy. HeaderScan will still warn about this short lifetime during the rollout.
After receiving HSTS, the browser upgrades future HTTP requests for that host. Removing the header does not clear a remembered policy; max-age=0 must reach the browser over HTTPS to clear that host’s policy. Only add includeSubDomains after checking every affected subdomain. Preloading requires a separate, deliberate rollout and should not be added just to improve a score.
Framing controls who can embed your page. Add frame-ancestors to your intended CSP instead of replacing the whole policy. It has no default-src fallback; frame-src controls the opposite direction, the frames your page loads. Test both an allowed parent and a disallowed parent in staging. Keep any X-Frame-Options fallback consistent with your embedding requirements.
# Initial HSTS rollout on HTTPS responses only
Strict-Transport-Security: max-age=300
# No embedding: add this directive to your existing CSP
frame-ancestors 'none'
# Alternative for same-origin embedding
frame-ancestors 'self' - Request the HTTP URL in a fresh browser profile and confirm it reaches the intended HTTPS page without a certificate error.
- Inspect the HTTPS response for HSTS, then revisit the HTTP URL in that profile and check the browser upgrades it before sending an insecure request.
- Increase the HSTS lifetime after verifying HTTPS coverage and renewal. Check a partner iframe separately before enforcing framing restrictions.
Reference: MDN: Strict-Transport-Security
Verify the protection and the working page
For each change, record the URL, intended restriction and browser action that demonstrates it. Header presence alone cannot prove that every route is covered. Use the checks below for the other findings in your report; informational headers do not all need to be added.
Server version banners deserve a separate check at the layer emitting them. Remove unnecessary implementation details where supported, but keep the software patched: hiding a version does not repair a vulnerability.
| Policy | Practical change | Pass condition |
|---|---|---|
| X-Content-Type-Options | Send nosniff and correct Content-Type values for scripts and styles. | JavaScript and CSS load without MIME-type errors; fix a wrong Content-Type instead of removing nosniff. |
| Referrer-Policy | Evaluate strict-origin-when-cross-origin, or no-referrer when no referrer should be sent. | Inspect Referer on same-origin and external requests; only the intended URL information is sent. |
| Permissions-Policy | Disable unused features, such as camera=(), microphone=(), only if the page does not need them. | Required browser features still work; an intentionally disabled feature is denied. |
| COOP, CORP and CORS | Choose policies for the actual popup, resource-sharing and API requirements. | Test sign-in popups, allowed and denied origins, and relevant preflights; this scan does not exercise those flows. |
- Change one policy at its owner and inspect the final response in staging, including any CDN layer.
- Test the expected restriction and the normal journey: navigation, form submission, login, payments and embedded content where used.
- Deploy and repeat the checks on the same public URL. Rescan it to confirm the corresponding finding changed as expected.
- Inspect authenticated pages, assets and error responses separately before treating the change as a site-wide fix.
Reference: OWASP: HTTP security header guidance
Keep reading
Related guides
Cache-Control explained: no-cache, no-store and private
Choose Cache-Control for account pages, public HTML and versioned assets, then verify ETag revalidation and CDN behaviour with practical checks.
Read guide CookiesSecure, HttpOnly and SameSite cookies explained
Fix SameSite and session-cookie findings with Set-Cookie examples, host-only scope and browser checks for login, embedded content and logout.
Read guide Nginx configurationHow to configure security headers in Nginx
Add Nginx security headers to the correct HTTPS server, fix location inheritance and duplicates, then verify normal pages and error responses.
Read guide LaravelHow to add security headers in Laravel
Add response headers with Laravel middleware, register them correctly, test normal and error responses, and check proxy or CDN overrides.
Read guide CSP implementationHow to roll out Content Security Policy with Report-Only
Build and test a CSP candidate, connect matching nonces and reporting endpoints, then enforce it with a practical rollback plan.
Read guideHTTP response headers reference: security, cookies and caching
Look up common HTTP response headers, their purpose and the checks to make before changing a policy.
Open reference