HTTP security headers are the cheapest security work a website can do: a few lines in the server or CDN config, no code change. They are also easy to lose. A new CDN rule, a framework upgrade or a migration to another host can drop them silently, and nothing breaks for visitors, so nobody notices.
This post shows how to check them with curl, then with a short Python script for a list of sites, and what the results actually mean.
The headers worth checking
-
Strict-Transport-Security (HSTS): tells the browser to use HTTPS only for this host. Without it, a visitor who types
example.comcan be served over plain HTTP first. Amax-ageof at least 6 months (15768000 seconds) is the usual baseline. -
Content-Security-Policy (CSP): lists where scripts, styles and frames may load from. It is the browser-side defence against injected scripts. A CSP whose
script-srcallows'unsafe-inline'without a nonce or hash removes most of that defence. -
Clickjacking protection:
X-Frame-Options: DENY(orSAMEORIGIN), or the CSP directiveframe-ancestors. Without either, another site can load yours in an invisible frame. - X-Content-Type-Options: nosniff: stops the browser from guessing a file type, for example running an uploaded "image" as a script.
-
Referrer-Policy: controls how much of the URL is sent to other sites in the
Refererheader. URLs with tokens or search terms leak without it. - Permissions-Policy and Cross-Origin-Opener-Policy: turn off browser features you do not use (camera, geolocation...) and isolate your window from pages it opens.
Two things to look at besides the headers: a Server or X-Powered-By value that contains a version number (free information for anyone matching versions to known bugs), and cookies set without Secure, HttpOnly or SameSite.
Option A: curl for one site
curl -sI https://github.com | grep -i -E "strict|content-security|x-frame|x-content|referrer|permissions|cross-origin"
-I sends a HEAD request and prints only the headers. One catch: some servers answer HEAD differently from GET. If a header seems missing, check again with curl -s -D - -o /dev/null https://github.com, which sends a normal GET and prints its headers.
Option B: a Python script for a list
Standard library only. It follows redirects, so it checks the page a visitor really lands on, and it still reads the headers of a 403 or 404 page:
import sys, urllib.request, urllib.error
WANTED = {
"strict-transport-security": "HTTPS only, no downgrade",
"content-security-policy": "limits where scripts can load from",
"x-content-type-options": "should be nosniff",
"referrer-policy": "controls what the Referer header leaks",
"permissions-policy": "turns off camera, mic, geolocation...",
"cross-origin-opener-policy": "isolates the window from popups",
}
def check(url):
if "://" not in url:
url = "https://" + url
req = urllib.request.Request(url, headers={"User-Agent": "header-check"})
try:
resp = urllib.request.urlopen(req, timeout=20)
except urllib.error.HTTPError as e:
resp = e # a 403 or 404 page still has headers
h = {k.lower(): v for k, v in resp.headers.items()}
print(f"{url} -> {resp.url} ({resp.status})")
for name, why in WANTED.items():
if name not in h:
print(f" missing {name}: {why}")
csp = h.get("content-security-policy", "")
if "frame-ancestors" not in csp and "x-frame-options" not in h:
print(" missing clickjacking protection (X-Frame-Options or frame-ancestors)")
if "'unsafe-inline'" in csp and "nonce-" not in csp and "sha256-" not in csp:
print(" CSP allows 'unsafe-inline' scripts")
for name in ("server", "x-powered-by"):
if any(c.isdigit() for c in h.get(name, "")):
print(f" {name} leaks a version: {h[name]}")
for c in resp.headers.get_all("Set-Cookie") or []:
flags = c.lower()
lacks = [f for f in ("secure", "httponly", "samesite") if f not in flags]
if lacks:
print(f" cookie {c.split('=')[0]} lacks {', '.join(lacks)}")
for line in open(sys.argv[1], encoding="utf-8"):
if line.strip():
check(line.strip())
Run it with python check_headers.py sites.txt. Output from a real run:
https://example.com -> https://example.com (200)
missing strict-transport-security: HTTPS only, no downgrade
missing content-security-policy: limits where scripts can load from
missing x-content-type-options: should be nosniff
missing referrer-policy: controls what the Referer header leaks
missing permissions-policy: turns off camera, mic, geolocation...
missing cross-origin-opener-policy: isolates the window from popups
missing clickjacking protection (X-Frame-Options or frame-ancestors)
https://github.com -> https://github.com (200)
missing permissions-policy: turns off camera, mic, geolocation...
missing cross-origin-opener-policy: isolates the window from popups
cookie _octo lacks httponly
https://www.mozilla.org -> https://www.mozilla.org (200)
missing permissions-policy: turns off camera, mic, geolocation...
CSP allows 'unsafe-inline' scripts
Read results with judgement. A missing HttpOnly is expected on a cookie that the site's own JavaScript must read. And the 'unsafe-inline' test here is crude: it looks at the whole policy, so an 'unsafe-inline' in style-src alone would also trigger it (on mozilla.org it is really in script-src).
Limits of this script: one page per site, no grade, no security.txt check, and it does not refuse private addresses, so do not feed it URLs from untrusted users.
Option C: a hosted checker with a grade
Disclosure: this one is ours. We publish Security Headers Checker on Apify. It runs the same checks on a list of sites and adds an A to F grade, findings with a severity (high, medium, low), a read of security.txt (RFC 9116: Contact, Expires, expired file), and it refuses URLs that resolve to private or local addresses, also after a redirect.
{
"urls": ["github.com", "example.com", "https://www.mozilla.org"],
"checkSecurityTxt": true
}
On a real run, example.com gets grade F (score 0) with high findings for HSTS and CSP, and github.com gets grade B (score 80): permissions-policy and cross-origin-opener-policy missing, one cookie without HttpOnly, and a security.txt found. The score adds points per good header (HSTS 20, CSP 25, clickjacking 15, nosniff, Referrer-Policy, Permissions-Policy and COOP 10 each); any high finding caps the grade at C.
It is free during launch: no per-URL fee at the moment, only Apify's platform usage, which the Free plan's monthly credit covers for normal use. Scheduled weekly, it tells you when a deploy dropped a header.
Its limits, stated plainly:
- It grades one response per URL; other pages or API routes can send different headers.
- The grade is a checklist of well-known headers, not a security audit. A good grade does not mean a site is secure.
- It does not run JavaScript, and sites that block automated clients are reported with the headers of their block page.
- The CSP check is a set of simple rules, not a full policy evaluation.
- Only check sites you are allowed to look at. It sends normal GET requests and does not scan or test for vulnerabilities.
What to fix first
- HSTS, once every subdomain works over HTTPS.
-
X-Content-Type-Options: nosniffandframe-ancestors 'self'(orX-Frame-Options): almost never break anything. - CSP last, in
Content-Security-Policy-Report-Onlymode first, so you see what it would block before it blocks it.
Top comments (1)
This is the kind of checklist I wish more teams ran on a schedule, not just once. The line that stuck with me is that headers are easy to lose — a CDN rule, a framework upgrade, or a migration can drop them silently, and nothing visibly breaks, so nobody notices. That is exactly how a small regression becomes a quiet security hole.
I also liked that you called out the limits of your own script instead of hiding them, especially the crude unsafe-inline check. Flagging style-src the same way as script-src is the sort of false positive that makes people stop trusting a checker, and noting that mozilla.org really does have it in script-src shows you actually ran it against real sites. The grading detail helps too — a high finding capping the grade at C makes the score harder to game than a simple points total.
One thing I would add to the fix-first list: run the check after every deploy, not just when you set headers up. In my own work, the drift after a change is where things slip. Which header do you see missing most often in the wild, HSTS or a real CSP?