Security headers are instructions your server sends with every page, telling the visitor's browser how to behave safely. They are free, powerful, and most sites do not set them. Here are the ones worth adding, what each one stops, and how to roll them out without breaking your site.

How security headers work

Every response from your server starts with headers: name-and-value lines the visitor never sees. Some describe the content, such as its type and caching rules. Security headers tell the browser to turn on protections it already has, such as refusing to load your site in a frame or refusing to guess a file's type. They don't change your pages; they change how the browser treats them.

The headers worth adding

Content-Security-Policy (CSP). The most powerful and the most complex. It tells the browser which sources of scripts, styles, and images to trust, and blocks everything else. A good CSP stops most cross-site scripting attacks dead, because injected scripts come from an untrusted source. Start in report-only mode to avoid breaking your site.

Strict-Transport-Security (HSTS). Forces browsers to use HTTPS for your site, always. Once a browser sees this header, it refuses to connect over insecure HTTP, which blocks a class of interception attacks.

X-Frame-Options. Stops other sites from loading yours inside a frame. This prevents "clickjacking," where an attacker overlays your site invisibly to trick users into clicking things.

X-Content-Type-Options: nosniff. Stops the browser from guessing a file's type, which can be abused to run a file as a script.

Referrer-Policy. Controls how much of your URL is shared when users click away, protecting information that might be in your URLs.

Permissions-Policy. Controls which browser features (camera, microphone, location) your site and its embedded content can use.

Header A safe starting value
Strict-Transport-Security max-age=31536000
X-Frame-Options SAMEORIGIN
X-Content-Type-Options nosniff
Referrer-Policy strict-origin-when-cross-origin
Permissions-Policy camera=(), microphone=(), geolocation=()
Content-Security-Policy built for your own site, in report-only mode first

What each header changes in practice

  • With HSTS, after a browser's first secure visit, typing your address or following an old http:// link goes straight to HTTPS, so there is no insecure first request to intercept.
  • With X-Frame-Options: SAMEORIGIN, a page on another domain that tries to load your login or checkout page in an invisible frame gets an empty frame.
  • With nosniff, a file uploaded as an image but containing script is never run as a script.
  • With strict-origin-when-cross-origin, other sites see only your domain when a visitor follows a link away, not the full address with its path and query string.
  • With a CSP that lists only your own domain and the services you use, a script injected from an attacker's server is refused by the browser.

How to add them

You can set headers in your server config (.htaccess for Apache, the server block for Nginx), or a security plugin can manage them for you. Test with a tool like securityheaders.com after you add them.

  1. Find out what you already send. Your host or CDN may set some headers already. Check the response headers in your browser's developer tools (Network tab) before you add anything, so you don't send a header twice with different values.
  2. On Apache, add lines like Header always set X-Content-Type-Options "nosniff" to .htaccess. This needs the mod_headers module, which most hosts enable.
  3. On Nginx, add lines like add_header X-Content-Type-Options "nosniff" always; to the server block. Nginx drops these headers in any location block that has its own add_header, so repeat them there.
  4. Add HSTS only when HTTPS works everywhere on the domain. Start with a short max-age, such as one day, then raise it. Add includeSubDomains only when every subdomain has HTTPS.
  5. Roll out CSP in report-only mode. Send Content-Security-Policy-Report-Only first, watch the browser console (or a reporting endpoint) for what it would block, adjust, then switch to the enforcing header.
  6. Test again after every change, on your public pages and in the dashboard.

A word of caution

CSP especially can break things if set too strictly: a legitimate script from a service you use might get blocked. Roll it out carefully and in report-only mode first.

Common mistakes

  • Copying someone else's CSP. A policy only works if it lists the sources your own site uses: analytics, payment forms, embedded video, fonts.
  • Using X-Frame-Options: ALLOW-FROM. Browsers no longer support it. Use the CSP frame-ancestors directive if you need to allow specific sites to frame yours.
  • Setting a long HSTS max-age too early. Browsers remember it, so a later problem with your certificate locks visitors out until it expires.
  • Thinking headers fix vulnerabilities. They limit what an attack can do in the browser. They don't patch a vulnerable plugin, and a CSP that allows inline scripts stops very little.

What a header check can and can't tell you

A security scanner can tell you which headers you are missing and whether sensitive information is exposed. It reads what your server sends; it can't tell whether your CSP matches everything your site legitimately loads. Only testing your real pages does that.

How Silent Threads helps

Silent Threads can send X-Frame-Options, X-Content-Type-Options, Referrer-Policy and Permissions-Policy, plus HSTS on HTTPS sites. It doesn't set a Content-Security-Policy, because a useful one depends on what your site loads. The free security checker reads your headers from outside and warns when a CSP allows inline scripts, eval() or any host.