Beginner’s Guide to Security Headers
Part 1: Understanding the basics of Security Headers

Chris de Groot
Pon.Tech.Talk
Published in
3 min readJun 7, 2023

--

Security is everywhere (Source: https://unsplash.com)

As we keep sharing more and more sensitive information online these days, the security of your online environments has become increasingly important. One way to keep websites safe from attacks is to use security headers in HTTP. These headers are small pieces of code that are added to the response of a web server to the browser. They instruct your browser how to handle certain types of content, like blocking dangerous scripts or making sure you have a secure connection. By using security headers, website owners can help protect their users from different kinds of attacks, including cross-site scripting (XSS), clickjacking and man-in-the-middle attacks. In this article, we’ll explore the different types of security headers available and how they can help to improve the security of your website and keep your information safe.

What are security headers?

In the early 2000s, with the introduction of JavaScript and all its possibilities, web developers became increasingly aware of the need for better security measures on websites. Over time, additional security headers were added to the HTTP protocol, and today, there are many different security headers available that website owners can use to help protect their users. While the use of security headers is not a guarantee of complete security, they provide an important additional layer of protection against various types of attacks.

Security headers play a crucial role in protecting your website or application. When a user’s browser requests data from the server, the server sends back a response that includes HTTP headers. These headers provide instructions to the browser on how to interact with the server and how the webpage should behave. However, security headers are not automatically included in this communication and must be specifically set up to be activated.

The structure of security headers is similar to other HTTP headers, where the key identifies the security feature and the value provides additional information or instructions. Security headers can also include multiple directives, which provide additional instructions or restrictions. These directives are separated by semicolons and can be used to further customise the behaviour of the security feature. For example, the Content-Security-Policy header can include multiple directives, such as “default-src”, “script-src”, and “style-src”, to specify different rules for different types of resources.

How can they secure our websites and -apps?

As mentioned above, security headers tell the browser what kind of actions and communication is allowed and what is not. For example, there is a header that determines which browser APIs a website is allowed to use (such as geolocation, usage of the camera). Restricting access to browser features can prevent the unauthorised use of the webcam without consent, or disclosing your location without you being aware. In addition to that, this could potentially also lead to other security vulnerabilities where an attacker injects malicious code into a website by exploiting these features (cross-site scripting (XSS) attacks). Another common security header is a header which explicitly tells the browser only to allow communication via a secured HTTP connection. If the browser of a user previously accessed the website and received this header, it will refuse to connect over HTTP even when the user explicitly clicked on or typed in a link starting with `http://`.

Now that you have a solid understanding of the basics of security headers, you can begin taking the necessary steps to implement them on your website. By doing so, you’ll be taking an important step in protecting your website from common cyber threats and ensuring that your visitors have a safe browsing experience. In Part 2 of this series, we’ll cover the most common types of security headers and how to implement them properly. Stay tuned to learn more about how to strengthen your website’s security with these powerful tools.

--

--