← Back to the blog

15 Oct, 2026

Security headers: HSTS, CSP, X-Frame-Options

When a scanner tells you "Missing header: HSTS" or "Content-Security-Policy missing", it is not saying you got hacked. It is saying the server does not ask the browser to turn on protections the browser already ships with. Turning them on takes minutes and closes the door to several common attacks.

The headers that matter

HeaderWhat it does
Strict-Transport-Security (HSTS)Forces the browser to always use HTTPS on your domain.
Content-Security-Policy (CSP)Sets which domains may load scripts, styles and images. It is the best defence against XSS.
X-Frame-OptionsStops another site from showing yours inside an iframe (clickjacking).
X-Content-Type-OptionsStops the browser from "guessing" a file type.
Referrer-PolicyControls how much of your URL is sent to other sites.
Permissions-PolicyTurns off APIs you do not use (camera, microphone, geolocation).

Apache or shared hosting (.htaccess)

On most hosts (Hostinger, cPanel) you can add them in the .htaccess at the root:

<IfModule mod_headers.c>
  Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
  Header always set X-Frame-Options "SAMEORIGIN"
  Header always set X-Content-Type-Options "nosniff"
  Header always set Referrer-Policy "strict-origin-when-cross-origin"
  Header always set Permissions-Policy "camera=(), microphone=(), geolocation=()"
</IfModule>

Nginx

add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;

WordPress

If you have no access to the server, you can do it from the child theme functions.php:

add_action('send_headers', function () {
    header('Strict-Transport-Security: max-age=31536000; includeSubDomains');
    header('X-Frame-Options: SAMEORIGIN');
    header('X-Content-Type-Options: nosniff');
    header('Referrer-Policy: strict-origin-when-cross-origin');
});

CSP: start in "report only" mode

Content-Security-Policy is the most powerful one and the only one that can break your site if you get it wrong (for example, by blocking Google Analytics or your chat widget). That is why it pays to start with Content-Security-Policy-Report-Only: the browser blocks nothing, it only reports in the console what it would block.

Header always set Content-Security-Policy-Report-Only "default-src 'self'; img-src 'self' data: https:; script-src 'self' https://www.googletagmanager.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com"

Open your site, watch the browser console (F12), add the legitimate domains that show up and, once there are no warnings left, switch to Content-Security-Policy.

Before enabling HSTS

  • Make sure every part of the site and its subdomains works over HTTPS. With includeSubDomains, a subdomain without a certificate stops loading.
  • Start with a short max-age (say 300) and raise it to a year once you confirm everything works.

How to check it

In the browser: F12 → Network tab → reload → click the main document → Response headers. From the terminal: curl -I https://yoursite.com.

If you want to see the state of your site without installing anything, scan your site free with CLIC404: it reviews broken links, security headers and basic SEO in a single report.

Want to know how your site is doing right now?

Scan your site for free: broken links, security headers and basic SEO in a single report.

Scan my site free