Security headers on static hosting
Which security headers matter, which ones actually work as HTML meta tags, and how to add the rest on GitHub Pages, Cloudflare Pages and Netlify.
Security headers are instructions your server sends with each page, telling the browser what the page is allowed to do. They stop whole classes of attacks: injected scripts, clickjacking, leaking full URLs to other sites. Many checklists tell you to “add them as meta tags”. Most of them do not work that way.
What works whereLink to this section
| Header | What it does | As a <meta> tag |
Needs a real header |
|---|---|---|---|
| Content-Security-Policy | Limits where scripts, styles, images and connections can come from | Works, except frame-ancestors, report-uri and sandbox |
For those three parts |
| Referrer-Policy | Controls how much of your URL other sites see | Works (<meta name="referrer">) |
No |
| Strict-Transport-Security (HSTS) | Forces HTTPS on future visits | Ignored | Yes |
| X-Content-Type-Options | Stops browsers guessing file types | Ignored | Yes |
X-Frame-Options / frame-ancestors |
Stops your site being framed by others | Ignored | Yes |
| Permissions-Policy | Turns off camera, microphone, location and similar | Ignored | Yes |
So writing <meta http-equiv="X-Frame-Options" content="DENY"> gives a false sense of security. Use meta tags for CSP and referrer policy, and real headers for the rest.
A strict Content-Security-PolicyLink to this section
The strongest policy only allows files from your own site. This works if you avoid inline <script> code and style="" attributes, and host fonts yourself:
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'self'; base-uri 'self'; form-action 'self'; object-src 'none'; upgrade-insecure-requests">
<meta name="referrer" content="strict-origin-when-cross-origin">
If you load analytics or a CDN, add only those exact domains to the matching directive, for example script-src 'self' https://cdn.jsdelivr.net. Avoid 'unsafe-inline' for scripts; it removes most of the protection. This wiki uses the policy above.
Adding real headers by hostLink to this section
GitHub Pages cannot set custom headers. You get HTTPS automatically, and you can use the meta tags above. For the rest, put Cloudflare DNS in front:
- Move your nameservers to Cloudflare and keep your GitHub Pages DNS records, with the proxy (orange cloud) on.
- Set SSL/TLS mode to Full so Cloudflare talks to GitHub over HTTPS.
- Add a response header Transform Rule for all requests with:
X-Content-Type-Options: nosniff,X-Frame-Options: DENY,Permissions-Policy: camera=(), microphone=(), geolocation=(), andStrict-Transport-Security: max-age=31536000. - Check the result with MDN HTTP Observatory.
Cloudflare Pages and Netlify read a plain _headers file in your published folder:
/*
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
Referrer-Policy: strict-origin-when-cross-origin
Permissions-Policy: camera=(), microphone=(), geolocation=()
Strict-Transport-Security: max-age=31536000
Vercel uses a headers section in vercel.json.
Questions people ask
Does X-Frame-Options work as a meta tag?
How do I stop my site being shown inside another site's frame on GitHub Pages?
Tools on this page
- GitHub PagesFree, checked Oct 2026
- Cloudflare DNSFree tier, checked Oct 2026
- MDN HTTP ObservatoryFree, checked Oct 2026
- Cloudflare PagesFree tier, checked Oct 2026
- NetlifyFree tier, checked Oct 2026
- VercelFree tier, checked Oct 2026