<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: az hala</title>
    <description>The latest articles on DEV Community by az hala (@newazhala).</description>
    <link>https://dev.to/newazhala</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4108526%2F1a347ead-6803-45a0-8354-d6a64ccd918c.png</url>
      <title>DEV Community: az hala</title>
      <link>https://dev.to/newazhala</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/newazhala"/>
    <language>en</language>
    <item>
      <title>HTTP Security Headers Explained: A Practical Guide for Developers</title>
      <dc:creator>az hala</dc:creator>
      <pubDate>Thu, 03 Sep 2026 20:54:39 +0000</pubDate>
      <link>https://dev.to/newazhala/http-security-headers-explained-a-practical-guide-for-developers-1fal</link>
      <guid>https://dev.to/newazhala/http-security-headers-explained-a-practical-guide-for-developers-1fal</guid>
      <description>&lt;h1&gt;
  
  
  HTTP Security Headers Explained: A Practical Guide for Developers
&lt;/h1&gt;

&lt;p&gt;A website can use HTTPS, strong passwords, authentication, and secure application code and still have security weaknesses that browsers can help mitigate.&lt;/p&gt;

&lt;p&gt;One of the simplest ways to add another layer of protection is through &lt;strong&gt;HTTP security headers&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Security headers allow a web server to tell the browser how certain resources should be handled, whether a page can be embedded, which origins can load content, and how much information should be included in referrer requests.&lt;/p&gt;

&lt;p&gt;In this guide, we'll look at the most important security headers, explain what they do, and show practical configuration examples for modern websites.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Are HTTP Security Headers?
&lt;/h2&gt;

&lt;p&gt;HTTP security headers are response headers sent by a web server to a browser.&lt;/p&gt;

&lt;p&gt;For example, a server might return:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="k"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="m"&gt;200&lt;/span&gt;
&lt;span class="na"&gt;Content-Type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;text/html; charset=UTF-8&lt;/span&gt;
&lt;span class="na"&gt;Content-Security-Policy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;default-src 'self'&lt;/span&gt;
&lt;span class="na"&gt;X-Content-Type-Options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nosniff&lt;/span&gt;
&lt;span class="na"&gt;Referrer-Policy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;strict-origin-when-cross-origin&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The browser reads these headers and adjusts its behavior based on the policies provided by the server.&lt;/p&gt;

&lt;p&gt;Security headers can help reduce the impact of several common web security problems, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cross-site scripting (XSS)&lt;/li&gt;
&lt;li&gt;Clickjacking&lt;/li&gt;
&lt;li&gt;MIME-type confusion&lt;/li&gt;
&lt;li&gt;Unsafe resource loading&lt;/li&gt;
&lt;li&gt;Unnecessary referrer information exposure&lt;/li&gt;
&lt;li&gt;Some cross-origin security risks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, security headers are &lt;strong&gt;not a replacement for secure application development&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You still need proper authentication, authorization, input validation, output encoding, secure session management, HTTPS, dependency management, and other security practices.&lt;/p&gt;

&lt;p&gt;Think of security headers as an additional defensive layer.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Content-Security-Policy (CSP)
&lt;/h2&gt;

&lt;p&gt;Content-Security-Policy, commonly called CSP, is one of the most powerful security headers available to web developers.&lt;/p&gt;

&lt;p&gt;CSP allows you to control where browsers can load resources such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JavaScript&lt;/li&gt;
&lt;li&gt;CSS&lt;/li&gt;
&lt;li&gt;Images&lt;/li&gt;
&lt;li&gt;Fonts&lt;/li&gt;
&lt;li&gt;Frames&lt;/li&gt;
&lt;li&gt;Media&lt;/li&gt;
&lt;li&gt;Connections&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A very simple policy is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;Content-Security-Policy: default-src 'self'
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tells the browser that resources should generally come from the same origin.&lt;/p&gt;

&lt;p&gt;A more realistic example could be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;Content-Security-Policy: default-src 'self'; script-src 'self' https://cdn.example.com; style-src 'self' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data: https:;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The exact policy depends entirely on the application.&lt;/p&gt;

&lt;p&gt;For example, if your website uses third-party analytics, payment services, video embeds, or CDNs, those resources may need to be explicitly allowed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why CSP Matters
&lt;/h3&gt;

&lt;p&gt;One important benefit of CSP is reducing the impact of certain XSS attacks.&lt;/p&gt;

&lt;p&gt;If an attacker manages to inject a script into a page but the script violates the site's CSP, the browser can refuse to execute it.&lt;/p&gt;

&lt;p&gt;That makes CSP an important defense-in-depth mechanism.&lt;/p&gt;

&lt;h3&gt;
  
  
  Test CSP Before Enforcing It
&lt;/h3&gt;

&lt;p&gt;A restrictive CSP can accidentally break a website.&lt;/p&gt;

&lt;p&gt;For an existing application, you can test a policy with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;Content-Security-Policy-Report-Only: default-src 'self'
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Report-only mode allows developers to identify policy violations without immediately blocking the resources.&lt;/p&gt;

&lt;p&gt;Once the policy has been tested and adjusted, it can be moved to the normal &lt;code&gt;Content-Security-Policy&lt;/code&gt; header.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Strict-Transport-Security (HSTS)
&lt;/h2&gt;

&lt;p&gt;HTTP Strict Transport Security tells browsers that a website should be accessed using HTTPS.&lt;/p&gt;

&lt;p&gt;A basic configuration looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;Strict-Transport-Security: max-age=31536000
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The value is expressed in seconds.&lt;/p&gt;

&lt;p&gt;For example, &lt;code&gt;31536000&lt;/code&gt; represents one year.&lt;/p&gt;

&lt;p&gt;A configuration may also include subdomains:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;Strict-Transport-Security: max-age=31536000; includeSubDomains
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Be Careful With HSTS
&lt;/h3&gt;

&lt;p&gt;HSTS should not be enabled blindly.&lt;/p&gt;

&lt;p&gt;Before using &lt;code&gt;includeSubDomains&lt;/code&gt;, make sure the relevant subdomains are correctly configured for HTTPS.&lt;/p&gt;

&lt;p&gt;Otherwise, users could have problems accessing services that still depend on HTTP.&lt;/p&gt;

&lt;p&gt;HSTS is particularly useful for helping prevent protocol downgrade attacks and ensuring that browsers consistently use HTTPS after receiving the policy.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. X-Content-Type-Options
&lt;/h2&gt;

&lt;p&gt;This is one of the simplest security headers to configure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;X-Content-Type-Options: nosniff
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;nosniff&lt;/code&gt; value tells browsers not to try to guess the MIME type of certain resources.&lt;/p&gt;

&lt;p&gt;Web servers should correctly specify the content type of files such as JavaScript, CSS, images, and other resources.&lt;/p&gt;

&lt;p&gt;For many websites, adding this header is a straightforward security improvement.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Referrer-Policy
&lt;/h2&gt;

&lt;p&gt;When a browser navigates from one page to another, it can send information about the previous page through the &lt;code&gt;Referer&lt;/code&gt; request header.&lt;/p&gt;

&lt;p&gt;Depending on the URL structure of your website, that information may reveal more than you want to share.&lt;/p&gt;

&lt;p&gt;A commonly useful policy is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;Referrer-Policy: strict-origin-when-cross-origin
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This generally provides more limited information when navigating between different origins while retaining useful referrer information for same-origin requests.&lt;/p&gt;

&lt;p&gt;Other policies include:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;Referrer-Policy: no-referrer
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;Referrer-Policy: same-origin
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The right choice depends on the privacy and analytics requirements of your application.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Permissions-Policy
&lt;/h2&gt;

&lt;p&gt;Modern browsers expose powerful features such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Camera&lt;/li&gt;
&lt;li&gt;Microphone&lt;/li&gt;
&lt;li&gt;Geolocation&lt;/li&gt;
&lt;li&gt;Sensors&lt;/li&gt;
&lt;li&gt;Fullscreen&lt;/li&gt;
&lt;li&gt;USB&lt;/li&gt;
&lt;li&gt;Other browser capabilities&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Permissions-Policy allows developers to control which origins can use specific features.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;Permissions-Policy: camera=(), microphone=(), geolocation=()
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This configuration disables camera, microphone, and geolocation access for the document.&lt;/p&gt;

&lt;p&gt;If your application does not need a browser capability, restricting it can reduce unnecessary exposure.&lt;/p&gt;

&lt;p&gt;If the application actually requires a feature, the policy should be configured accordingly.&lt;/p&gt;




&lt;h2&gt;
  
  
  6. X-Frame-Options and Clickjacking
&lt;/h2&gt;

&lt;p&gt;Clickjacking occurs when an attacker attempts to trick users into interacting with a website through an embedded frame.&lt;/p&gt;

&lt;p&gt;A traditional defense is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;X-Frame-Options: DENY
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This prevents the page from being framed.&lt;/p&gt;

&lt;p&gt;Another option is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;X-Frame-Options: SAMEORIGIN
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This allows framing by pages from the same origin.&lt;/p&gt;

&lt;p&gt;Modern applications can also use CSP's &lt;code&gt;frame-ancestors&lt;/code&gt; directive:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;Content-Security-Policy: frame-ancestors 'self'
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The exact configuration depends on whether your website needs to be embedded by other pages.&lt;/p&gt;




&lt;h2&gt;
  
  
  7. Cross-Origin Security Headers
&lt;/h2&gt;

&lt;p&gt;Modern web applications may also use headers that control relationships between documents and resources from different origins.&lt;/p&gt;

&lt;p&gt;Three headers you may encounter are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Resource-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These headers have different purposes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cross-Origin-Opener-Policy
&lt;/h3&gt;

&lt;p&gt;COOP controls how a document interacts with browsing contexts from other origins.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;Cross-Origin-Opener-Policy: same-origin
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Cross-Origin-Resource-Policy
&lt;/h3&gt;

&lt;p&gt;CORP allows a resource to specify which origins can load it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;Cross-Origin-Resource-Policy: same-origin
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Cross-Origin-Embedder-Policy
&lt;/h3&gt;

&lt;p&gt;COEP controls whether cross-origin resources can be embedded under specific conditions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;Cross-Origin-Embedder-Policy: require-corp
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These policies can affect third-party resources, so they should be introduced carefully and tested against the actual application.&lt;/p&gt;




&lt;h1&gt;
  
  
  A Practical Starting Configuration
&lt;/h1&gt;

&lt;p&gt;A basic security configuration might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;Content-Security-Policy: default-src 'self'
Strict-Transport-Security: max-age=31536000
X-Content-Type-Options: nosniff
Referrer-Policy: strict-origin-when-cross-origin
Permissions-Policy: camera=(), microphone=(), geolocation=()
X-Frame-Options: SAMEORIGIN
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But this should &lt;strong&gt;not&lt;/strong&gt; be treated as a universal copy-and-paste configuration.&lt;/p&gt;

&lt;p&gt;Every application is different.&lt;/p&gt;

&lt;p&gt;For example, a website that uses Google Fonts, YouTube, analytics platforms, advertising networks, payment gateways, or external JavaScript libraries may require a more specific CSP.&lt;/p&gt;

&lt;p&gt;Always test your configuration before deploying it to production.&lt;/p&gt;




&lt;h1&gt;
  
  
  Configuring Security Headers With Apache
&lt;/h1&gt;

&lt;p&gt;Apache HTTP Server can configure response headers using &lt;code&gt;mod_headers&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight apache"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nl"&gt;IfModule&lt;/span&gt;&lt;span class="sr"&gt; mod_headers.c&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="nc"&gt;Header&lt;/span&gt; &lt;span class="ss"&gt;always&lt;/span&gt; &lt;span class="ss"&gt;set&lt;/span&gt; X-Content-Type-Options "nosniff"
    &lt;span class="nc"&gt;Header&lt;/span&gt; &lt;span class="ss"&gt;always&lt;/span&gt; &lt;span class="ss"&gt;set&lt;/span&gt; Referrer-Policy "strict-origin-when-cross-origin"
    &lt;span class="nc"&gt;Header&lt;/span&gt; &lt;span class="ss"&gt;always&lt;/span&gt; &lt;span class="ss"&gt;set&lt;/span&gt; X-Frame-Options "SAMEORIGIN"
    &lt;span class="nc"&gt;Header&lt;/span&gt; &lt;span class="ss"&gt;always&lt;/span&gt; &lt;span class="ss"&gt;set&lt;/span&gt; Permissions-Policy "camera=(), microphone=(), geolocation=()"
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nl"&gt;IfModule&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;HSTS can be added after HTTPS has been correctly configured:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight apache"&gt;&lt;code&gt;&lt;span class="nc"&gt;Header&lt;/span&gt; &lt;span class="ss"&gt;always&lt;/span&gt; &lt;span class="ss"&gt;set&lt;/span&gt; Strict-Transport-Security "max-age=31536000"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure the relevant Apache modules and configuration permissions are available on your hosting environment.&lt;/p&gt;




&lt;h1&gt;
  
  
  Configuring Security Headers With Nginx
&lt;/h1&gt;

&lt;p&gt;Nginx uses the &lt;code&gt;add_header&lt;/code&gt; directive.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;&lt;span class="k"&gt;add_header&lt;/span&gt; &lt;span class="s"&gt;X-Content-Type-Options&lt;/span&gt; &lt;span class="s"&gt;"nosniff"&lt;/span&gt; &lt;span class="s"&gt;always&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;add_header&lt;/span&gt; &lt;span class="s"&gt;Referrer-Policy&lt;/span&gt; &lt;span class="s"&gt;"strict-origin-when-cross-origin"&lt;/span&gt; &lt;span class="s"&gt;always&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;add_header&lt;/span&gt; &lt;span class="s"&gt;X-Frame-Options&lt;/span&gt; &lt;span class="s"&gt;"SAMEORIGIN"&lt;/span&gt; &lt;span class="s"&gt;always&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;add_header&lt;/span&gt; &lt;span class="s"&gt;Permissions-Policy&lt;/span&gt; &lt;span class="s"&gt;"camera=(),&lt;/span&gt; &lt;span class="s"&gt;microphone=(),&lt;/span&gt; &lt;span class="s"&gt;geolocation=()"&lt;/span&gt; &lt;span class="s"&gt;always&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;HSTS can be configured as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;&lt;span class="k"&gt;add_header&lt;/span&gt; &lt;span class="s"&gt;Strict-Transport-Security&lt;/span&gt; &lt;span class="s"&gt;"max-age=31536000"&lt;/span&gt; &lt;span class="s"&gt;always&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Again, verify your HTTPS configuration before enabling HSTS.&lt;/p&gt;




&lt;h1&gt;
  
  
  Configuring Headers in Node.js
&lt;/h1&gt;

&lt;p&gt;If you're building a Node.js application, you can set response headers in application code.&lt;/p&gt;

&lt;p&gt;A simple example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setHeader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;X-Content-Type-Options&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;nosniff&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setHeader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Referrer-Policy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;strict-origin-when-cross-origin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setHeader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;X-Frame-Options&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SAMEORIGIN&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For larger applications, security middleware can make header management easier.&lt;/p&gt;

&lt;p&gt;However, developers should still understand what the individual headers actually do.&lt;/p&gt;

&lt;p&gt;Using middleware without understanding the policies can make debugging much harder.&lt;/p&gt;




&lt;h1&gt;
  
  
  How to Check Security Headers
&lt;/h1&gt;

&lt;p&gt;You don't necessarily need a specialized tool to inspect HTTP response headers.&lt;/p&gt;

&lt;p&gt;One of the simplest methods is using &lt;code&gt;curl&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-I&lt;/span&gt; https://example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You may see something similar to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP/2 200
content-type: text/html
x-content-type-options: nosniff
referrer-policy: strict-origin-when-cross-origin
strict-transport-security: max-age=31536000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also inspect headers directly from your browser.&lt;/p&gt;

&lt;p&gt;Open Developer Tools, go to the &lt;strong&gt;Network&lt;/strong&gt; tab, reload the page, select the main document request, and inspect the &lt;strong&gt;Response Headers&lt;/strong&gt; section.&lt;/p&gt;

&lt;p&gt;This is especially useful when troubleshooting a missing or incorrectly configured header.&lt;/p&gt;




&lt;h1&gt;
  
  
  Automating Security Header Audits
&lt;/h1&gt;

&lt;p&gt;If you regularly work with multiple websites, manually checking every response becomes repetitive.&lt;/p&gt;

&lt;p&gt;A security header checker can automate the process.&lt;/p&gt;

&lt;p&gt;A basic scanner can:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Accept a URL.&lt;/li&gt;
&lt;li&gt;Make an HTTP or HTTPS request.&lt;/li&gt;
&lt;li&gt;Follow redirects.&lt;/li&gt;
&lt;li&gt;Read the final response headers.&lt;/li&gt;
&lt;li&gt;Check important security policies.&lt;/li&gt;
&lt;li&gt;Identify missing headers.&lt;/li&gt;
&lt;li&gt;Produce a report or score.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A simplified Node.js example might look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;contentSecurityPolicy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;content-security-policy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;

  &lt;span class="na"&gt;strictTransportSecurity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;strict-transport-security&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;

  &lt;span class="na"&gt;contentTypeOptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;x-content-type-options&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;

  &lt;span class="na"&gt;referrerPolicy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;referrer-policy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;

  &lt;span class="na"&gt;permissionsPolicy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;permissions-policy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A production-grade scanner requires much more than this small example.&lt;/p&gt;

&lt;p&gt;Important considerations include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Redirect limits&lt;/li&gt;
&lt;li&gt;Request timeouts&lt;/li&gt;
&lt;li&gt;TLS certificate validation&lt;/li&gt;
&lt;li&gt;DNS resolution&lt;/li&gt;
&lt;li&gt;IPv4 and IPv6 handling&lt;/li&gt;
&lt;li&gt;Private network protection&lt;/li&gt;
&lt;li&gt;SSRF prevention&lt;/li&gt;
&lt;li&gt;Rate limiting&lt;/li&gt;
&lt;li&gt;Abuse prevention&lt;/li&gt;
&lt;li&gt;Maximum response sizes&lt;/li&gt;
&lt;li&gt;Error handling&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If a tool accepts arbitrary URLs, SSRF protection is especially important.&lt;/p&gt;

&lt;p&gt;A server should not blindly make requests to internal services or private network addresses.&lt;/p&gt;




&lt;h1&gt;
  
  
  Security Headers and Technical SEO
&lt;/h1&gt;

&lt;p&gt;Security headers are primarily security mechanisms rather than direct search-engine ranking factors.&lt;/p&gt;

&lt;p&gt;However, security and technical SEO can overlap in several areas.&lt;/p&gt;

&lt;p&gt;For example, incorrect HTTPS configuration can cause redirect problems.&lt;/p&gt;

&lt;p&gt;An overly restrictive CSP can prevent important resources from loading.&lt;/p&gt;

&lt;p&gt;Broken redirects can interfere with crawling and canonicalization.&lt;/p&gt;

&lt;p&gt;Mixed-content problems can affect page functionality.&lt;/p&gt;

&lt;p&gt;Server reliability can also influence how users and automated crawlers experience a website.&lt;/p&gt;

&lt;p&gt;This means security configuration should be considered alongside other technical website practices such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Crawlability&lt;/li&gt;
&lt;li&gt;HTTPS&lt;/li&gt;
&lt;li&gt;Canonical URLs&lt;/li&gt;
&lt;li&gt;Structured data&lt;/li&gt;
&lt;li&gt;Mobile rendering&lt;/li&gt;
&lt;li&gt;Page performance&lt;/li&gt;
&lt;li&gt;Internal linking&lt;/li&gt;
&lt;li&gt;Server responses&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For developers and website owners working on broader technical SEO, understanding how the server and browser interact is just as important as optimizing page content.&lt;/p&gt;




&lt;h1&gt;
  
  
  Common Security Header Mistakes
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Mistake 1: Copying a CSP Without Testing
&lt;/h2&gt;

&lt;p&gt;CSP is powerful, but an overly restrictive policy can break legitimate resources.&lt;/p&gt;

&lt;p&gt;Always test the policy against your actual application.&lt;/p&gt;




&lt;h2&gt;
  
  
  Mistake 2: Enabling HSTS Too Early
&lt;/h2&gt;

&lt;p&gt;HSTS can create accessibility problems if parts of your infrastructure are not ready for HTTPS.&lt;/p&gt;

&lt;p&gt;Verify your domain and relevant subdomains before deploying an aggressive HSTS policy.&lt;/p&gt;




&lt;h2&gt;
  
  
  Mistake 3: Adding Every Header You Find
&lt;/h2&gt;

&lt;p&gt;More headers do not automatically mean better security.&lt;/p&gt;

&lt;p&gt;Security policies should address the actual requirements of your application.&lt;/p&gt;

&lt;p&gt;A poorly configured policy can create compatibility problems without providing meaningful protection.&lt;/p&gt;




&lt;h2&gt;
  
  
  Mistake 4: Forgetting Third-Party Resources
&lt;/h2&gt;

&lt;p&gt;Modern websites often depend on external services.&lt;/p&gt;

&lt;p&gt;Your CSP and other policies should account for legitimate third-party resources without unnecessarily allowing everything.&lt;/p&gt;




&lt;h2&gt;
  
  
  Mistake 5: Testing Only the Homepage
&lt;/h2&gt;

&lt;p&gt;Different routes can be handled differently.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/
 /login
 /dashboard
 /api/
 /static/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;may be served through different application layers, proxies, or services.&lt;/p&gt;

&lt;p&gt;Important routes should therefore be included in your security testing.&lt;/p&gt;




&lt;h1&gt;
  
  
  Security Header Audit Checklist
&lt;/h1&gt;

&lt;p&gt;Use this checklist when reviewing a website:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[ ] HTTPS is correctly configured&lt;/li&gt;
&lt;li&gt;[ ] HSTS is appropriate for the domain&lt;/li&gt;
&lt;li&gt;[ ] CSP is present and tested&lt;/li&gt;
&lt;li&gt;[ ] X-Content-Type-Options is configured&lt;/li&gt;
&lt;li&gt;[ ] Referrer-Policy is configured&lt;/li&gt;
&lt;li&gt;[ ] Permissions-Policy has been reviewed&lt;/li&gt;
&lt;li&gt;[ ] Clickjacking protection is configured&lt;/li&gt;
&lt;li&gt;[ ] Cross-origin policies are reviewed where necessary&lt;/li&gt;
&lt;li&gt;[ ] Redirects behave correctly&lt;/li&gt;
&lt;li&gt;[ ] Third-party resources are accounted for&lt;/li&gt;
&lt;li&gt;[ ] Important routes return the expected headers&lt;/li&gt;
&lt;li&gt;[ ] Security policies do not break legitimate functionality&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;HTTP security headers provide an additional layer of browser-enforced protection for modern websites.&lt;/p&gt;

&lt;p&gt;The most important lesson is not to copy a list of headers and assume the website is secure.&lt;/p&gt;

&lt;p&gt;Instead, use a process:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understand → Configure → Test → Monitor → Improve&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Start with the policies that make sense for your application.&lt;/p&gt;

&lt;p&gt;If you manage multiple websites, automating security-header checks can also save time and make configuration problems easier to identify.&lt;/p&gt;

&lt;p&gt;Building a small security-header scanner is an excellent practical project for developers because it combines HTTP, networking, backend development, browser security, and real-world web infrastructure.&lt;/p&gt;

&lt;p&gt;Security headers are only one part of a secure website, but they are a practical and useful place to start.&lt;/p&gt;




&lt;h2&gt;
  
  
  Further Reading
&lt;/h2&gt;

&lt;p&gt;For deeper information, developers should consult authoritative documentation and security references such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;OWASP HTTP Security Response Headers Cheat Sheet&lt;/li&gt;
&lt;li&gt;MDN Web Docs&lt;/li&gt;
&lt;li&gt;Content Security Policy documentation&lt;/li&gt;
&lt;li&gt;HTTP Strict Transport Security documentation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Always verify security recommendations against current browser and server documentation before deploying them to production.&lt;br&gt;
If you're working on the broader technical side of website SEO, you can also use this guide from AzkiWeb:&lt;br&gt;
&lt;a href="https://azkiweb.com/seo-website" rel="noopener noreferrer"&gt;https://azkiweb.com/seo-website&lt;/a&gt;&lt;br&gt;
For developers who want to go beyond security headers and improve the overall technical foundation of a website, see AzkiWeb's guide to web design and development:&lt;br&gt;
&lt;a href="https://azkiweb.com/web-design" rel="noopener noreferrer"&gt;https://azkiweb.com/web-design&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>security</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
