Contents 10 sections
- What are Security Headers?
- How do Security Headers work?
- Why are security headers important?
- How are the security headers to be implemented?
- Adding Security Headers via .htaccess on Apache servers
- Adding security headers on Nginx servers
- Plugins for WordPress for Security Headers
- Implementing Security Headers for the Headless CMS Strapi
- Test tools for security headers and security vulnerabilities of websites
- Are security headers useful for search engine optimization (SEO)?
Learn here what Security Headers are all about, how they work, and why they are important for your website security, and how they also help you safeguard your SEO measures.
The help article on Security Headers covers the following topics:
What are Security Headers?
Security Headers are HTTP headers used on websites and web applications to improve security and protection against various types of attacks and security vulnerabilities. They provide an important layer of security to protect users and data from threats.
If you are wondering whether you even need this, you can test your current security with an online tool. You can do this with securityheaders.com. Enter your URL there.

You will probably get a result of D or F. Most websites initially score poorly because website security is on the agenda of very few developers and agencies when creating websites or doing relaunches. You will learn below how to get the Security Headers implemented (even as a non-developer). But now you already know that there is fundamentally a need for action on your part.
How do Security Headers work?
Security Headers are part of the HTTP response that a web server sends to the browser when a request is made to a website or web application. These headers contain instructions and information that tell the browser how it should behave with regard to security and privacy. Here are some important Security Headers and how they work:
HTTP Strict Transport Security (HSTS)
HSTS forces the browser to establish and maintain the connection to the website via HTTPS in order to prevent man-in-the-middle attacks.
Many websites only have a 301 redirect from HTTP to HTTPS. Many links in the content of websites are still set up as HTTP. If someone clicks on such a link, the HTTP page is loaded first and the 301 redirect becomes active. Or if you only enter deine-domain.com in the browser to access a website, without entering the https part, which will probably be the case for most people, there is a possibility of a man-in-the-middle attack.
HSTS prevents an attacker from downgrading the HTTPS connection to an HTTP connection, which would allow the attacker to exploit insecure redirects. It thus enforces loading via a secure HTTPS connection.
X-Content-Type-Options
This header controls whether a browser tries to guess the MIME type of a resource if the specified type is not correct. It helps prevent MIME spoofing attacks because only styles and scripts with the correct MIME type are loaded. By way of background: browsers can "sniff out" whether content is text, an image (.png), a video (.mp4), or HTML, JavaScript, and other types of content that can be downloaded from a website.
Using "X-Content-Type-Options: nosniff" is an important security measure, as it helps prevent certain attack vectors such as Cross-Site Scripting (XSS). In XSS attacks ??? see also below ??? an attacker can try to insert malicious JavaScript code into a resource such as a PDF by tricking the browser into thinking it is a PDF and then getting it to execute the file as JavaScript, even if the MIME type actually indicates something else, here PDF.
This has a whole series of negative consequences for the website visitor, especially in a so-called drive-by download attack, where malware is then installed on the visitor's computer.
Using "nosniff" is particularly important in conjunction with other security measures such as Content Security Policy (CSP) to increase the security of web applications and reduce the attack surface. This header should generally be enabled in the HTTP responses for all resources (e.g. HTML, JavaScript, CSS files) on a website.
X-Frame-Options
This header prevents a web page from being displayed in an HTML frame or iframe in order to prevent clickjacking attacks. Using "X-Frame-Options" is an important security measure to prevent clickjacking attacks, in which an attacker tries to load a website in an invisible frame and exploit the user's mouse clicks. By setting the header, website operators can control the way their website is embedded in frames.
Note that "X-Frame-Options" is considered an older method of preventing clickjacking. A more modern approach is to use the "Content Security Policy" header (CSP), which can also prevent clickjacking and additionally covers other security aspects. More on this below.
X-XSS-Protection
This header enables or disables the browser's built-in XSS protection.
Note, however: MDN lists the header as deprecated and non-standard and advises against using it in new projects. Instead, a strong Content Security Policy provides protection, which is explained further below.
Referrer-Policy
The "Referrer-Policy" is an HTTP header sent by web servers to specify how a web browser should handle information in the "Referrer" field of an HTTP request. The "Referrer" is an HTTP header field that normally indicates the URL of the previous page from which the user navigated to the current page. The "Referrer-Policy" gives website operators a way to control the passing on of referrer information to other websites and to protect users' privacy. Good to know for everyone who also earns money with their content online: The Referrer-Policy has no effect on affiliate links .
Content Security Policy (CSP)
CSP headers specify from which sources resources (such as scripts, images and stylesheets) may be loaded. This helps prevent Cross-Site Scripting (XSS), code injections and similar attacks.
Cross-Site Scripting (XSS) attacks are designed to exploit a security vulnerability in your CMS or framework to upload malicious scripts to your website, which are then loaded into the browsers of your website visitors. An entry point for an XSS attack can be, for example, an email form that is not coded in such a way that only restricted input is expected. A poorly coded form can allow other inputs, which can then lead to the injection of malicious files. Incidentally, this is also one reason why we, as an agency, equip many client projects completely without a contact form, because they usually get along just fine without one.
With your CSP header, you use a kind of whitelist of domains to determine what your website may load at all and what it may not. Any attacker who downloads malicious scripts from another server outside this trusted group is blocked. In December 2016, the Content Security Policy was further developed with CSP Level 2, which added hash-source, nonce-source and five new directives. No problems are to be expected on the browser side because of this. As of September 11, 2023, CSP 2 is compatible with 95 percent of all browsers.

Creating a Content Security Policy can be strong or weak, depending on how you set it up. Of all the headers, setting it up actually took the longest for us at TutKit.com, because all scripts and resources that are downloaded from outside have to be listed in order to put them on the whitelist. You can check the correct implementation via securityheaders.com, with Mozilla Observatory and also via Google PageSpeed Insights in the Best Practices section. The advantage of the Mozilla service is that your URL is simultaneously tested by other external testing tools as well. If one of them returns a negative result, you can research a bit deeper there.
Why are security headers important?
Security headers are important because they help reduce the attack surface of websites and web applications and close known security vulnerabilities. By giving browsers instructions on how to behave with regard to security, they can help prevent various types of attacks or at least make them more difficult. This includes XSS attacks, clickjacking, MIME spoofing and other security issues.
Online shops that store, transmit or process credit card transactions must be PCI-DSS compliant. Many PCI-DSS audits also check for an activated HSTS (HTTP Strict Transport Security) and other security headers. If your website falls under PCI compliance, meaning you process credit card payments, and your payment provider expects a PCI certification from you and you have to prove it via a test/audit, the implementation of security headers will become an issue for you at the latest then.
- Security headers reduce the attack surface
- Many PCI-DSS audits check HSTS and other headers
- The user experience remains protected, also for SEO
As a third reason, your user experience is also safeguarded, which contributes positively to your SEO efforts. More on that below.
How are the security headers to be implemented?
Implementing Security Headers usually requires configuration changes at the web server or web application level.
- First, identify the Security Headers you need: Consider which Security Headers are most important for your website or web application. The selection depends on your specific requirements and threats. If you only have a one-pager without cookies and a contact form that is based purely on HTML, your risk is lower than with a shop with cookies, credit card data transfers, customer data, and a CMS.
- Configure the web server: You can add most Security Headers by adjusting the configuration of your web server. For example, Apache servers can configure the headers in the .htaccess file, while Nginx uses the configuration file nginx.conf or sites-available.
- Set the headers in the HTTP response: The headers should be set in the HTTP response of your website or web application. This can usually be achieved using server modules, scripts, or middleware.
- Test the implementation: After you have added the Security Headers, you should thoroughly test your website or web application to make sure everything works as expected. There are also online tools such as Security Headers and Mozilla Observatory that can analyze the security configuration of your website.
- Keep the headers up to date: Monitor and update the Security Headers regularly to ensure they comply with current best practices and are protected against new threats.
- Select headersdepending on your site's risk
- Configure web serverApache, Nginx or plugin
- Set headersin the HTTP response
- Testfunctions and online tools
- Keep up to datecheck regularly
The exact procedure for implementing Security Headers may vary depending on the web server technology and platform, so it is advisable to consult the documentation of your server and your web application or, if necessary, to seek professional support. Below you will find instructions on how to implement it on Apache and Nginx servers. As a non-developer, it is unfortunately not as simple on the server side as configuring it with a WordPress plugin.
Adding Security Headers via .htaccess on Apache servers
Adding Security Headers via the .htaccess file is a commonly used method to improve the security of a website on the Apache web server. The .htaccess file allows you to define server-wide settings and configurations, including the Security Headers. Here is a step-by-step guide on how to include Security Headers via the .htaccess file:
Create a backup: Back up your website and make a backup of the .htaccess file before making any changes, to make sure you don't accidentally make the website inaccessible.
Open your .htaccess file: You can usually find the .htaccess file in the root directory of your WordPress installation. You can open it with a text editor such as Notepad++, Dreamweaver, PHP Storm, or Visual Studio Code.
Add the Security Headers: To add Security Headers, you use the Header directive in your .htaccess file. Here are some examples of commonly used Security Headers and how you can add them:
Content Security Policy (CSP):
Header always set Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' data:; style-src 'self' 'unsafe-inline';"
X-Content-Type-Options:
Header always set X-Content-Type-Options "nosniff"
X-Frame-Options:
Header always set X-Frame-Options "DENY"
X-XSS-Protection:
Header always set X-XSS-Protection "1; mode=block"
HTTP Strict Transport Security (HSTS):
Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"
Referrer-Policy:
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Save the .htaccess file: After you have added the desired security headers, save the .htaccess file and upload it to your web server if necessary.
- Create a backup
- Open .htaccess
- Add headers
- Save the file
- Test the website
Check the configuration: Make sure you have not made any syntax errors in the .htaccess file by visiting the website and watching for possible error messages. You can also use online tools to check the effectiveness of your security headers.
Test your website: Check your website thoroughly to make sure that all functions work properly and that the security headers implement the desired security measures.
Please note that adding security headers via the .htaccess file only works on Apache servers. If you use a different web server such as Nginx, you must edit the corresponding configuration files for that web server in order to set the security headers. More on that below ...
Adding security headers on Nginx servers
Security headers are added in Nginx via Nginx's configuration files, usually in a file with the extension .conf. Here is a step-by-step guide to adding security headers in Nginx:
Create a backup: Before you make changes to your Nginx configuration, you should create a backup of the configuration files to ensure that you can return to a working configuration in case of problems.
Open the Nginx configuration file: The main Nginx configuration file can usually be found in a directory such as /etc/nginx/ on Linux systems. The exact file may differ from system to system, but it is usually named nginx.conf or default or sites-available for each website.
Use a text editor or a command-line editor (such as nano, vim or gedit) to open the configuration file. You need root or superuser permissions to be able to edit the file.
Add the desired security headers: You can add the desired security headers to your Nginx configuration using add_header directives. Here are examples of some commonly used security headers:
Content Security Policy (CSP):
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' data:; style-src 'self' 'unsafe-inline';";
X-Content-Type-Options:
add_header X-Content-Type-Options "nosniff";
X-Frame-Options:
add_header X-Frame-Options "DENY";
X-XSS-Protection:
add_header X-XSS-Protection "1; mode=block";
HTTP Strict Transport Security (HSTS) (Caution: Only use if your website is always accessible via HTTPS):
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
Referrer-Policy:
add_header Referrer-Policy "strict-origin-when-cross-origin";
Save and close the configuration file: After you have added the desired headers, save the configuration file and close it.
Now check the configuration: You can check the validity of the Nginx configuration with the command nginx -t. If the configuration is valid, a success message should be displayed.
Start or reload Nginx: After you have checked the configuration, start or reload the Nginx server so that the new headers are activated. You can restart the server with the command sudo service nginx restart (on Debian/Ubuntu) or sudo systemctl restart nginx (on systemd-based systems).
- Set headeradd_header directive
- Check configurationnginx -t
- Restart serversudo systemctl restart nginx
Test your website: Check your website to make sure that all functions work properly and that the Security Headers implement the desired security measures.
Note that the Nginx configuration can differ from system to system, especially if you use multiple virtual hosts (server blocks) or a more complex configuration. So make sure that you edit the correct configuration file that is responsible for your website.
Plugins for WordPress for Security Headers
There are various WordPress plugins that can help you set up Security Headers in your WordPress website. These plugins make it easier to implement security measures, even if you don't have in-depth technical knowledge.
The plugin "Headers Security Advanced & HSTS WP" is specifically designed to implement security headers and HTTP Strict Transport Security (HSTS) in WordPress websites. It offers a user-friendly way to configure these headers and security measures.
https://de.wordpress.org/plugins/headers-security-advanced-hsts-wp/

Here are some other WordPress plugins that can help you with the setup of Security Headers:
- WP Security Headers: This plugin allows you to configure various Security Headers in your WordPress website. It offers a user-friendly interface and allows you to customize headers such as Content Security Policy (CSP), X-Frame-Options, and more.
- HTTP Headers: HTTP Headers is a WordPress plugin that allows you to set various HTTP headers for more security and privacy. With it, you can configure headers such as X-Content-Type-Options, X-XSS-Protection, and Referrer-Policy.
- Security Headers: This plugin is specifically focused on setting up Content Security Policy (CSP). It offers a simple way to define and customize a CSP policy for your website.
- Easy Security Headers: This plugin offers a simple way to enable and configure important Security Headers in WordPress. It includes headers such as Content Security Policy, Strict-Transport-Security, and X-Content-Type-Options.
Before you use a plugin to set up Security Headers in WordPress, you should make sure that it is compatible with your WordPress version and your PHP version.
Implementing Security Headers for the Headless CMS Strapi
Strapi is a popular headless CMS (Content Management System) based on Node.js. Similar to WordPress, there is also the option to implement Security Headers for Strapi. In Strapi, however, the configuration of Security Headers is usually done at a deeper level, since it is a server-side application. Here are the steps to set up Security Headers in a Strapi application:
Use middleware: In Strapi, you can use middleware to set HTTP headers. You can create a custom middleware that adds the desired Security Headers to the HTTP responses. Here is an example of how you can do this:
1. Create a file, e.g. security-headers.js, in your middleware directory
module.exports = (strapi) => {
return {
initialize() {
strapi.app.use(async (ctx, next) => {2. Set the desired Security Headers
ctx.set('Content-Security-Policy', "default-src 'self'"); ctx.set('X-Content-Type-Options', 'nosniff'); ctx.set('X-Frame-Options', 'DENY'); ctx.set('X-XSS-Protection', '1; mode=block'); ctx.set('Strict-Transport-Security', 'max-age=63072000; includeSubDomains; preload'); ctx.set('Referrer-Policy', 'strict-origin-when-cross-origin');3. Call the next middleware step
await next();});},
};
};
Register middleware: After you have created the middleware, you must register it in the middleware.js file of your Strapi application to ensure that it is executed on every HTTP request.
module.exports = {
settings: {Other settings ...
},
middleware: {
Other middleware ...
securityHeaders: {enabled: true,},
},
};
Customize and test: Adjust the header values in the middleware according to your requirements. Make sure that the headers are set correctly by testing the application and using tools such as security header checkers.
Check server configuration: In addition to the middleware setting in Strapi, it is important to make sure that your web server (e.g. Nginx or Apache), if present, does not set any conflicting headers that could override those set by Strapi.
The exact implementation may vary depending on your Strapi setup and your server. An alternative implementation is also possible via config/app.js in the Strapi CMS. But the approach via middleware gives you more control and flexibility.
This is what it looks like on our agency website 4eck-media.de, which relies on the headless CMS Strapi:

Test tools for security headers and security vulnerabilities of websites
Once you have implemented the security headers, be sure to run a functional test of your website with different browsers and devices. And also use the following two test tools to check whether everything is integrated correctly:
- securityheaders.com => the tool tests specifically for security headers. See the screenshot above.
- securityscan.getastra.com => the tool tests for over 140 security vulnerabilities, and security headers are included as well.
In the health check via https://securityscan.getastra.com/, we now have a score of 90/100 for tutkit.com:

As you can see, there is still a bit of room for improvement, even though everything is okay. In our case, it is related to certain modules that output JavaScript differently than recommended by security requirements for best practice. With the next major update of our JavaScript framework vue.js and the Laraberg modules of TutKit.com, we will take care of this as well.
Are security headers useful for search engine optimization (SEO)?
There is a connection between security headers and SEO (search engine optimization), although this connection is rather indirect in nature.
In May 2020, Google stated that in 2021 the Page Experience would bundle seven different factors and become a holistic picture of the quality of the experience of a website.

HTTPS and Safe Browsing are among the primary factors that contribute to the positive signals for the Page Experience. The use of HTTPS was also described by Google as a ranking factor. The same initially applied to Safe Browsing. In August 2021, Google then backpedaled and stated that Safe Browsing would no longer be considered as a ranking factor after all, since many website owners cannot be blamed for hacking.
In PageSpeed Insights as well as in Lighthouse tests via the Dev Tools in the Chrome browser, you will see a recommendation on Safe Browsing in the results. It is therefore reasonable to assume that the topic of Safe Browsing is not entirely off the table for SEO:

In addition, Google weights websites higher that meet the EEAT principle, i.e. whose content is validated according to Expertise, Experience, Authority and Trustworthiness. Trustworthiness refers to the reliability and credibility of a website or web content. Google assesses trustworthiness based on factors such as data protection, security and transparency.
Exactly how security headers are related to SEO can be illustrated by five benefits of HTTP headers for your website and your website visitors:
- Trust and security: A website that uses security headers signals to visitors and search engines that it cares about the security of its users and data. This can strengthen users' trust in the website and reduce the risk of security issues such as data leaks and malware attacks.
- Avoiding security problems: Security headers, such as Content Security Policy (CSP) and X-XSS-Protection, help prevent known vulnerabilities such as cross-site scripting (XSS). Websites that are vulnerable to security problems could be penalized by search engines or appear in warning messages for users, which can have a negative impact on SEO.
- Improved loading times: Some security headers, such as HTTP Strict Transport Security (HSTS), can help improve the website's loading times, as they force the browser to establish the connection via HTTPS. Faster loading times are an important factor for SEO, as search engines like Google take loading time into account as a ranking criterion.
- Preventing clickjacking & phishing: Security headers such as X-Frame-Options can help prevent clickjacking attacks, in which a website's content is displayed in an invisible frame. This can increase users' trust in the website and reduce the likelihood of phishing attacks.
- HTTPS and Ranking: Although not directly related to security headers, the use of HTTPS (promoted by security headers such as HSTS) is an important SEO factor. Google announced back in 2010 that HTTPS would be considered as a ranking signal, and websites with HTTPS can have an SEO advantage.
In my opinion, the use of security headers can have a positive effect on a website's SEO ranking, but they are not the sole criterion, just a very small part of the overall security and SEO equation. A website that offers irrelevant content or an inadequate user experience will not perform better in search results simply by adding security headers. SEO is a complex process that takes many factors into account, including high-quality content, good user experience, mobile optimization, and much more. However, security headers are an important component for gaining users' trust and making the website more secure overall, which can ultimately have a positive effect on the SEO ranking.
Or conversely: If your website is infected with malware and Google displays a warning to website visitors, it has a directly negative effect on your reputation. Your ranking will fall, and with it all of your previous SEO successes. As a website operator, you will also receive a notice from Google in this case via the Search Console. Alternatively, you can also have your website tested for malware infection here.
In any case, we are proud that we brought our security headers up to the most modern standard in a security sprint. And with that, we also made it into the Hall of Fame:

Conclusion: Implementing security headers is not rocket science and should be considered with every website launch. Unfortunately, very few website operators, agencies, and SEO experts have it on their radar, which is why it would be good if SEO tools also included the check for HTTP headers in their audits. We will see … in any case, I have already brought this wish to the attention of the management of SEOBILITY :-)
Comments
Register and comment.
Continue reading
