<?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: Everest Paudel</title>
    <description>The latest articles on DEV Community by Everest Paudel (@rest).</description>
    <link>https://dev.to/rest</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%2F4250002%2Fd7569d75-56f0-4914-a72a-f8b705657da1.jpg</url>
      <title>DEV Community: Everest Paudel</title>
      <link>https://dev.to/rest</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rest"/>
    <language>en</language>
    <item>
      <title>Understanding CSRF: How Attackers Trick Users Into Performing Unauthorized Actions</title>
      <dc:creator>Everest Paudel</dc:creator>
      <pubDate>Wed, 18 Nov 2026 01:26:25 +0000</pubDate>
      <link>https://dev.to/rest/understanding-csrf-how-attackers-trick-users-into-performing-unauthorized-actions-33ef</link>
      <guid>https://dev.to/rest/understanding-csrf-how-attackers-trick-users-into-performing-unauthorized-actions-33ef</guid>
      <description>&lt;h1&gt;
  
  
  Understanding CSRF: How Attackers Trick Users Into Performing Unauthorized Actions
&lt;/h1&gt;

&lt;p&gt;Imagine you're logged into your bank account in one browser tab.&lt;/p&gt;

&lt;p&gt;You open another tab and visit a website that contains malicious content.&lt;/p&gt;

&lt;p&gt;Without realizing it, your browser sends a request to your bank using your existing login session.&lt;/p&gt;

&lt;p&gt;What if that request transfers money?&lt;/p&gt;

&lt;p&gt;This is the basic idea behind &lt;strong&gt;Cross-Site Request Forgery (CSRF)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;CSRF is a web application vulnerability where an attacker tricks an authenticated user's browser into sending an unwanted request to a website where the user is already logged in.&lt;/p&gt;

&lt;p&gt;Let's understand how it works.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. First, Understand How Authentication Cookies Work
&lt;/h2&gt;

&lt;p&gt;Before understanding CSRF, we need to understand cookies.&lt;/p&gt;

&lt;p&gt;Imagine you log in to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://bank.example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After successful authentication, the server sends a session cookie:&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="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt; &lt;span class="no"&gt;OK&lt;/span&gt;
&lt;span class="na"&gt;Set-Cookie: sessionid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;abc123&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nc"&gt;Secure&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nc"&gt;HttpOnly&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your browser stores this cookie.&lt;/p&gt;

&lt;p&gt;Whenever you make another request to the same website, the browser automatically includes the cookie.&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="no"&gt;POST&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;account&lt;/span&gt; &lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt;
&lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;bank&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;
&lt;span class="na"&gt;Cookie: sessionid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;abc123&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The server recognizes your session and knows you are authenticated.&lt;/p&gt;

&lt;p&gt;This automatic cookie behavior is an important part of understanding CSRF.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. How Does a CSRF Attack Work?
&lt;/h2&gt;

&lt;p&gt;Let's use a simple example.&lt;/p&gt;

&lt;p&gt;Suppose a banking application has an endpoint:&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="no"&gt;POST&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;transfer&lt;/span&gt; &lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt;
&lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;bank&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;
&lt;span class="na"&gt;Cookie: sessionid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;abc123&lt;/span&gt;

&lt;span class="na"&gt;amount&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;attacker&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The application checks the session cookie and processes the transfer.&lt;/p&gt;

&lt;p&gt;Now imagine an attacker creates a malicious webpage containing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="na"&gt;action&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"https://bank.example.com/transfer"&lt;/span&gt; &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"POST"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"hidden"&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"amount"&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"500"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"hidden"&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"to"&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"attacker"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;forms&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;submit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The attacker tricks an authenticated victim into visiting that page.&lt;/p&gt;

&lt;p&gt;If the browser sends the bank's session cookie with the cross-site request, and the application lacks effective CSRF protections, the transfer might be processed.&lt;/p&gt;

&lt;p&gt;The victim may not even realize that the request happened.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; This example assumes the application accepts the request without additional CSRF validation and that cookie settings allow the cross-site request.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Understanding the Attack Flow
&lt;/h2&gt;

&lt;p&gt;Let's visualize the complete process.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. Victim logs into bank.example.com
             |
             v
2. Browser stores authentication cookie
             |
             v
3. Victim visits attacker's website
             |
             v
4. Malicious webpage triggers a request
             |
             v
5. Browser may automatically attach
   the bank's authentication cookie
             |
             v
6. Bank receives the request
             |
             v
7. If CSRF protection is missing,
   the action may be executed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important thing to understand is that the attacker does not necessarily need to know the victim's password or session cookie.&lt;/p&gt;

&lt;p&gt;The browser already has the authenticated session.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Why Does CSRF Happen?
&lt;/h2&gt;

&lt;p&gt;The fundamental problem is that the application assumes:&lt;/p&gt;

&lt;p&gt;"If a request contains a valid session cookie, it must have been intentionally initiated by the authenticated user."&lt;/p&gt;

&lt;p&gt;But this assumption is not always correct.&lt;/p&gt;

&lt;p&gt;A browser can send authenticated requests that were triggered by another website.&lt;/p&gt;

&lt;p&gt;The server needs additional mechanisms to verify that the request was legitimately initiated.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Types of CSRF
&lt;/h2&gt;

&lt;h3&gt;
  
  
  A. GET-Based CSRF
&lt;/h3&gt;

&lt;p&gt;Imagine an application performs a sensitive action through a GET request:&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="na"&gt;GET /change-email?email&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;attacker&lt;/span&gt;@&lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt; &lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt;
&lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An attacker might create:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"https://example.com/change-email?email=attacker@example.com"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the browser loads the image, it sends a GET request.&lt;/p&gt;

&lt;p&gt;If the application performs the sensitive action through GET and accepts the victim's session cookie, the action might succeed.&lt;/p&gt;

&lt;p&gt;Sensitive state-changing operations should not use GET requests.&lt;/p&gt;

&lt;h3&gt;
  
  
  B. POST-Based CSRF
&lt;/h3&gt;

&lt;p&gt;POST-based CSRF uses an HTML form to submit data to a target website.&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 html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="na"&gt;action&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"https://example.com/change-password"&lt;/span&gt; &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"POST"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"hidden"&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"password"&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"newpassword123"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;forms&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;submit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Whether this works depends on the application's CSRF protections, cookie policy, and other browser security controls.&lt;/p&gt;

&lt;h3&gt;
  
  
  C. Login CSRF
&lt;/h3&gt;

&lt;p&gt;Login CSRF is another interesting variation.&lt;/p&gt;

&lt;p&gt;An attacker attempts to make a victim log into an application using an account controlled by the attacker.&lt;/p&gt;

&lt;p&gt;This can cause the victim to unknowingly interact with the attacker's account.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. How Do Developers Prevent CSRF?
&lt;/h2&gt;

&lt;p&gt;There are several important defensive mechanisms.&lt;/p&gt;

&lt;h3&gt;
  
  
  A. CSRF Tokens
&lt;/h3&gt;

&lt;p&gt;A server generates a unique, unpredictable token and associates it with the user's session.&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 html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"POST"&lt;/span&gt; &lt;span class="na"&gt;action&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/transfer"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"hidden"&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"csrf_token"&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"random-token"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"amount"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Transfer&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the form is submitted, the server validates the token.&lt;/p&gt;

&lt;p&gt;An attacker on another website generally cannot read the legitimate page's token because of the browser's same-origin policy.&lt;/p&gt;

&lt;p&gt;Without a valid token, the server rejects the request.&lt;/p&gt;

&lt;h3&gt;
  
  
  B. SameSite Cookies
&lt;/h3&gt;

&lt;p&gt;Cookies support the &lt;code&gt;SameSite&lt;/code&gt; attribute.&lt;/p&gt;

&lt;p&gt;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="na"&gt;Set-Cookie: sessionid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;abc123&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nc"&gt;Secure&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nc"&gt;HttpOnly&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nc"&gt;SameSite&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;Lax&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Common values:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Attribute&lt;/th&gt;
&lt;th&gt;Behavior&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Strict&lt;/td&gt;
&lt;td&gt;Restricts cookies to same-site contexts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Lax&lt;/td&gt;
&lt;td&gt;Allows cookies in certain cross-site navigations&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;Allows cross-site cookie use, requiring Secure&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;SameSite helps reduce CSRF risk, but it should not automatically replace appropriate CSRF protections.&lt;/p&gt;

&lt;h3&gt;
  
  
  C. Origin and Referer Validation
&lt;/h3&gt;

&lt;p&gt;Applications can validate the &lt;code&gt;Origin&lt;/code&gt; header and, where appropriate, the &lt;code&gt;Referer&lt;/code&gt; header to check where a request originated.&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="nc"&gt;Origin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;https&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//attacker.example&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the application only accepts requests originating from its trusted website, it can reject unexpected origins.&lt;/p&gt;

&lt;p&gt;These headers should be validated carefully, with a safe policy for missing or malformed values.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. How to Test CSRF Using Burp Suite
&lt;/h2&gt;

&lt;p&gt;When testing an application you own or are authorized to assess:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Log in to the application.&lt;/li&gt;
&lt;li&gt;Identify sensitive actions such as changing an email address or updating account settings.&lt;/li&gt;
&lt;li&gt;Intercept the corresponding request in Burp Suite.&lt;/li&gt;
&lt;li&gt;Look for CSRF tokens.&lt;/li&gt;
&lt;li&gt;Investigate whether the token is validated server-side.&lt;/li&gt;
&lt;li&gt;Test whether the application checks Origin or Referer.&lt;/li&gt;
&lt;li&gt;Examine the authentication cookie's SameSite configuration.&lt;/li&gt;
&lt;li&gt;Verify whether an unauthorized cross-site request can actually perform the action.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Pay attention to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Missing CSRF tokens.&lt;/li&gt;
&lt;li&gt;Tokens that are not validated.&lt;/li&gt;
&lt;li&gt;Tokens that can be reused incorrectly.&lt;/li&gt;
&lt;li&gt;Sensitive GET endpoints.&lt;/li&gt;
&lt;li&gt;Inadequate Origin validation.&lt;/li&gt;
&lt;li&gt;Cookie configurations that permit unwanted cross-site requests.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Remember: a missing CSRF token alone does not always establish an exploitable CSRF vulnerability. Modern applications may have other effective protections.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. CSRF vs XSS: What Is the Difference?
&lt;/h2&gt;

&lt;p&gt;These two vulnerabilities are often confused.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;CSRF&lt;/th&gt;
&lt;th&gt;XSS&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Tricks a victim's browser into sending unwanted requests&lt;/td&gt;
&lt;td&gt;Injects attacker-controlled JavaScript into a trusted page&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Abuses the victim's authenticated session&lt;/td&gt;
&lt;td&gt;Executes scripts in the context of the vulnerable website&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Does not inherently require JavaScript execution on the target website&lt;/td&gt;
&lt;td&gt;Requires script execution in the target website's origin&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CSRF tokens and SameSite cookies help prevent it&lt;/td&gt;
&lt;td&gt;Contextual output encoding and safe sanitization help prevent it&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;One important relationship:&lt;/p&gt;

&lt;p&gt;XSS can often bypass CSRF protections because malicious JavaScript executing within the trusted origin can access page content and submit legitimate requests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;CSRF teaches us something important about web application security:&lt;/p&gt;

&lt;p&gt;Authentication alone does not prove that a user intentionally initiated a request.&lt;/p&gt;

&lt;p&gt;Browsers automatically manage cookies and sessions, and attackers can sometimes abuse this behavior to trigger unwanted actions.&lt;/p&gt;

&lt;p&gt;Understanding cookies, HTTP requests, browser security policies, and server-side validation is essential for identifying and preventing CSRF vulnerabilities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Don't just memorize payloads. Understand why the browser sends the request and why the server accepts it.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>security</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Understanding Host Headers: How One Server Hosts Multiple Websites and How Attackers Exploit It</title>
      <dc:creator>Everest Paudel</dc:creator>
      <pubDate>Wed, 18 Nov 2026 01:23:16 +0000</pubDate>
      <link>https://dev.to/rest/understanding-host-headers-how-one-server-hosts-multiple-websites-and-how-attackers-exploit-it-58f6</link>
      <guid>https://dev.to/rest/understanding-host-headers-how-one-server-hosts-multiple-websites-and-how-attackers-exploit-it-58f6</guid>
      <description>&lt;h1&gt;
  
  
  Understanding Host Headers: How One Server Hosts Multiple Websites and How Attackers Exploit It
&lt;/h1&gt;

&lt;p&gt;Have you ever wondered how a single VPS can host multiple websites using just one public IP address?&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;example.com&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;shop.example.com&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;admin.example.com&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All three websites could run on the same VPS.&lt;/p&gt;

&lt;p&gt;So, how does the server know which application a visitor wants to access?&lt;/p&gt;

&lt;p&gt;The answer is the &lt;strong&gt;HTTP Host header&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Understanding this concept is also important when learning about Host Header Injection, one of the vulnerabilities encountered during web application security testing.&lt;/p&gt;

&lt;p&gt;Let's break it down.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. What Is the HTTP Host Header?
&lt;/h2&gt;

&lt;p&gt;Whenever a browser sends an HTTP request, it includes information about the requested hostname.&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="no"&gt;GET&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt;
&lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;
&lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Agent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Mozilla&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;5.0&lt;/span&gt;
&lt;span class="nc"&gt;Accept&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;html&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important part 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="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Host header tells the web server which hostname the client wants to access.&lt;/p&gt;

&lt;p&gt;But why do we need it?&lt;/p&gt;

&lt;p&gt;Because multiple domains can point to the same IP address.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. How Can One VPS Host Multiple Websites?
&lt;/h2&gt;

&lt;p&gt;Imagine we have one VPS with the following public IP:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;192.168.1.100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We configure two domains:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Domain&lt;/th&gt;
&lt;th&gt;IP Address&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;example.com&lt;/td&gt;
&lt;td&gt;192.168.1.100&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;shop.com&lt;/td&gt;
&lt;td&gt;192.168.1.100&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Both domains point to the same server.&lt;/p&gt;

&lt;p&gt;Inside the VPS, we have two applications:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Application 1: Go backend running on port &lt;code&gt;3000&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Application 2: Node.js backend running on port &lt;code&gt;4000&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both applications run simultaneously.&lt;/p&gt;

&lt;p&gt;But how do incoming requests reach the correct application?&lt;/p&gt;

&lt;p&gt;This is where Apache or Nginx comes in.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Apache and Nginx: The Receptionist
&lt;/h2&gt;

&lt;p&gt;Think of Apache or Nginx as a receptionist in a building.&lt;/p&gt;

&lt;p&gt;The building has multiple offices, and the receptionist directs visitors to the correct office.&lt;/p&gt;

&lt;p&gt;Similarly, Apache and Nginx receive incoming HTTP requests and select the appropriate website configuration.&lt;/p&gt;

&lt;p&gt;This is called &lt;strong&gt;name-based virtual hosting&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Apache Configuration
&lt;/h3&gt;

&lt;p&gt;Apache uses VirtualHost configurations to handle multiple domains.&lt;/p&gt;

&lt;p&gt;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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;VirtualHost&lt;/span&gt; &lt;span class="o"&gt;*:&lt;/span&gt;&lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nc"&gt;ServerName&lt;/span&gt; &lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;

    &lt;span class="nc"&gt;ProxyPass&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//127.0.0.1:3000/&lt;/span&gt;
    &lt;span class="nc"&gt;ProxyPassReverse&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//127.0.0.1:3000/&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;VirtualHost&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;VirtualHost&lt;/span&gt; &lt;span class="o"&gt;*:&lt;/span&gt;&lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nc"&gt;ServerName&lt;/span&gt; &lt;span class="n"&gt;shop&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;

    &lt;span class="nc"&gt;ProxyPass&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//127.0.0.1:4000/&lt;/span&gt;
    &lt;span class="nc"&gt;ProxyPassReverse&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//127.0.0.1:4000/&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;VirtualHost&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What happens?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Apache receives an HTTP request.&lt;/li&gt;
&lt;li&gt;It checks the requested hostname.&lt;/li&gt;
&lt;li&gt;It matches the hostname against &lt;code&gt;ServerName&lt;/code&gt; and &lt;code&gt;ServerAlias&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;It selects the appropriate VirtualHost.&lt;/li&gt;
&lt;li&gt;It forwards the request to the configured backend application.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Host header&lt;/th&gt;
&lt;th&gt;Backend&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;example.com&lt;/td&gt;
&lt;td&gt;127.0.0.1:3000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;shop.com&lt;/td&gt;
&lt;td&gt;127.0.0.1:4000&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Nginx Configuration
&lt;/h3&gt;

&lt;p&gt;Nginx achieves something similar using the &lt;code&gt;server&lt;/code&gt; and &lt;code&gt;server_name&lt;/code&gt; directives.&lt;/p&gt;

&lt;p&gt;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="n"&gt;server&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;listen&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;server_name&lt;/span&gt; &lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;location&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;proxy_pass&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//127.0.0.1:3000;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;server&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;listen&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;server_name&lt;/span&gt; &lt;span class="n"&gt;shop&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;location&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;proxy_pass&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//127.0.0.1:4000;&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;Nginx receives the request, checks the hostname, and selects the matching server block.&lt;/p&gt;

&lt;p&gt;Both Apache and Nginx can act as reverse proxies.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. What Happens When an Attacker Changes the Host Header?
&lt;/h2&gt;

&lt;p&gt;Now comes the interesting part from a web security perspective.&lt;/p&gt;

&lt;p&gt;Normally, a browser sends:&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="no"&gt;GET&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt;
&lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But an attacker can modify this header using tools such as Burp Suite.&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="no"&gt;GET&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt;
&lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;attacker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;example&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The application or web server might handle this unexpected hostname in different ways.&lt;/p&gt;

&lt;p&gt;The important security question is:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does the application trust the Host header without validating it?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If the application uses an untrusted hostname to generate URLs, redirects, or other security-sensitive content, vulnerabilities may occur.&lt;/p&gt;

&lt;p&gt;Let's look at some examples.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Common Host Header Attacks
&lt;/h2&gt;

&lt;h3&gt;
  
  
  A. Password Reset Poisoning
&lt;/h3&gt;

&lt;p&gt;Imagine a website generates password reset links using the incoming Host header.&lt;/p&gt;

&lt;p&gt;Normally, the application generates:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://example.com/reset?token=12345
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But if an attacker can manipulate the Host header, the application might generate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://attacker.example/reset?token=12345
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If this poisoned link is sent to a victim, the victim may visit the attacker's domain with their reset token.&lt;/p&gt;

&lt;p&gt;An attacker could potentially capture the token.&lt;/p&gt;

&lt;p&gt;The root cause is trusting an unvalidated Host header when generating password reset URLs.&lt;/p&gt;

&lt;h3&gt;
  
  
  B. Web Cache Poisoning
&lt;/h3&gt;

&lt;p&gt;Some applications generate HTML content using the Host header.&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 html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"https://example.com/app.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the application uses an attacker-controlled hostname instead, it might generate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"https://attacker.example/app.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If a shared cache stores and serves this manipulated response to other users, it could result in cache poisoning.&lt;/p&gt;

&lt;h3&gt;
  
  
  C. Virtual Host Discovery
&lt;/h3&gt;

&lt;p&gt;A single server may host multiple applications.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;www.example.com&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;admin.example.com&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;dev.example.com&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;An attacker may investigate whether different Host values cause the server to return different applications.&lt;/p&gt;

&lt;p&gt;However, discovering an internal virtual host does not automatically mean authentication has been bypassed.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. What About X-Forwarded-Host?
&lt;/h2&gt;

&lt;p&gt;There is another HTTP header worth understanding:&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="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Forwarded&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;attacker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;example&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Consider this architecture:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Browser
   |
   v
Nginx Reverse Proxy
   |
   v
Backend Application
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A reverse proxy can pass hostname information to the backend using forwarded headers.&lt;/p&gt;

&lt;p&gt;Some applications use &lt;code&gt;X-Forwarded-Host&lt;/code&gt; when generating absolute URLs.&lt;/p&gt;

&lt;p&gt;If the proxy blindly forwards attacker-controlled values and the application trusts them, this can introduce security issues.&lt;/p&gt;

&lt;p&gt;Therefore, validating forwarded headers is just as important as validating the original Host header.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. How to Test Host Header Injection Using Burp Suite
&lt;/h2&gt;

&lt;p&gt;When testing an authorized application, start with a normal request.&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="no"&gt;GET&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt;
&lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;example&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then modify the Host header:&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="no"&gt;GET&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt;
&lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;attacker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;example&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Observe:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Does the response change?&lt;/li&gt;
&lt;li&gt;Does the application redirect to another domain?&lt;/li&gt;
&lt;li&gt;Does the application generate URLs using the supplied hostname?&lt;/li&gt;
&lt;li&gt;Does a password reset email contain a manipulated URL?&lt;/li&gt;
&lt;li&gt;Does the response get stored and reused by a shared cache?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also investigate forwarded headers:&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="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Forwarded&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;attacker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;example&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remember: changing a header and observing a different response is not sufficient to prove a vulnerability. You need to demonstrate a meaningful security impact.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. How Can Developers Prevent These Attacks?
&lt;/h2&gt;

&lt;p&gt;Some important defensive practices include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Maintain an explicit allowlist of valid hostnames.&lt;/li&gt;
&lt;li&gt;Use a configured canonical domain when generating password reset links.&lt;/li&gt;
&lt;li&gt;Configure Apache and Nginx with intentional default virtual hosts.&lt;/li&gt;
&lt;li&gt;Do not blindly trust &lt;code&gt;X-Forwarded-Host&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Configure reverse proxies to overwrite or sanitize forwarded headers.&lt;/li&gt;
&lt;li&gt;Validate redirects and URLs generated by the application.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The HTTP Host header might look like a simple part of an HTTP request, but it plays an important role in how modern web applications and web servers work.&lt;/p&gt;

&lt;p&gt;Understanding how one VPS can host multiple applications, how Apache and Nginx select virtual hosts, and how applications consume hostname information provides a strong foundation for learning Host Header Attacks.&lt;/p&gt;

&lt;p&gt;For anyone learning web application security, understanding the underlying architecture is just as important as learning payloads.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep learning, keep testing, and understand the logic behind every vulnerability.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>backend</category>
      <category>cybersecurity</category>
      <category>networking</category>
      <category>security</category>
    </item>
  </channel>
</rss>
