‹ Back to Analyzer
Security Headers for Static Websites
Security headers tell the browser how strictly to treat your pages. On a static site they take a few lines to add and close several common gaps.
Headers are sent by your host or CDN, not stored in your HTML files. A source scanner cannot see them, so check them in your browser’s DevTools Network tab (select the page request and read the response headers) or with your host’s documentation.
Headers worth setting
- Content-Security-Policy (CSP): limits where scripts, styles, images and connections may load from. It reduces the damage of injected scripts.
- X-Content-Type-Options: nosniff stops browsers guessing file types.
- Referrer-Policy: controls how much of your URL is shared with other sites, for example
strict-origin-when-cross-origin. - Permissions-Policy: turns off browser features you do not use, such as camera or geolocation.
- frame-ancestors (in CSP) or X-Frame-Options: prevents other sites from embedding yours.
- Strict-Transport-Security (HSTS): keeps visitors on HTTPS. Most hosts add it for you on HTTPS sites.
Example for Netlify
Create a file named _headers in your publish folder:
/*
X-Content-Type-Options: nosniff
Referrer-Policy: strict-origin-when-cross-origin
Permissions-Policy: camera=(), microphone=(), geolocation=()
Content-Security-Policy: default-src 'self'; img-src 'self' data: https:; frame-ancestors 'self'
Roll out a CSP safely
Start with a policy that matches what your pages already load, open every page, and watch the browser console for blocked resources. Inline scripts and third-party tags are the usual surprises. The third-party scripts guide helps you list them first.
Headers are one layerThey reduce risk but do not replace secure code. Pair them with the frontend security checklist.
Open CodBy Analyzer