Skip to content

HTTP Security Headers Guide: CSP, HSTS & More

Practical developer guide to HTTP security headers: configure Strict-Transport-Security (HSTS), Content-Security-Policy (CSP), and frame rules.

By BugSnaps Security Research · 2 min read · Updated

Add BugSnaps as a preferred source on Google(opens in a new tab)

Want more of our security guides? Select BugSnaps and confirm your choice on Google.

HTTP response security headers instruct modern browsers how to enforce transport encryption, restrict framing, isolate scripts, and handle MIME types. While headers do not fix broken server-side SQL queries or authorization bugs, deploying a consistent security header policy across your web application and API responses removes entire classes of browser-side exploitation.

Core HTTP security headers every web deployment should review

When auditing your production and staging responses, verify that your reverse proxy, CDN, or framework middleware emits these six defensive headers with appropriate directives:

  • `Strict-Transport-Security (HSTS)`: `max-age=63072000; includeSubDomains; preload` tells browsers to connect to your domain exclusively over HTTPS, preventing protocol downgrade and cookie interception on untrusted networks.
  • `Content-Security-Policy (CSP)`: defines approved origins (or cryptographic nonces) for scripts, styles, connect targets, and frame ancestors (`frame-ancestors 'none'`), significantly limiting the impact of XSS and clickjacking.
  • `X-Content-Type-Options: nosniff`: prevents the browser from MIME-sniffing a response away from its declared `Content-Type`, blocking uploaded text or image responses from executing as script.
  • `X-Frame-Options: DENY` (or `SAMEORIGIN`): protects older browsers alongside CSP `frame-ancestors` to prevent external sites from embedding your authenticated pages inside hidden clickjacking iframes.
  • `Referrer-Policy: strict-origin-when-cross-origin`: sends the full path on same-origin navigation but strips sensitive URL paths and query strings when a user clicks an external link.
  • `Permissions-Policy`: explicitly disables browser features your app does not use—such as `camera=(), microphone=(), geolocation=(), payment=()`—so embedded content cannot request them.

Verifying headers across HTML routes, APIs, and error pages

A common deployment oversight is applying security headers only on 200 OK HTML pages while omitting them on `/api/*` routes, static asset responses, or 404/500 error pages generated by an upstream load balancer. Configure headers at your outermost edge or framework layout and verify them automatically on every release candidate with MyPentest.

Pair HTTP security headers with Secure, HttpOnly, and SameSite cookie attributes, and verify them across both HTML and API routes with a free MyPentest scan.

Run a vulnerability scan on your website.

Verify your domain and use MyPentest to check for supported web and API weaknesses. Review findings and coverage; a clean scan does not rule out every CVE.