Skip to content
LockdownGuide

Security headers

HTTP security headers generator

Select your web application requirements to generate copy-paste HTTP response security headers with explanations of CSP directives and HSTS preloading.

Last updated October 24, 2026

Why HTTP Security Headers Are Essential for Modern Web Applications

HTTP security response headers provide an essential layer of defensive posture against common client-side web vulnerabilities, including Cross-Site Scripting (XSS), clickjacking, MIME-type confusion attacks, and SSL stripping.

According to web security assessments conducted by the Open Web Application Security Project (OWASP), a large majority of public web servers omit foundational security headers or misconfigure directives, leaving users exposed to automated attacks.

Key Security Headers and Their Directives

  1. Strict-Transport-Security (HSTS): Tells browsers that the site must only be accessed over HTTPS for a specified duration (typically 1 to 2 years, or 63,072,000 seconds). The preload directive qualifies the domain for inclusion in Chrome, Firefox, and Safari hardcoded browser preload lists.
  2. Content-Security-Policy (CSP): The primary defense against Cross-Site Scripting. CSP defines an explicit allowlist of authorized script, image, and font sources. Disallowing 'unsafe-inline' prevents injected script tags from executing in the visitor's DOM.
  3. X-Content-Type-Options: nosniff: Prevents browsers from MIME-sniffing a response away from the declared Content-Type, mitigating attacks where malicious script files masquerade as benign images or text files.
  4. X-Frame-Options / frame-ancestors: Restricts who can embed your web pages inside <frame>, <iframe>, or <object> elements, stopping clickjacking attacks.
  5. Permissions-Policy: Explicitly revokes access to browser hardware features (accelerometer, camera, geolocation, microphone) so compromised third-party scripts cannot spy on users.

Implementation Best Practices

  • Test in Report-Only Mode First: When introducing a strict CSP on existing web properties, use the Content-Security-Policy-Report-Only header paired with a reporting endpoint to discover broken third-party scripts before enforcing full blocking.
  • Set Headers on the Origin and the CDN: Configure headers at your edge CDN layer (Cloudflare Transform Rules or AWS CloudFront Function) as well as the origin server to ensure consistent policy application across cached assets.

Sources and further reading

Frequently asked questions

What is HSTS Preloading?
HSTS preloading registers your domain into hardcoded lists built into Google Chrome, Firefox, and Safari, guaranteeing that browsers connect via HTTPS on the very first visit before any DNS or HTTP redirect occurs.
Does CSP protect against SQL Injection?
No. Content Security Policy is a client-side browser defense against Cross-Site Scripting (XSS) and data exfiltration; it does not protect backend database layers against SQL injection.
Why is 'unsafe-inline' discouraged in CSP?
Allowing 'unsafe-inline' permits any inline `<script>` tag or HTML onclick handler to execute, effectively defeating the primary XSS mitigation mechanism of CSP.

Spotted an error or want a calculator we do not have yet? Tell us.