

What Are Security Headers?
Security headers are HTTP response headers that tell a browser how to handle your siteβs content, adding a layer of protection against common web attacks. When configured correctly, headers such as Content-Security-Policy (CSP), Strict-Transport-Security (HSTS), and X-Frame-Options help prevent cross-site scripting (XSS), man-in-the-middle attacks, and clickjacking β with no extra software, infrastructure, or cost.
When developing applications, you should always ask yourself: βIs my product secure?β
Security headers are an essential ingredient to include while developing applications β you could liken them to salt in a meal. To understand what security headers are, however, we must first navigate the maze of HTTP headersβ¦
Disclaimer β pretty technical stuff lies beyond this point.
What Are HTTP Headers?
Simply put, HTTP headers are key and value pairs that enable the client and server to send supplementary information alongside a request or response. Theyβre used to instruct a server or a browser on how it should behave and what features are supported.
Security headers are HTTP headers with specific configurations that bolster the security of applications. They are usually categorized as either request or response headers β sometimes both.
Structure Of a Security Header
The first part of a security header is the name (or key), usually the name of the specific header in use. The last part is the value that defines a specific configuration. The key and value are separated by a colon when sent in HTTP requests and responses.
Strict-Transport-Security: max-age=2300; includeSubDomains
Here the header in use is Strict-Transport-Security (the key), followed by a colon. The configurations applied are max-age and includeSubDomains, separated by a semicolon.
Strict-Transport-Security is a response header that tells a browser a website can only be browsed over an HTTPS (encrypted) connection. If any attempt is made to use HTTP (unencrypted), the connection is upgraded to HTTPS instead. The max-age value states that the HTTPS connection should subsist for 2300 seconds (about 38 minutes), and includeSubDomains specifies that subdomains are covered too.
Applying this header to a banking application, for example, reduces the risk of customers being affected by a man-in-the-middle attack: an attacker couldnβt intercept the connection because it would be encrypted, preventing sensitive data from being exposed.
Common Security Headers
The good news is that there are various security headers available. The bad news is that not all browsers support them β the site Can I Use is a good tool for checking. Some common security headers include:
- Content Security Policy (CSP) β a powerful header for mitigating injection and cross-site scripting (XSS) attacks when configured correctly.
- Cross-Origin Resource Sharing (CORS) β controls which resources can be shared and which domains are allowed.
- Strict-Transport-Security (HSTS) β an essential header that helps ensure the security of your request and response connection.
- Set-Cookie β not a security header in itself, but it carries security elements. Its directives govern what is sent to the server alongside user cookies, and it can be effective against cross-site request forgery when implemented correctly.
The Essential Security Headers at a Glance
Here are the headers most security teams recommend implementing, what each one does, and an example value to start from.
Demo: Stopping an XSS Attack with CSP
Rather than simply stating the importance of security headers, itβs better to show you. In this demo, weβll use a simple TODO list application to see how a CSP header can avert an XSS attack.
First attempt (no CSP). We start with a simple TODO list application that has no CSP header implemented. An XSS payload is prepared using a script tag and added through the form, and the Add button is selected. The attack executes on the application β in this example, changing the background color from white to teal.
In reality, an attacker could do far more than change a background color. They could execute stored XSS to target every user who visits the site, compromise user accounts, expose user data, or even take over the entire application.
Second attempt (CSP in place). Now we add a CSP header and run the same payload. This time it no longer executes, despite the page being vulnerable to XSS. Instead, it shows a blank entry on the TODO list and logs an error in the browserβs developer console.
Why Security Headers Matter So Much
Now, onto why security headers are so important β magical, in fact. Although there are no spells involved (sorry, Harry Potter fans), security headers require no installation, infrastructure, or hardware, and are entirely cost-free.
Security headers can help prevent mainstream attacks against end-users and supply chains β such as data injection, man-in-the-middle, cache-poisoning, and data leakage β and even help avert state-sponsored disinformation campaigns. This isnβt a conspiracy theory, I assure you.
In 2011, in the wake of the Arab Spring, the Syrian government executed a man-in-the-middle attack via an HTTP connection on Facebook, allowing it to track pro-rebel supporters and even censor their accounts. This attack could have been avoided if the Strict-Transport-Security header had been in place. Once your headers are running, you can use securityheaders.com to analyze their security level.
How to Add and Test Security Headers
Set security headers at your web server, reverse proxy, or CDN/hosting layer β not in page HTML β so they apply to every response. On a platform like Webflow, you can configure custom response headers; on your own infrastructure, youβd set them in your server (e.g. Nginx or Apache) or edge configuration.
To check your work, scan your live site with securityheaders.com, inspect the Response Headers in your browserβs developer tools (Network tab), and confirm browser support with Can I Use. Immersiveβs hands-on Secure Engineering labs let developers practice configuring CSP and other headers in real environments.
βDevelopers have a really hard job. They donβt get measured on security β they get measured on releasing good code and products. So a lot of the focus isnβt necessarily on security, but security really underpins all of it.β
β Chris Wood, Principal Application Security SME, Immersive
Defense in Depth: Headers Are One Layer
Thereβs no such thing as being too prepared when it comes to cybersecurity. This is the essence of a defense-in-depth approach, which Immersive champions. Security headers are powerful, but theyβre one layer β most effective alongside secure coding, input validation, dependency and patch management, and regular testing.
Now that youβve been introduced to the wonderful world of security headers, explore Immersiveβs Secure Engineering labs β part of the broader application security catalog β to learn the best headers to use and how to configure them correctly. You can also see how Immersive One helps teams build security in across the SDLC, or book a demo. Make haste, my friend, for the attackers are lurking!
Frequently Asked Questions
What Are Security Headers?
Security headers are HTTP response headers that instruct a browser how to handle a website's content, adding a layer of defense against common web attacks. Correctly configured headers such as Content-Security-Policy, Strict-Transport-Security, and X-Frame-Options help prevent cross-site scripting (XSS), man-in-the-middle attacks, and clickjacking, with no extra software or cost.
What Are the Most Important Security Headers?
The most widely recommended security headers are Content-Security-Policy (CSP), Strict-Transport-Security (HSTS), X-Frame-Options, X-Content-Type-Options, Referrer-Policy, and Permissions-Policy. Cross-Origin Resource Sharing (CORS) rules and secure Set-Cookie attributes (Secure, HttpOnly, SameSite) are also important for controlling access and protecting session cookies.
How Do Security Headers Help Prevent Xss Attacks?
A Content-Security-Policy (CSP) header tells the browser which sources of scripts and other content are trusted. If an attacker injects a malicious inline script, the CSP blocks it from running because it isn't on the allowed list, so the page stays safe even if it is technically vulnerable to cross-site scripting.
How Do I Add and Test Security Headers?
Set security headers at your web server, reverse proxy, or CDN/hosting layer rather than in page HTML. Then test your live site with a scanner such as securityheaders.com and inspect the Response Headers in your browser's developer tools. Use a compatibility resource like Can I Use to confirm browser support.
Are Security Headers Enough to Secure an Application on Their Own?
No. Security headers are one layer of a defense-in-depth strategy. They should be combined with secure coding practices, input validation, dependency and patch management, authentication controls, and regular testing to meaningfully reduce risk.

Aforoghene Annabelle Pendlebury
Junior Application Security Engineer
Immersive Labs
β

See how to prove readiness with one platform.
See how Immersive One helps technical teams and leaders prove readiness, close capability gaps, benchmark progress, and report cyber resilience with confidence.