Increasing security with HTTP Security Headers

Why are HTTP Security Headers important, and what are they? We might think of HTTP Security Headers as something extremely technical. In reality, this part of how a blog or website is built deserves a closer look and the best possible handling if you want to work towards SEO optimisation and keep your site running…

Author

Franco Farnedi

Published

22 November 2023

Reading time

5 minutes

Category

Cyber Security

Why are HTTP Security Headers important, and what are they?

We might think of HTTP Security Headers as something extremely technical. In reality, this part of how a blog or website is built deserves a closer look and the best possible handling if you want to work towards SEO optimisation and keep your site running at a high standard. Put another way, you cannot be online and ignore this subject: it is a website security parameter, and security today is part of what Google calls Page Experience, a general assessment of the various elements that make up the user experience. It also includes Core Web Vitals, mobile optimisation, the presence of HTTPS and, precisely, the security of web pages.

HTTP Security Headers are website security directives that are transmitted through the HTTP response header, that is, the response the web server gives to the browser software trying to access the website. The client, the program you use to browse, connects to your web space through a domain and receives various pieces of information, such as the status code (200 if all is well, 404 if not). The security headers in HTTP Security Headers define limits and instructions that prevent unwanted actions that are dangerous for the work you have published on the internet.

These elements are there to set an advanced level of security, by limiting the behaviour that the browser and the server (that is, the request and response of data) are allowed once an action is carried out by a user or a bot. Automated software is always searching for websites in order to find security weaknesses. Of course, you can work on other fronts too, for example by using plugins to increase security, setting up a good firewall or using quality hosting. But that is not always enough, which is why HTTP Security Headers come into play.

Let’s look together at the main directives you can use:

Strict Transport Security (HSTS) – Strict security on HTTP transport

The Strict-Transport-Security header (often abbreviated to HSTS) tells browsers that the site must only be accessed over the HTTPS protocol and that any future attempt to access it over HTTP must be automatically converted to HTTPS.

This is safer than an ordinary 301 redirect, which would allow “man in the middle” attacks.

Through parameters you can set the maximum time browsers remember the setting, as well as whether it applies to subdomains. Example:

Strict-Transport-Security: max-age=31536000 ; includeSubDomains

Content Security Policy (CSP) – Content security policy

This solution is designed to anticipate and defuse a wide range of attacks, including Cross Site scripting, which exploits a vulnerability in website security. Thanks to such oversights, like using insecure plugins or not updating WordPress themes, malicious actors can run harmful scripts on a website that are then downloaded into the user’s browser (in which case the site could be banned by Google, with irreparable damage).

Content Security Policy forces the browser to download resources only from a given group of domains. As a result, if the content security policy you apply is very restrictive, you need to bear in mind that it can have negative effects on the logic of your website, because many resources get blocked! This security header is recommended for websites that handle sensitive user data; if you have a simple blog or informational site, its usefulness is much reduced.

You also need to consider that it is not that simple to enable all the CSP security features, as numerous customisations to the WordPress or website code may be needed. For example, to enable nonce-based strict CSP you will have to edit the calls to all the dependencies the website uses, which is not always trivial. If you choose instead to enable hash-based strict CSP, you will have to put all the inline scripts in your HTML template, because browsers are not allowed to use hashes on external dependencies. Two opposing methods that both require significant work on the HTML templates and on how dependencies are included. An example of a directive:

Content-Security-Policy: font-src font.example.com;

X-Content-Type-Options

This header is used by the server to signal that the MIME types indicated for the various pieces of content published on the page (images, files, JavaScript, etc.) must be respected and not altered.

This prevents files from being misinterpreted, which becomes crucial if a malicious file is disguised as a different file type using the MIME type sniffing technique: this vulnerability arises when a site allows data to be uploaded to the server and a user disguises an HTML file as a different file type, opening a breach in security. It is enabled with the directive:

X-Content-Type-Options: nosniff

Referrer Policy

This directive determines what information is passed to the landing site of a link on your website whenever someone leaves a page. Various options are available depending on the protocol (HTTP or HTTPS) and the site (the same one or another). The purpose of a Referrer-Policy header is to control what information is sent when a visitor leaves your pages to visit another site.

The default is to send the domain, path and query string when staying on the same site. For requests to external sites, the domain is sent if the connection stays on HTTPS. No data is sent when moving to HTTP. With the no-referrer value the header is omitted entirely, for example:

Referrer-Policy: no-referrer

Clear Site Data (CSD)

The Clear-Site-Data parameter deletes browsing data (such as cookies and cache) relating to the website. It gives webmasters greater control over the information stored by a web browser. This header is useful during a logout process, for example, as it ensures that all content stored in the browser is removed. In the header syntax you can list the individual items to clear or use the asterisk to include them all, even future ones that will be added. Example:

Clear-Site-Data: “cache”,”cookies”,”storage”

Permissions Policy

Permissions Policy provides mechanisms that allow developers to explicitly declare which features can and cannot be used on a site. It defines a set of “policies” that restrict the APIs the site’s code can access or change the browser’s default behaviour for certain features: this lets you apply best practice and embed third-party content more safely.

Permissions Policy is similar to CSP but controls features rather than security behaviour.

Examples of what you can do with Permissions Policy:

  • change the default autoplay behaviour on mobile and third-party videos;
  • limit a site’s use of sensitive devices such as the camera, microphone or speakers;
  • allow iframes to use the Fullscreen API;
  • stop scripts running on elements when they are not visible in the viewport, to improve performance.

X-Frame-Options

The X-Frame-Options header is a security measure that prevents the browser from loading web pages in a <frame>, <iframe>, <embed> or <object>. Enabling the X-Frame-Options HTTP response headers protects against Cross-Frame Scripting (XFS) attacks, clickjacking and other forms of cyber attack: once it is active, your content will not be embedded elsewhere.

This header is no longer in use and it is preferable to use the CSP tools instead.

Conclusions

From our experience, we have found that enabling very strict headers means, on the one hand, meeting the highest security standards, often required by companies under review by external consultants, and on the other a considerable investment of resources and the technical skills of an operator who can liaise with the hosting support team and any developers working on the project in order to carefully choose the permitted resources.

Going back to projects with a very strict CSP, perhaps to add a new plugin or a feature with active third parties, often means further work on the headers that are enabled.

We therefore recommend a smart, flexible solution that is not too restrictive and goes hand in hand with constant monitoring systems such as WP Remote, the BlogVault platform we use to monitor the security and performance of the websites covered by WP-HELP contracts.

Share the article

Available for work

Stay in touch

Have a new project to start, or just want to know more about what we do? Our team helps you find the solution that best fits your needs.

Contact us
This site is registered on wpml.org as a development site. Switch to a production site key to remove this banner.