Headers

Security Headers on GitHub Pages โ€” What Is Possible and What Is Not

Updated April 2026

Reading this article? Verify your fix in real-time. Scan your site headers โ†’ HeadersFixer

GitHub Pages does not support custom HTTP response headers. You cannot add HSTS, CSP, X-Frame-Options, or any security header directly. Here is exactly what you get by default and what workarounds exist.

What GitHub Pages gives you by default

HeaderValueNotes
Strict-Transport-Securitymax-age=31536000Set by GitHub โ€” good
X-Content-Type-OptionsnosniffSet by GitHub โ€” good
X-Frame-OptionsDENYSet by GitHub โ€” good
Content-Security-PolicyNot setYou cannot add it
Referrer-PolicyNot setYou cannot add it
Permissions-PolicyNot setYou cannot add it
CORS headersNot setYou cannot add them

What you cannot do on GitHub Pages

Workaround 1 โ€” CSP via meta tag

CSP can be set in an HTML meta tag instead of a header. It is less powerful (cannot use some directives like frame-ancestors) but works for most XSS protection:

<head> <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline';">
</head>

Limitations of meta CSP: cannot use frame-ancestors, sandbox, or report-uri. GitHub Pages already sets X-Frame-Options: DENY so clickjacking is covered.

Workaround 2 โ€” Move to a platform that supports headers

PlatformCustom headersFree tier
Vercelโœ… vercel.json headersโœ… Yes
Netlifyโœ… _headers fileโœ… Yes
Cloudflare Pagesโœ… _headers fileโœ… Yes
GitHub PagesโŒ Not possibleโœ… Yes

Workaround 3 โ€” Cloudflare proxy in front of GitHub Pages

Point your custom domain through Cloudflare (free plan). Use Cloudflare Transform Rules to add response headers:

Cloudflare Dashboard โ†’ Rules โ†’ Transform Rules โ†’ Response Header Modification โ†’ Add rule โ†’ add your security headers. This applies at the Cloudflare edge before the browser sees the response.

What securityheaders.com shows for GitHub Pages

A raw GitHub Pages site will typically get a C or D grade because CSP, Referrer-Policy, and Permissions-Policy are not set. If you need an A grade, move to Netlify, Vercel, or Cloudflare Pages โ€” all free and all support full header control.

Scan your site headers โ†’ HeadersFixer
Check if your domain is on the HSTS preload list โ†’ HSTS Preload Checker