Hardening Your HTTP Security Headers

By Brian Jackson
Updated on September 8, 2022
Hardening Your HTTP Security Headers

There are a lot of things to consider to when securing your website or web application, but a good place to start is to explore your HTTP security headers and ensure you are keeping up with best practices. In many cases they are very easy to implement and only require a slight web server configuration change. HTTP security headers provide yet another layer of security by helping to mitigate attacks and security vulnerabilities. In this post we will explore some of them to help you better understand their purpose and how to implement them.

What are HTTP security headers?

Whenever a browser requests a page from a web server, the server responds with the content along with HTTP response headers. Some of these headers contain content meta data such as the Content-Encoding, Cache-Control, status codes, etc.

Along with these are also HTTP security headers that tell your browser how to behave when handling your website's content. For example, by using the Strict-Transport-Security you can force the browser to communicate solely over HTTPS. There are six different HTTP security headers that we will explore below (in no particular order) that you should be aware of and we recommend implementing if possible.

1. Content Security Policy

The Content-Security-Policy header provides an additional layer of security. This policy helps prevent attacks such as Cross Site Scripting (XSS) and other code injection attacks by defining content sources which are approved and thus allowing the browser to load them.

All major browsers currently offer full or partial support for content security policy. And it won't break delivery of the content if it does happen to be delivered to an older browser, it will simply not be executed.

There are many directives that you can use with Content-Security-Policy. This example below allows scripts from both the current domain (defined by 'self') as well as google-analytics.com.

Content-Security-Policy: script-src 'self' https://www.google-analytics.com

To explore all of the directives, and to see implementation on Nginx and Apache, make sure to check out our in-depth post on Content Security Policy.

2. X-XSS-Protection

The X-XSS-Protection header is designed to enable the cross-site scripting (XSS) filter built into modern web browsers. This is usually enabled by default, but using it will enforce it. It is supported by Internet Explorer 8+, Chrome, and Safari. Here is an example of what the header looks like:

X-XSS-Protection: 1; mode=block

Enable in Nginx

add_header X-XSS-Protection "1; mode=block" always;

Enable in Apache

header always set X-XSS-Protection "1; mode=block"

3. HTTP Strict Transport Security (HSTS)

The Strict-Transport-Security header is a security enhancement that restricts web browsers to access web servers solely over HTTPS. This ensures the connection cannot be establish through an insecure HTTP connection which could be susceptible to attacks.

All major modern browsers currently support HTTP strict transport security except for Opera Mini and versions previous of Internet Explorer.

Here is an example of what the header looks like: You can include the max age, subdomains, and preload.

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

To read more about this header and see implementation on Nginx and Apache, make sure to check out our in-depth post on HTTP Strict Transport Security.

4. X-Frame-Options

The X-Frame-Options header provides clickjacking protection by not allowing iframes to load on your website. It is supported by IE 8+, Chrome 4.1+, Firefox 3.6.9+, Opera 10.5+, Safari 4+. Here is an example of what the header looks like:

X-Frame-Options: SAMEORIGIN

Enable in Nginx

add_header X-Frame-Options "SAMEORIGIN" always;

Enable in Apache

header always set X-Frame-Options "SAMEORIGIN"

5. Expect-CT

The Expect-CT header prevents misissued certificates from being used by allowing websites to report and optionally enforce Certificate Transparency requirements. When this header is enabled the website is requesting the browser to verify whether or not the certificate appears in the public CT logs. Here is an example of what the header looks like:

Expect-CT: max-age=604800, enforce, report-uri="https://www.example.com/report"

Enable in Nginx

add_header Expect-CT "max-age=604800, enforce, report-uri='https://www.example.com/report' always;

Enable in Apache

header always set Expect-CT "max-age=604800, enforce, report-uri="https://www.example.com/report"

6. X-Content-Type-Options

The X-Content-Type-Options header prevents Internet Explorer and Google Chrome from sniffing a response away from the declared Content-Type. This helps reduce the danger of drive-by downloads and helps treat the content the right way. Here is an example of what the header looks like:

X-Content-Type-Options: nosniff

Enable in Nginx

add_header X-Content-Type-Options "nosniff" always;

Enable in Apache

header always set X-Content-Type-Options "nosniff"

7. Feature-Policy

The Feature-Policy header grants the ability to allow or deny browser features, whether in its own frame or content within an inline frame element (<iframe>). Here is an example of what the header looks like:

Feature-Policy: autoplay 'none'; camera 'none'

Enable in Nginx

add_header Feature-Policy "autoplay 'none'; camera 'none'" always;

Enable in Apache

header always set Feature-Policy "autoplay 'none'; camera 'none'"

How to check your HTTP security headers

Below are three quick and easy ways to check your HTTP security headers, as part of your HTTP response headers.

1. KeyCDN's HTTP Header Checker tool

KeyCDN has an online HTTP Header Checker tool that you can easily use to retrieve which HTTP security headers are currently running on your website. Simply input the URL you want to check.

It will then return with your HTTP response headers.

2. Chrome DevTools response headers

Another quick and easy way to access your HTTP security headers, as part of your response headers, is to fire up Chrome DevTools. To run this click into the Network panel press Ctrl + R (Cmd + R) to refresh the page. Click into your domain's request and you will see a section for your response headers.

3. Scan your website with Security Headers

A third way to to check your HTTP security headers is to scan your website on Security Headers. This is a handy little little tool that was developed by Scott Helme, an information security consultant. It gives your website a score, based on present HTTP security headers, from an A+ grade down to an F grade. Make sure to bookmark it. Here is an example of an A+ grade on his own website.

Here is an example of an F grade without any of the HTTP security headers present on Citi's corporate website.

It spits out both your raw HTTP headers and gives you a nice summary of each HTTP security header and what is missing.

Scott also created a Firefox extension in which you can scan the HTTP security headers of a website you want to analyze. He did an analysis in February 2016 of the Alexa top 1 million sites to see what their HTTP security header usage was and the results might surprise you. The number of sites using the strict-transport-security header nearly doubled. So it appears more people are starting to implement them, especially now that many companies are making the transition to HTTPS. We recommend during an HTTPS migration to do a full evaluation of your current security policies.

Content Security Policy (CSP) especially can be a powerful mechanism to prevent Cross Site Scripting (XSS) attacks which accounts for 84% of all security vulnerabilities in web sites. However as you can see above less than 5% of websites are actively using the headers. This needs to change.


As you can see HTTP security headers can help harden the security of your website and in most scenarios there is no reason not to use them. If you don't control access to your own web servers we recommend reaching out to your webhost and let them know. Maybe send them a link from securityheaders.io, an F grade is never a good thing!

Do you have any thoughts on HTTP security headers? If so, leave us a comment below.

  • Share

Supercharge your content delivery 🚀

Try KeyCDN with a free 14 day trial, no credit card required.

Get started


Comment policy: Comments are welcomed and encouraged. However, all comments are manually moderated and those deemed to be spam or solely promotional in nature will be deleted.
  • **bold**
  • `code`
  • ```block```
KeyCDN uses cookies to make its website easier to use. Learn more