Security headers are instructions a server sends with every response telling the browser how to behave. They are free to deploy and block whole categories of attack.
The headers that matter
- Strict-Transport-Security (HSTS) โ forces HTTPS for a set period. Example:
max-age=31536000; includeSubDomains; preload. - Content-Security-Policy (CSP) โ controls which sources of scripts, styles and images are allowed, the single strongest defence against cross-site scripting (XSS).
- X-Frame-Options โ
SAMEORIGINstops your site being framed by attackers (clickjacking). - X-Content-Type-Options: nosniff โ stops the browser guessing a file type and running a non-script as script.
- Referrer-Policy โ
strict-origin-when-cross-originlimits how much URL data leaks to other sites. - Permissions-Policy โ disables powerful features (camera, microphone, geolocation) you do not use.
Getting started
Start with HSTS and X-Content-Type-Options (both safe and instant), then add X-Frame-Options. CSP is the most powerful but needs testing โ begin in report-only mode, watch what breaks, then enforce. A scan of your site headers shows which are present and which are missing.