Website hardening: from missing security headers to A+/A+/A+/100/99
Where I started
My website was fast, but it was missing important security headers. I added the headers, moved inline JavaScript into external files, tightened the TLS configuration, and enabled HTML caching at the edge. Subsequent tests returned A+ from SecurityHeaders.com, A+ from Mozilla Observatory, A+ from SSL Labs, and PageSpeed scores of 99 on mobile and 100 on desktop. Here is what I changed and two pitfalls I encountered.
The website consists of static HTML pages served by nginx behind my self-hosted infrastructure. A simplified request path looks like this:
Browser → Cloudflare (CDN/edge) → Traefik with TLS and WAF checks before delivery → nginx
With 74 pages, a homepage of roughly 11 KB, and a measured TTFB of 0.16 s, performance was already good. The security headers and configuration still needed attention:
| Check | Before |
|---|---|
Security headers, including HSTS, CSP, and X-Content-Type-Options | None present in the check |
| TLS at the origin | TLS 1.2 was still allowed |
| Edge caching of the tested HTML response | DYNAMIC – not served from the edge cache |
| Inline JavaScript / inline handlers | More than 100 instances across the website |
Even a fast static website benefits from additional browser protections. Appropriate headers help prevent unwanted framing and MIME sniffing, for example. They complement safe content and sound server configuration; a good grade alone does not guarantee a secure website.

Step 1 – Security headers: the basics
A few lines in the nginx server block provide an important foundation. I then add the CSP from Step 2 to these five headers:
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Permissions-Policy "camera=(), microphone=(), geolocation=(), interest-cohort=()" always;
add_header X-Frame-Options "DENY" always;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains" always;
Three details matter here:
- HSTS with
includeSubDomains: This setting requires browsers to use HTTPS for subdomains as well. Every affected subdomain must remain available over HTTPS with a valid certificate, including subdomains added in the future. Using a CDN alone is not enough to establish that. Only adopt the longmax-agein my example after checking this requirement. - HSTS without preloading: I deliberately chose not to submit the domain to the preload list. Removal is possible later, but it can take weeks or months to reach browsers. Adding the
preloadtoken alone does not put a domain on the list. - Preventing framing:
X-Frame-Options: DENYand CSPframe-ancestors 'none'prevent other websites from embedding my pages in frames. The overlapping settings account for differences in browser support.
The nginx inheritance trap: By default, a child block inherits its parent's add_header directives only if it defines none of its own. If I use add_header to set a separate Cache-Control header in the static-asset location block, I must account for the security headers there too under this inheritance model. always applies the headers regardless of response status, including error responses. Without it, the headers apply to specified success and redirect statuses, not just 200. nginx 1.29.3 and later also offer add_header_inherit, including a merge option; this example does not depend on that feature.
Step 2 – A restrictive CSP: move inline JavaScript into files
The most involved part was tightening the Content Security Policy. Initially, script-src 'self' allowed scripts only from the same origin. Without additional allowances for inline code, this directive blocks executable inline scripts and event handlers such as onclick.
This is a restrictive, source-based CSP. Security guidance generally uses the term “strict CSP” for a policy based on nonces or hashes. That approach differs from the source allowlist shown here.

The refactoring had three parts:
- Removed more than 100 inline handlers: Events such as
onclickandoncontextmenuare now handled throughaddEventListenerin external files. - Moved executable inline script blocks into files: Shared code now lives in four files:
site.js,home.js,toc-generate.js, andblog-cms.js. - Stored configuration as data: Blog-series pages contain their configuration in
<script type="application/json">blocks. These are data blocks, not executable JavaScript; external scripts read the data.
The initial policy allowed no third-party scripts. The subsequent checks revealed that Cloudflare Web Analytics needed an explicit allowance, as described in Step 5. The final CSP in the local configuration is this nginx directive:
add_header Content-Security-Policy "default-src 'self'; script-src 'self' https://static.cloudflareinsights.com; style-src 'self' 'unsafe-inline'; img-src 'self' https://media.martin-ehrentraut.de data:; media-src 'self' https://media.martin-ehrentraut.de; font-src 'self'; connect-src 'self' https://cloudflareinsights.com; object-src 'none'; base-uri 'none'; frame-ancestors 'none'; frame-src 'none'; form-action 'self'" always;
The long line is intentionally a complete nginx directive. Add it to the server block and account for the inheritance rules above. Before reloading, check the configuration with nginx -t in the appropriate nginx environment.
Images and media may load from my media subdomain as well as the same origin. Inline styles remain allowed for now, while inline JavaScript does not. The source list reflects my website and must be adapted to the resources another website actually needs. Each additional external service expands the set of sources the browser trusts.
During my test at the time, I opened all 74 pages in an automated headless run and observed no CSP violations; additionally, I tested interactively: language switching (DE/EN), the blog-series menu, article loading via fetch, and the “back to top” button. A fresh test should also cover navigation, menus, and other interactive features; loading each page once does not exercise every execution path.
Step 3 – TLS: 1.3 at the origin, at least 1.2 at the edge
There are two separate TLS connections:
- Browser → Cloudflare: I set “Minimum TLS Version” to TLS 1.2 at the edge. Connections using TLS 1.0 or 1.1 are therefore rejected.
- Cloudflare → Traefik: At the origin, I configured
minVersion: VersionTLS13in the relevant Traefik TLS option to require at least TLS 1.3. This connection runs from the CDN to my server; it is not confined to the host's internal network.
The original account records an SSL Labs improvement from B to A+. For a proxied domain, a public SSL Labs scan tests the reachable Cloudflare endpoints. It does not automatically verify the origin's TLS configuration, which needs a separate check.
The minimum TLS version and the permitted cipher suites are separate settings: TLS 1.2 also includes CBC suites. Raising the minimum version alone therefore does not mean that every CBC suite has been disabled.
Step 4 – Performance: cache HTML at the edge
Before the change, Cloudflare returned cf-cache-status: DYNAMIC for the tested HTML page. That response was not served from the edge cache; it says nothing about whether other resources were cached. Cloudflare does not cache HTML by default, so I created a Cache Rule for my public static pages.
The rule is restricted to the hostnames martin-ehrentraut.de and www.martin-ehrentraut.de and makes matching responses eligible for caching. Cache eligibility and cache duration are separate decisions.

Distinguish origin TTL from edge TTL: My local nginx configuration uses expires 5m; for HTML responses. This sets cache instructions at the origin, but does not establish a five-minute Edge TTL override. Cloudflare documents a minimum of two hours for that override on the Free plan and one hour on Pro. For your own setup, check the plan and selected rule, decide whether origin headers should be respected or overridden, and inspect repeated requests. CF-Cache-Status and, where present, Age help with this; a single HIT does not establish a particular TTL. A browser cache can also persist independently of the edge cache.
The media subdomain stays outside this broad HTML rule. Public media can have its own caching strategy. Protected content and time-limited downloads, including those using presigned URLs, need rules that prevent a shared cache from undermining access restrictions or validity periods.
curl -w '%{time_starttransfer}')Latency series: 0.20 s (baseline, Nov 1) → 0.16 s (after the header deploy) → 0.11 s and 0.07 s directly at an edge HIT. Only time_starttransfer (TTFB) was measured; single measurements, not a benchmark.
Effective edge TTL ≈ 5 minutes (an indication, not a stopwatch measurement): (1) an error entry showed age: 223 and was cf-cache-status: EXPIRED 70 seconds later – the actual expiry therefore lies between 223 s and 293 s. (2) a page entry showed age: 265; 70 seconds later it had been refetched from the origin with age: 39 – computed: 265 + 70 − 39 ≈ 296 s. Both observations are consistent with a refresh after ≈ 5 minutes. Caveat: Age can also be reset by revalidation, purge, or eviction.
Summary: the observations support a cache refresh after roughly five minutes. The API accepted an override of 300 seconds. Whether that override or the origin cache directives (max-age=300) drove the observed behaviour cannot be conclusively distinguished from the measurements.
MISS→HIT: homepage: request 1 MISS, request 2 HIT (age: 1), further HIT.
Step 5 – Web Analytics, CSP, and privacy
During verification, the DevTools console reported a blocked request for the Cloudflare Web Analytics script automatically injected on my website. I explicitly allowed the required script source:
script-src 'self' https://static.cloudflareinsights.com
The data endpoint depends on the integration. For sites proxied through Cloudflare, the documentation specifies /cdn-cgi/rum on the site's own domain. In that case, connect-src 'self' is generally sufficient. For non-proxied sites, it specifies https://cloudflareinsights.com/cdn-cgi/rum. My current local configuration also allows that external source; whether it is needed should be checked against the actual requests. The final policy above reflects that configuration.
Cloudflare describes Web Analytics as a service that does not collect or use visitors' personal data. This is the vendor's description of its analytics product and should be distinguished from other processing performed by the CDN service.
I updated the privacy policy to explain its use. Whether consent is required and which legal basis applies must be assessed against the actual integration and processing. The absence of cookies alone does not answer that question: Section 25 of Germany's TDDDG covers terminal-equipment protections beyond cookies, while processing personal data also requires assessment under the GDPR. Disabling JavaScript can prevent the browser-side beacon, but it neither replaces that assessment nor provides a general opt-out from other CDN processing.
Two pitfalls worth avoiding
- A cached 404 can remain visible after a restart. The original test recorded a 404 with
cf-cache-status: HIT(age 223) after an nginx restart, while the origin was simultaneously verifiably serving HTTP 200. The observation is consistent with an error response generated during the brief outage window of the container restart and adopted by the edge cache; conclusively proving its origin would require matching server logs. After roughly five minutes (TTL expiry) HTTP 200 was served again automatically. Lesson: after changes, check the status code and the cache status, purge the affected URL if needed, and account explicitly for error responses in the cache rule. Cloudflare can cache 404 responses; their lifetime depends on the applicable rules and headers. - Browser extensions can affect local Lighthouse runs. Extensions such as password managers can inject code that appears in the trace under URLs such as
chrome-extension://…. My initial local mobile test scored 84. A later Lighthouse run through PageSpeed Insights was independent of my local extensions and scored 99. Without comparable test conditions, the difference cannot be attributed entirely to extensions. For local comparisons, use a fresh profile without extensions and document the conditions. The PageSpeed Insights performance score is a lab measurement; available CrUX field data is reported separately.
Results
The table below reproduces the results recorded in the original draft. “–” means that no specific baseline score was documented. These are point-in-time results from November 2, 2026.
| Tool / check | Before | After |
|---|---|---|
| SecurityHeaders.com | – (none of the checked security headers) | A+ |
| Mozilla Observatory | – | A+ (115/100, 12/12 tests) |
| SSL Labs, public edge endpoints | B | A+ |
| PageSpeed mobile, Lighthouse lab test | – | 99 (FCP 0.8 s · LCP 2.0 s · TBT 0 ms · CLS 0) |
| PageSpeed desktop, Lighthouse lab test | – | 100 (FCP 0.3 s · LCP 0.6 s) |
| Tested HTML response at the edge | DYNAMIC | HIT (TTFB 0.07 s, down from 0.16 s) |

Sources and verifiability
Editorial status: November 2, 2026. Technical statements refer to primary sources; vendor pages may change after this date. Operational recommendations are phrased as such; the illustrations are AI-generated symbolic images.
- SecurityHeaders.com
- Mozilla Observatory
- SSL Labs
- PageSpeed Insights
- nginx headers module and inheritance
- Google: strict Content Security Policy
- HSTS preload removal
- Cloudflare edge cipher suites
- Cloudflare default cache behavior
- Cloudflare Cache Rule settings
- Cloudflare edge and browser cache TTL
- Cloudflare Web Analytics product description
- Cloudflare Web Analytics data collection and endpoints
- Lower Saxony data protection authority: TDDDG FAQ
- Google: PageSpeed Insights methodology