Skip to main content

Security headers: the full set and how to check them

Security · · 4 min read

What to check right now

Headers are the cheapest protection there is: they need no code changes and are switched on in the web server configuration. Start with what your site serves today:

curl -sI https://example.com/ | grep -iE \
  'content-security-policy|strict-transport|x-content-type|x-frame|referrer|permissions|cross-origin'

Empty output means nothing is configured. From there, one header at a time, from the most useful to the optional.

The two big ones have their own articles

Content-Security-Policy and HSTS do more than all the rest together, and they are harder to configure. They are covered separately: Content Security Policy and HSTS. One thing matters here: a CSP policy also carries the ban on framing your site, and the HSTS value is counted in seconds, where a year is 31536000.

X-Content-Type-Options

One header with one value, and every site should send it:

add_header X-Content-Type-Options "nosniff" always;

It forbids the browser from guessing a file's type from its contents instead of what the server declared. Without it, an image uploaded by a visitor with markup inside can be interpreted as a document and executed. The header has no side effects under one condition: the file types on the server are declared correctly.

X-Frame-Options and frames

Banning your page from being framed closes the trick where a transparent foreign layer is drawn over your button. Today this is set by the frame-ancestors directive in a CSP policy, and the old header is kept for browsers that do not understand it:

add_header X-Frame-Options "SAMEORIGIN" always;

When the values disagree, CSP wins in browsers that support it. So keep them consistent, or the behaviour will differ between browsers.

Referrer-Policy

By default the browser tells a foreign site which page the visitor came from. For internal addresses carrying parameters that is a leak: the full address of your password reset page lands in someone else's server log.

add_header Referrer-Policy "strict-origin-when-cross-origin" always;

This value sends only the domain name when leaving for another site, and the full address within your own. The no-referrer variant is stricter but breaks some analytics and affiliate flows — choose deliberately.

Permissions-Policy

The header switches off browser capabilities the site does not need: camera, microphone, location, sensors. The point is not protection from yourself but limiting embedded third-party frames — ads and widgets inherit the page's rights.

add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;

Empty parentheses mean "denied to everyone, the page itself included". If your site does use the camera, write camera=(self), or your own feature will stop working.

The header it is time to remove

X-XSS-Protection is a legacy of old browsers. MDN marks it deprecated and states plainly that it is non-standard: this feature is not standardized. Modern browsers do not use it, and in the past the built-in filter was itself a source of problems. Remove the line from your configuration if it is there: its presence creates the false impression that cross-site scripting protection is configured, when CSP is what actually provides it.

Isolation headers: not for everyone

The Cross-Origin-* group governs how far the page is isolated from other tabs and foreign resources. You need them if you work with shared memory or precise timers, and they break embedding of third-party widgets if switched on without understanding.

HeaderWhat it doesWhen to set it
Cross-Origin-Opener-PolicyCuts the link to the window that opened youLogin and payment pages
Cross-Origin-Embedder-PolicyRequires permission from third-party resourcesOnly together with the previous one
Cross-Origin-Resource-PolicyStops other sites embedding your filesImages and fonts that should not be someone else's

How to check, and where the result misleads

Check not the home page but the addresses where the response is built differently: an error page, a static file, an application interface response. A common mistake is a header set in one location and missing from the others.

for u in / /404-test /css/main.css /api/health; do
  printf '%-16s %s\n' "$u" "$(curl -sI https://example.com$u | grep -ic x-content-type-options)"
done

One more Nginx subtlety: an add_header directive from an outer block is not inherited if the inner block has an add_header of its own — there the headers must be listed again. So trust the curl output for each address rather than the presence of a line in the configuration.

What sits next to this

Headers protect the visitor in the browser but do not close the server. Neighbouring measures: hardening Nginx, SRI for third-party scripts and scanning the site.

Was this article helpful?
Back to Knowledge Base Ask Support