Security headers for a static site, starting from OWASP
Security headers are instructions your site sends with every page, telling the browser what the page may and may not do. A static site has no logins, forms, or database, so most web security advice doesn't apply to it. Headers do: they limit the damage if a bad script ever lands on a page, for example through a third-party tag.
Where the guidance lives
Don't take any one blog post's word for which headers to send. Read the sources the posts copy from, and check each against the others. These are the ones this site used:
- OWASP Secure Headers Project: the list of recommended headers and values. OWASP, the Open Worldwide Application Security Project, is the nonprofit most security checklists start from.
- OWASP HTTP Headers Cheat Sheet: one recommendation line per header. Start here.
- OWASP Content Security Policy Cheat Sheet: the deep version of the hardest header.
- OWASP Top 10: the risks behind the advice. Missing headers count as security misconfiguration; the scripts they stop count as injection.
- MDN Web Docs on Content Security Policy: what every directive means and which browsers support it.
- Google's CSP guide for Tag Manager and Analytics: the exact domains their scripts need. Every third-party tool you use should have a page like this; find it before you write your policy.
And the checkers, which grade your live site:
- Mozilla HTTP Observatory scores your headers and explains each deduction.
- securityheaders.com gives a letter grade.
- Google's CSP Evaluator reviews a policy for weak spots, such as overly broad domains.
The headers, and what this site sends
| Header | What it does | This site |
|---|---|---|
Content-Security-Policy | Lists the only places scripts, styles, images, and connections may come from | This site, plus Google Tag Manager and Analytics. Enforced. |
Strict-Transport-Security | Browsers use HTTPS only | One year |
X-Content-Type-Options | Stops browsers guessing file types | nosniff |
X-Frame-Options | Stops other sites framing yours to trick clicks | DENY, plus frame-ancestors 'none' in the CSP |
Referrer-Policy | Limits what other sites learn when visitors follow a link | strict-origin-when-cross-origin |
Permissions-Policy | Turns off browser features the site never uses | Camera, microphone, location, payments, and USB off |
X-XSS-Protection | An old browser filter that caused its own problems | 0, off, as OWASP advises |
Test the Content Security Policy before it can break anything
A Content Security Policy that's wrong blocks your own scripts, and the page breaks for every visitor. So:
- List every source your pages load. Your own files, inline scripts and styles, and each third party. For each third party, find its own CSP page.
- Test locally with the policy enforced. This site added the policy
to local copies of every page as a
<meta http-equiv="Content-Security-Policy">tag, loaded each in headless Chrome, and collected the console's "violates the following Content Security Policy directive" messages. Then it planted a script from an unlisted domain to prove the test catches one. - Ship it report-only. The
Content-Security-Policy-Report-Onlyheader makes browsers log violations without blocking anything. - Check the live site, then enforce. Open each page with the
browser's developer tools and read the console for violation messages. An automated
browser tool may not show them, because the browser writes those messages itself
rather than through the page's own logging. This site checked two other ways: it
listed every resource the page loaded and compared each against the policy, and it
listened for
securitypolicyviolationevents on the live page. When both stay clean, switch the header name toContent-Security-Policy.
For the CLI'ers
If you'd rather not open a browser, use curl to save a page's headers
and HTML to two files:
curl -s -D skunkyard.com.headers -o skunkyard.com.html https://skunkyard.com/
In skunkyard.com.headers, look for the policy line. It starts with
content-security-policy-report-only: while you test, and with
content-security-policy: once it's enforced. If neither is there, the
policy isn't reaching visitors.
grep -i content-security-policy skunkyard.com.headers
On this site, it prints:
content-security-policy: default-src 'self'; script-src 'self' 'unsafe-inline' 'wasm-unsafe-eval' https://*.googletagmanager.com; worker-src 'self' blob:; style-src 'self' 'unsafe-inline'; img-src 'self' data: https://*.googletagmanager.com https://*.google-analytics.com https://*.google.com https://*.g.doubleclick.net; connect-src 'self' https://*.googletagmanager.com https://*.google-analytics.com https://*.analytics.google.com https://*.google.com https://*.g.doubleclick.net https://pagead2.googlesyndication.com; font-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'
In skunkyard.com.html, look for anything the policy must allow:
- Other sites' addresses in
src,href, andactionattributes. Each domain must be in the matching directive, such asscript-srcfor scripts andform-actionfor forms. - Inline
<script>blocks andstyle=attributes. These need'unsafe-inline', a nonce, or a hash. <iframe>,<object>, and<embed>tags. These needframe-srcorobject-src.
grep -oE '(src|href|action)="https?://[^"]*"' skunkyard.com.html
grep -c '<script>' skunkyard.com.html
grep -cE 'style=|<iframe|<object|<embed' skunkyard.com.html
On this site's home page, they print:
src="https://www.googletagmanager.com/gtm.js?id=GTM-WH6WJZHS"
href="https://skunkyard.com/"
1
0
The first line is the Tag Manager script, which script-src allows with
https://*.googletagmanager.com. The second is the page's canonical link,
which the policy doesn't govern. The 1 is the inline Tag Manager snippet,
which 'unsafe-inline' allows. The 0 means no
style= attributes, frames, or embeds. Nothing on the page falls outside the
policy.
curl doesn't run scripts, so it can't see what a script loads after the
page opens. Tag Manager, for example, loads Analytics, which sends data to Google's
servers. For those, use the third party's own CSP page, or check in a browser.
Where this site departs from OWASP, and why
'unsafe-inline'scripts. OWASP and Google both prefer a nonce, a random value the server makes for each response. A static site on a CDN has no server to make one. The policy still blocks scripts from every domain it doesn't list.- No
includeSubDomainson HTTPS-only. OWASP suggests it, but this domain's mail-setup subdomains point to the mail provider's servers, and forcing HTTPS there could break mail apps. - No
preload, and one year instead of two. Joining browsers' built-in HTTPS-only list is hard to undo. Wait until the site's setup has settled.
What headers don't do
- They don't fix a vulnerable script you chose to load; a listed domain is trusted completely.
- They don't protect visitors on old browsers that ignore them.
- Every new third-party tool needs its domains added to the policy, and a deploy. That's the price of the protection.