Security headers every small business website should send
Every time a browser loads a page from your website, your server sends a few lines of instructions before the page itself. These are the HTTP response headers. Most of them are routine, but a handful tell the browser how to protect your visitors: always use an encrypted connection, refuse to run scripts from places you did not approve, refuse to show your page inside someone else's frame. They cost nothing, they work in every modern browser, and many small business sites still send none of them.
This guide covers the headers we set on every site we build or repair, in the order we add them, how to check them, and the mistakes that break a site when they are added carelessly.
Why headers matter on a small site
Attackers rarely pick a small business site by hand. Automated tools scan the web for weak sites and use them to steal form data, inject spam links, or redirect visitors to scams. A contact form, a login page or a checkout makes your site worth attacking even if your business is small. Security headers do not fix a bug in your code, but they limit what an attacker can do with one: a script injected into your page cannot load, a fake copy of your login page cannot frame the real one, and a visitor's browser will not quietly fall back to an unencrypted connection.
1. Always encrypted: Strict-Transport-Security
Once your whole site works over HTTPS, tell browsers to never use plain HTTP for it again:
Strict-Transport-Security: max-age=31536000; includeSubDomains
The browser remembers this for the number of seconds given (here, one year). Start with a short value, such as one day, and raise it once you are sure every page and every subdomain works over HTTPS. The includeSubDomains part covers every subdomain too, so leave it out until they all have certificates. A long setting is hard to undo: browsers that saw it will refuse plain HTTP until it expires.
2. Only the scripts you chose: Content-Security-Policy
The Content Security Policy (CSP) is the most powerful header and the one most likely to break something. It lists where the page may load scripts, styles, images, fonts and frames from, and where it may send data. Anything not on the list is blocked. A simple starting point for a site that loads everything from itself:
Content-Security-Policy: default-src 'self'; img-src 'self' data:; frame-ancestors 'none'; base-uri 'self'; form-action 'self'
Then add each outside service the site really uses, and only for the type of content it needs: your analytics provider for scripts and connections, your payment provider for scripts and frames, your font service for styles and fonts. Three rules keep a policy useful:
- Avoid
'unsafe-inline'for scripts. It allows any script written into the page, which is exactly what an injected script is. Move inline scripts into files on your own site, or allow each one by its hash. - Name hosts, not whole categories.
https:on its own allows every encrypted site on the internet. - Try it first in report-only mode. Sending the policy as
Content-Security-Policy-Report-Onlymakes the browser report what it would block without blocking anything. Fix what it reports, then switch to the enforcing header.
3. No framing: frame-ancestors and X-Frame-Options
A page shown invisibly inside another site's frame can trick a visitor into clicking your buttons (this is called clickjacking). The frame-ancestors 'none' part of the policy above stops it. Older browsers use a separate header for the same job, so send both:
X-Frame-Options: DENY
If your own site needs to frame its own pages, use frame-ancestors 'self' and SAMEORIGIN instead.
4. The small ones that still count
X-Content-Type-Options: nosniffstops the browser from guessing a file's type, so an uploaded text file cannot be run as a script.Referrer-Policy: strict-origin-when-cross-originsends only your domain, not the full address, when a visitor follows a link to another site. Addresses can contain order numbers, search terms or reset tokens.Permissions-Policy: camera=(), microphone=(), geolocation=()switches off powerful browser features your site does not use, so an injected script cannot ask for them either.
5. Check files you load from other sites
If a page loads a script from a public library server, add a Subresource Integrity hash to the tag: integrity="sha384-..." plus crossorigin="anonymous". The browser then refuses the file if a single byte of it changed. Most library servers show the hash next to each version. Pin the exact version you tested, because a hash only matches one version.
Where to set them
Headers are set by whatever serves your site, not inside your page design. On static hosts such as Cloudflare Pages or Netlify, a small text file named _headers in the published folder lists the headers for each path. On your own server they go in the web server's configuration (Apache or nginx). Many site builders and hosted stores let you set only some of them; check what your platform allows before you promise a client a full set.
A Content Security Policy can also be written into the page with a <meta> tag. Be careful mixing the two: when a page has a policy in the header AND one in a meta tag, the browser enforces both, and a file must pass both to load. We have seen sites where an embedded music player or a payment form worked in testing and showed a blank box in production because only one of the two policies had been updated. Note also that frame-ancestors has no effect in a meta tag; it must be sent as a header.
How to check your headers
- Look at what the server really sends. In your browser, open the developer tools, choose the Network tab, reload the page and click the first request: the response headers are listed there. From a terminal,
curl -I https://your-site.exampleprints them. - Check every kind of page, not only the home page. A rule written for one path can miss the checkout, the blog or error pages.
- Read the browser console on each page. A blocked script or frame shows a message naming the policy that blocked it.
- Walk the paths that make money. Submit the contact form, log in, and run a checkout to the payment page. A policy that blocks your payment provider costs more than the attack it prevents.
Mistakes we see most
- Turning on a long HSTS setting before every subdomain has HTTPS, which locks visitors out of the subdomain that does not.
- Adding
'unsafe-inline'to make an error go away, which removes most of what the policy protects. - Updating one policy and forgetting the other when a site has both a header and a meta tag.
- Never re-checking after adding a new service. A new chat widget, analytics tool or embed needs its host added, or it silently stops working.
- Treating a good score as the finish line. Online header graders are a useful first look, but a perfect grade with a broken checkout is a failure.
The short version
Serve everything over HTTPS and tell browsers to stick to it. Send a Content Security Policy that names only the services you really use, without 'unsafe-inline' for scripts, and test it in report-only mode first. Block framing, stop type guessing, trim the referrer, switch off browser features you do not use, and pin outside scripts with an integrity hash. Then check the headers the server really sends, on every kind of page, and walk your forms and checkout before you call it done.