DEV Community

A 10-minute HTTP security headers checklist for small websites

Most small sites ship with zero security headers. Adding a handful takes ten minutes and removes whole classes of attacks (clickjacking, MIME sniffing, some XSS). This is the checklist I use for static sites.

The headers

  • Content-Security-Policy - Limits where scripts, styles and images can load from - default-src 'self' (relax only what you need)
  • Strict-Transport-Security - Forces HTTPS - max-age=31536000; includeSubDomains (once HTTPS works everywhere)
  • X-Content-Type-Options - Stops MIME sniffing - nosniff
  • X-Frame-Options - Blocks clickjacking by framing - DENY (or use CSP frame-ancestors 'none')
  • Referrer-Policy - Controls what URL data you leak - strict-origin-when-cross-origin
  • Permissions-Policy - Turns off browser features you don't use - camera=(), microphone=(), geolocation=()
  • Cross-Origin-Opener-Policy - Isolates your window from popups - same-origin

Set them on Netlify

Create a _headers file in your publish folder:

/*
  Content-Security-Policy: default-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'
  Strict-Transport-Security: max-age=31536000; includeSubDomains
  X-Content-Type-Options: nosniff
  X-Frame-Options: DENY
  Referrer-Policy: strict-origin-when-cross-origin
  Permissions-Policy: camera=(), microphone=(), geolocation=()

Deploy, then check with:

curl -sI https://your-site.example | grep -iE 'content-security|strict-transport|x-content|x-frame|referrer|permissions'

CSP without pain

  • Start with Content-Security-Policy-Report-Only so nothing breaks.
  • Open the browser console and add only the sources that are reported.
  • Prefer no inline scripts. If you must, use a nonce or hash instead of 'unsafe-inline'.

Common mistakes

  • Setting HSTS before every subdomain supports HTTPS.
  • Using * in script-src, which defeats the point.
  • Testing only the home page: headers must apply to every path.

Test it

Run your URL through a header scanner and fix anything marked missing.

For quick offline checks of JSON responses, JWTs and hashes while debugging, I keep a free browser-only toolbox here: https://luxury-malabi-8a7447.netlify.app/toolbox.html (JSON, Base64, URL free; JWT, hashes and regex in the full version).

Written by Yogeshwaran Tech Tools. Corrections welcome.

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.