A 10-minute HTTP security headers checklist for small websites

2026-11-29来源 dev.toEnglish

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

Header What it does Safe starting value
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

  1. Start with Content-Security-Policy-Report-Only so nothing breaks.
  2. Open the browser console and add only the sources that are reported.
  3. 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.

原文:https://www.a8q9.cn/en/article/a-10-minute-http-security-headers-checklist-for-small-websites-d8c63d.html

相关文章