A missing security header is fixed by sending one more line in your server's HTTP response. Each header tells the browser to switch on a protection it already has, so the fix lives in your server or hosting config. Start with safe default values, check that nothing breaks, then tighten them.
This guide covers the six headers a scan usually flags, the value to start with for each, where to add them on common setups, and how to confirm the fix worked.
What security headers do
When a browser loads your page, the server sends HTTP headers before the content. Some of them change how the browser treats your site: force HTTPS, block scripts you never approved, stop other sites from framing your pages. Browsers keep these protections off unless you ask for them, because turning them on blindly could break older sites.
A missing header means one layer of defense is off. If an attacker finds a cross-site scripting bug or tricks someone onto plain HTTP, those layers decide how much damage they can do.
How to add each missing header
Most sites can add four of the six headers in a few minutes with no side effects. Content-Security-Policy and Strict-Transport-Security need a short test period first, because a wrong value can block your own scripts or lock subdomains out.
| Header | Safe starting value | Can it break the site? |
|---|---|---|
| Strict-Transport-Security | max-age=300 then raise |
Yes, if any subdomain lacks HTTPS |
| Content-Security-Policy | Report-only first | Yes, it can block scripts |
| X-Content-Type-Options | nosniff |
Rarely |
| X-Frame-Options | SAMEORIGIN |
Only if you embed your own pages elsewhere |
| Referrer-Policy | strict-origin-when-cross-origin |
No |
| Permissions-Policy | camera=(), microphone=(), geolocation=() |
Only for features you use |
1. Strict-Transport-Security
HSTS tells the browser to use HTTPS for your domain for a set time, even if someone types http:// or clicks an old link. Browsers ignore it when it arrives over plain HTTP, so your site needs working HTTPS first.
Raise the time in steps so a mistake expires quickly:
Strict-Transport-Security: max-age=300
Strict-Transport-Security: max-age=31536000; includeSubDomains
Add includeSubDomains only after you confirm every subdomain, including old ones like mail. or shop., works over HTTPS. A year (31536000 seconds) is the usual long-term value.
2. Content-Security-Policy
CSP lists where scripts, styles, images and frames may load from. If an attacker injects a script tag, the browser refuses to run it because its source is not on the list. It is the main defense against cross-site scripting, and the one most likely to break things.
Roll it out in report-only mode first. The browser logs what it would block, without blocking it:
Content-Security-Policy-Report-Only: default-src 'self'; img-src 'self' data:; frame-ancestors 'none'; object-src 'none'; base-uri 'self'
Open your site with the browser's developer console visible and click through the main pages. Each violation names the blocked source. Add the ones you trust, such as your analytics or font host, then rename the header to Content-Security-Policy to enforce it.
3. X-Content-Type-Options
This stops the browser from guessing a file's type. Without it, a file uploaded as an image could be run as a script if its contents look like one. It has one valid value:
X-Content-Type-Options: nosniff
4. X-Frame-Options
This stops other sites from loading your pages inside a hidden frame and tricking visitors into clicking buttons there, an attack called clickjacking.
X-Frame-Options: SAMEORIGIN
Use DENY if you never frame your own pages. If you already send a CSP, its frame-ancestors directive does the same job in modern browsers; sending both is fine.
5. Referrer-Policy
When someone follows a link from your site, the browser tells the next site which page they came from. Full URLs can leak search terms, reset tokens or private paths. This value sends only your domain to other sites and the full path within your own:
Referrer-Policy: strict-origin-when-cross-origin
6. Permissions-Policy
This switches off browser features your site never uses, so an injected script or an embedded third party can't ask for them either. List the features with empty parentheses:
Permissions-Policy: camera=(), microphone=(), geolocation=(), payment=()
Leave out any feature your site really needs, such as geolocation on a store finder.
Where to set headers on your server
Set headers in one place, as close to the edge as possible, so every page and file gets them. Use the setup you already run:
- Nginx: inside the
serverblock, one line per header:add_header X-Content-Type-Options "nosniff" always;. Thealwaysflag keeps the header on error pages too. - Apache: in the virtual host or
.htaccess, withmod_headersenabled:Header always set X-Frame-Options "SAMEORIGIN". - IIS: under
customHeadersinweb.config, or HTTP Response Headers in IIS Manager. - Next.js: return them from the
headers()function innext.config. - Static hosting: most static hosts read a headers file or a headers section in the project's config file. Check your host's documentation for the exact file name.
- WordPress: add them at the web server level as above, or through a security plugin you already use.
If a CDN sits in front of your site, set the headers either at the CDN or at the origin, not both with different values.
Hide the server version
Scanners also flag headers like Server: Apache/2.4.41 or X-Powered-By: PHP/8.1. They don't weaken anything directly, but they tell an attacker exactly which known bugs to try.
- Nginx:
server_tokens off; - Apache:
ServerTokens ProdandServerSignature Off - PHP:
expose_php = Offinphp.ini - Express:
app.disable("x-powered-by")
Cookies without Secure, HttpOnly or SameSite
Cookies are set with the Set-Cookie header, and three flags decide how well they're protected. A scan lists each cookie that lacks one:
Securesends the cookie over HTTPS only, so it can't be read on an open network.HttpOnlyhides the cookie from page scripts, so an injected script can't steal a login session.SameSite=Laxstops the browser from sending the cookie with most requests started by other sites, which blocks many cross-site request forgery attacks. UseStrictfor cookies that never need to travel with a link from elsewhere.
A session cookie should have all three:
Set-Cookie: session=…; Path=/; Secure; HttpOnly; SameSite=Lax
Leave out HttpOnly only for cookies your own front-end code has to read, such as a theme preference. A cookie with SameSite=None must also carry Secure, or browsers reject it. Where the cookie comes from your framework or CMS, set the flags in its session or cookie settings rather than editing headers by hand.
Make an existing CSP or HSTS stronger
A header can be present and still weak. These are the most common findings:
- CSP allows
'unsafe-inline'scripts. That lets injected inline scripts run, which is exactly what CSP is meant to stop. Move inline scripts into files, or use nonces or hashes for the few you must keep. - CSP has no
object-srcorbase-uri. Addobject-src 'none'andbase-uri 'self'; few sites need anything else. - CSP allows a whole domain with a wildcard like
https://*.example-cdn.com. Narrow it to the exact host you load from. - HSTS lacks
includeSubDomains. Subdomains can still be reached over HTTP. Add it once every subdomain has HTTPS. - HSTS lacks
preload. Without it, a person's first visit isn't protected. Preloading means asking browsers to hard-code your domain as HTTPS-only through hstspreload.org, which requires amax-ageof at least one year plusincludeSubDomainsandpreload. Removal from the list is slow, so only preload a domain you'll keep on HTTPS for good.
Frequently asked questions
Do security headers improve my search ranking?
No search engine lists security headers as a ranking signal. HTTPS itself is a confirmed signal, and HSTS keeps visitors on it. Add them to protect your visitors and your login forms.
Is X-XSS-Protection still needed?
No. Modern browsers removed the filter that header controlled, and it could even introduce bugs in older ones. A Content-Security-Policy replaces it. If a scan still asks for it, sending X-XSS-Protection: 0 is the safe value, but you can also leave it out entirely.
Why did my site break after adding a CSP?
The policy blocked a script, style or font your page needs. Open the browser console: each blocked load shows the source it came from. Add the sources you trust to the matching directive, or go back to report-only mode until the console stays clean while you click through the site.
How do I check that the headers are live?
Run the scan again after deploying. You can also open your browser's developer tools, reload the page and look at the response headers of the first document request. If a header is missing on some pages only, it is usually set in an app route instead of the server or CDN.
Check your site again
Run your domain through the security headers scanner after each change. It grades the six headers, shows the raw response, and links each failed check back to its fix here. If HTTPS itself is the problem, the SSL certificate checker tells you why.