What a security headers grade does and does not tell you
A header grade is a configuration check on one response. It tells you whether the browser has been given certain instructions. It does not tell you whether your application has an XSS hole, a broken access control or an injectable query. A site can score an A and still be exploitable, and a site can score an F and have no exploitable bug at all.
So treat the grade as a to-do list for hardening, not as a verdict. Our free Security Headers Grader makes one GET request and grades nine checks from A+ to F. It is a passive check of what your server sends, nothing more. It also shows why checkers differ: it reads CSP script directives in the order the specification defines (script-src-elem falls back to script-src, then default-src), it ignores 'unsafe-inline' when a nonce or hash is present, and it reads frame-ancestors before X-Frame-Options. It does not grade the Server header, because its requests leave through Cloudflare, which replaces that header.
HSTS: ramp up max-age, and treat preload as a separate decision
Strict-Transport-Security tells the browser to use HTTPS only for your host. It has to be sent over HTTPS; browsers ignore it when it arrives over plain HTTP. The directive that bites is max-age: once a browser has seen a long value, it will refuse plain HTTP to that host for that long, and you cannot cancel it from the server side until the browser next makes a secure request and sees a new value.
That is why a ramp-up is sensible. Start with a day, move to a week once nothing has complained, then a month, then a year. A forgotten HTTP-only service on a subdomain is the usual casualty, which is also why includeSubDomains deserves a look at your DNS before you add it: it applies the policy to every subdomain, including the ones nobody remembers.
preload is a different commitment. It is not part of the HSTS specification; it asks browsers to ship your domain in a built-in list so even the very first visit is HTTPS. hstspreload.org requires a valid certificate, an HTTP-to-HTTPS redirect on the same host if you serve port 80, HTTPS on every subdomain, and a header on the base domain with a max-age of at least 31536000 seconds, includeSubDomains and preload. It also warns that inclusion cannot easily be undone and that removal can take months to reach users. Add it only when you are sure you can serve every subdomain over HTTPS for the long term. You can check your own state with the HSTS preload checker, and the CryptoCheck tool grades HTTPS hygiene from the HSTS header, preload status and cookie flags only.
Strict-Transport-Security: max-age=31536000; includeSubDomains
Content-Security-Policy: start in Report-Only
A CSP is the header most likely to break pages. The reason is simple: it blocks things your pages already do, and you only learn what those are by trying. The answer is Content-Security-Policy-Report-Only, which logs violations without blocking anything. Run it for a week or two, read what it reports, fix or allow what is legitimate, and only then switch the header name to Content-Security-Policy.
If you already have an enforced CSP, do not paste a starting point over it. Send the new policy as Report-Only alongside the old one and compare. A browser honours both headers at once.
The directive that matters most is script-src. Prefer a per-response nonce or a hash over 'unsafe-inline': when a directive contains a nonce or hash, browsers ignore 'unsafe-inline', so you can leave it in as a fallback for very old browsers without weakening the modern policy. A nonce must be unpredictable and different on every response, which means static HTML cannot use one; hashes suit static files but must be recalculated whenever the script changes. Allowlisting hostnames is weaker than it looks, and we explain how it fails in CSP nonces and allowlist bypasses.
Be careful not to treat style-src as the same problem. Under style-src, 'unsafe-inline' permits inline <style> elements and style attributes. That is a real weakness, but injected script runs code and injected CSS mostly changes presentation, so most teams reasonably fix script-src first and accept 'unsafe-inline' for styles while their framework still emits inline style attributes. Do not accept it for scripts.
X-Content-Type-Options: nosniff
This one is cheap. X-Content-Type-Options: nosniff is the only valid form, and it makes the browser block a script response that is not served with a JavaScript MIME type and a stylesheet that is not text/css. The only way it breaks a site is if you were serving scripts or styles with the wrong Content-Type, which is worth fixing anyway.
Clickjacking: frame-ancestors and X-Frame-Options
To stop other sites embedding yours in a frame, use the CSP frame-ancestors directive. It does not fall back to default-src, so a policy that says default-src 'none' still lets anyone frame you unless you set it explicitly. It has to be sent as a header, since it is not supported in a <meta> tag. The CSP specification says frame-ancestors overrides X-Frame-Options when both are present and the CSP is enforced (a Report-Only frame-ancestors does not override it), so sending both is harmless and keeps very old browsers covered.
Use X-Frame-Options: DENY or SAMEORIGIN and nothing else. ALLOW-FROM is obsolete and modern browsers ignore a header that uses it. If you need to allow one specific partner site to embed you, that is a job for frame-ancestors alone. Before setting 'none', check that you do not deliberately embed your own pages, for instance in a dashboard widget.
Referrer-Policy and Permissions-Policy
Browsers already default to strict-origin-when-cross-origin when you send nothing: full URL for same-origin requests, origin only for cross-origin HTTPS requests, nothing on a downgrade. Setting it explicitly is still worth doing, because it makes the behaviour independent of the browser and stops checkers flagging the gap. If your URLs carry anything sensitive in the path or query string, consider same-origin or no-referrer, but check first that no analytics or payment return flow depends on the referrer.
Permissions-Policy switches off browser features you do not use. The syntax uses parentheses, and an empty list () disables the feature for your page and every frame inside it. Disable what you know you do not need, such as camera, microphone and geolocation. Leave anything you are unsure about alone. An embedded video or payment widget that stops working is a poor trade for a tidier header.
COOP and CORP, briefly
These two are usually optional for ordinary sites. Cross-Origin-Opener-Policy: same-origin severs the window.opener link to cross-origin popups, which breaks OAuth and payment pop-up flows that rely on it; same-origin-allow-popups is the softer option. Cross-Origin-Resource-Policy stops other sites loading your resources in no-cors contexts such as images and scripts. Treat both as a second pass, after the headers above are stable.
Remove X-Powered-By
X-Powered-By: Express and its relatives tell every visitor your framework, and sometimes its version. Removing it does not fix anything on its own, and it is not a defence in itself, but it costs one line and removes a free hint. Express: app.disable('x-powered-by'). Nginx in front of PHP: fastcgi_hide_header X-Powered-By;.
A rollout order that avoids outages
Go from least to most likely to break something, and watch for a day between steps that touch behaviour.
- Day one:
X-Content-Type-Options,Referrer-Policy, X-Frame-Options andframe-ancestors, and removal ofX-Powered-By. Check the pages you embed or are embedded by. - Day one, cautiously:
Permissions-Policywith only the features you are certain you do not use. - Week one: HSTS with a short
max-age, then raise it in stages. Audit subdomains beforeincludeSubDomains. - Weeks one to three: CSP in Report-Only mode. Fix reports, add nonces or hashes, repeat.
- After that: enforce the CSP, then consider COOP, CORP and, last of all and only if you mean it, preload.
One practical trap if you use nginx: add_header directives are inherited only if the current level defines none of its own, so adding one header inside a location block silently drops every header set at server level. Also, without always, nginx adds the header only on a fixed list of success and redirect status codes, so your 404 and 500 pages go out bare.
Copy-paste examples
These snippets add headers. If your application or CDN already sends any of them, check its current value first and keep whichever is stricter. Never lower an existing HSTS max-age or remove preload from a preloaded domain: doing so makes it eligible for removal from the list. Nginx appends rather than replaces, so behind an application that already sets the same header you get duplicates. The browser processes only the first HSTS field (RFC 6797, section 8.1), and conflicting X-Frame-Options values block all framing.
They are starting points, not finished policies. The CSP is Report-Only on purpose: run it, read the reports, adjust, and only then enforce it. If you already have a stricter enforced policy, keep it and test this one beside it. The reporting endpoint is a placeholder: replace https://example.com/csp-reports with a collector you run or subscribe to. Without report-to (or the older report-uri), a Report-Only policy only writes to each visitor's browser console. No reports reach you, and an empty inbox does not mean the policy is safe to enforce. Both directives are included because browser support differs.
nginx (nginx does not generate nonces out of the box, so script nonces normally come from your application):
# Inside your existing HTTPS server block (the one with "listen 443 ssl").
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;
# Short max-age first. Raise it in stages. No preload.
# Add includeSubDomains only after every subdomain serves HTTPS.
add_header Strict-Transport-Security "max-age=86400" always;
# Placeholder endpoint: replace with a collector you run or subscribe to.
add_header Reporting-Endpoints 'csp="https://example.com/csp-reports"' always;
# Starting point only: Report-Only, same-origin sources.
add_header Content-Security-Policy-Report-Only "default-src 'self'; report-to csp; report-uri https://example.com/csp-reports" always;
Express (a fresh nonce on every response, available to your templates as res.locals.nonce; place this after any middleware that already sets security headers and it will not overwrite them):
import crypto from 'node:crypto';
app.disable('x-powered-by');
function setIfAbsent(res, name, value) {
if (!res.hasHeader(name)) res.setHeader(name, value);
}
app.use((req, res, next) => {
const nonce = crypto.randomBytes(16).toString('base64');
res.locals.nonce = nonce;
setIfAbsent(res, 'X-Content-Type-Options', 'nosniff');
setIfAbsent(res, 'Referrer-Policy', 'strict-origin-when-cross-origin');
setIfAbsent(res, 'X-Frame-Options', 'SAMEORIGIN');
setIfAbsent(res, 'Permissions-Policy', 'camera=(), microphone=(), geolocation=()');
// Short max-age. Add includeSubDomains only after every subdomain serves HTTPS.
setIfAbsent(res, 'Strict-Transport-Security', 'max-age=86400');
// Placeholder endpoint: replace with a collector you run or subscribe to.
setIfAbsent(res, 'Reporting-Endpoints', 'csp="https://example.com/csp-reports"');
// Starting point only. Report-Only until the reports are clean.
setIfAbsent(res, 'Content-Security-Policy-Report-Only',
"default-src 'self'; script-src 'nonce-" + nonce + "'; " +
'report-to csp; report-uri https://example.com/csp-reports');
next();
});
Cloudflare Worker (sitting in front of an origin; it adds each header only if the origin has not set it, and deletes X-Powered-By):
const DEFAULTS = {
'X-Content-Type-Options': 'nosniff',
'Referrer-Policy': 'strict-origin-when-cross-origin',
'X-Frame-Options': 'SAMEORIGIN',
'Permissions-Policy': 'camera=(), microphone=(), geolocation=()',
// Short max-age. Add includeSubDomains only after every subdomain serves HTTPS.
'Strict-Transport-Security': 'max-age=86400',
// Placeholder endpoint: replace with a collector you run or subscribe to.
'Reporting-Endpoints': 'csp="https://example.com/csp-reports"',
'Content-Security-Policy-Report-Only':
"default-src 'self'; report-to csp; report-uri https://example.com/csp-reports",
};
export default {
async fetch(request) {
const upstream = await fetch(request);
// Do not re-wrap WebSocket upgrades.
if (upstream.status === 101) return upstream;
// Optional: limit this to HTML responses only.
// if (!(upstream.headers.get('content-type') || '').includes('text/html')) return upstream;
const headers = new Headers(upstream.headers);
headers.delete('X-Powered-By');
for (const [name, value] of Object.entries(DEFAULTS)) {
if (!headers.has(name)) headers.set(name, value);
}
return new Response(upstream.body, {
status: upstream.status,
statusText: upstream.statusText,
headers,
});
},
};
Expect a middling grade at this stage. Graders, including ours, ignore a Report-Only CSP and mark a short HSTS max-age as a warning. The A arrives once the CSP is enforced and max-age reaches at least six months.
Cookies are part of the same hygiene conversation; the Cookie Audit tool checks their flags in the same passive way.
What headers cannot do
Headers are configuration. They narrow what a browser will do with your pages, and a good CSP can limit the damage of an XSS bug, but none of them stops the bug existing. A header checker cannot tell you whether a user can read another user's records or whether a parameter reaches your database unescaped. That is what a penetration test is for; the difference is laid out in penetration testing versus vulnerability scanning, and the wider picture in web application security in 2026. Our Web Pentest covers the OWASP Top 10 plus configuration checks, with a reproducible proof of concept for each confirmed finding (unproven findings are labelled unconfirmed), at $399 per scan. Fix the headers first, because it is cheap. Then find out whether the application is actually exploitable.
Frequently Asked Questions
How do I get an A on a security headers check?
Send Strict-Transport-Security, X-Content-Type-Options, a framing rule (CSP frame-ancestors), Referrer-Policy, Permissions-Policy and a Content-Security-Policy without 'unsafe-inline' in script-src. Roll them out in the order given in the rollout section, and introduce the CSP in Report-Only mode first because it is the one most likely to break pages.
Is X-Frame-Options still needed if I use frame-ancestors?
It is optional. The CSP specification says frame-ancestors overrides X-Frame-Options when both are present and the CSP is enforced (a Report-Only frame-ancestors does not override it), so sending both is harmless and covers very old browsers. Use only DENY or SAMEORIGIN, because ALLOW-FROM is obsolete and ignored by modern browsers.
Should I add HSTS preload?
Only if you can serve every subdomain over HTTPS for the long term. Preload requires a max-age of at least one year, includeSubDomains and the preload directive, and hstspreload.org warns that inclusion cannot easily be undone. Run HSTS without preload first.
Why does my CSP break the site?
A CSP blocks anything your pages load or run that the policy does not allow, such as inline scripts, third-party scripts and inline event handlers. Deploy it as Content-Security-Policy-Report-Only first, read the reports, and enforce it only once the legitimate violations are fixed or allowed.
Does an A grade mean my site is secure?
No. The grade checks configuration on one response and says nothing about whether the application can be exploited. Headers reduce the impact of some bugs, but finding out whether a bug exists takes testing the application itself.