Host Header Injection
The report claims a Host Header Injection vulnerability on the main domain, where an attacker can manipulate the Host header to cause unexpected application behaviour. The impact section lists possible attacks such as web cache poisoning, password reset poisoning, XSS, access to internal hosts, and phishing, but no actual exploitation is demonstrated.
Originally disclosed on HackerOne
- Triaged in 27 days
- Fixed in 58 days
- Disclosed after 3 months
Summary:
Hello Team, While performing security testing on your Main Domain, I found a Host Header Injection Vulnerability.
Vulnerability Description: An attacker can manipulate the Host header as seen by the web application and cause the application to behave in unexpected ways. Very often multiple websites are hosted on the same IP address. This is where the Host Header comes in. This header specifies which website should process the HTTP request. The web server uses the value of this header to dispatch the request to the specified website. Each website hosted on the same IP address is called a virtual host. And It's possible to send requests with arbitrary Host Headers to the first virtual host.
Browsers Verified In:
- Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)
Steps To Reproduce:
If possible, the application should avoid incorporating user-controllable data into redirection targets. In many cases, this behavior can be avoided in two ways:
- Remove the redirection function from the application, and replace links to it with direct links to the relevant target URLs. 2.Maintain a server-side list of all URLs that are permitted for redirection. Instead of passing the target URL as a parameter to the redirector, pass an index into this list.
Supporting Material/References:
Vulnerable URL: http://kartpay.com
- [attachment / reference]
Video POC Attached below.
Impact
Tampering of Host header can lead to the following attacks:
-
Web Cache Poisoning-Manipulating caching systems into storing a page generated with a malicious Host and serving it to others.
-
Password Reset Poisoning-Exploiting password reset emails and tricking them to deliver poisoned content directly to the target.
-
Cross Site Scripting - XSS can be performed, if the value of Host header is used for writing links without HTML-encoding. For example Joomla used to write Host header to every page without HTML Encoding like this: <link href=”http://_SERVER['HOST']”> which led to cross site scripting.
-
Access to internal hosts-To access internal hosts.
5.) It can also lead to Phishing Attacks.
Attachments
Context
Kartpay runs its main site at kartpay.com, and the scope for this report was *.kartpay.com. The researcher, streetdragon, reported a Host Header Injection issue against the main domain; the report is rated medium severity. The report was disclosed on 10 May 2021 through HackerOne.
The Host header is the part of an HTTP request that tells the web server which site should handle it. When several virtual hosts share one IP address, the server uses the header value to dispatch the request to the right site. If the application trusts that value and uses it in a redirect target, an attacker can influence where the application sends users.
Setup
The report does not describe any account, role or special precondition. The only tooling detail is the proof-of-concept video, which was recorded in Burp Suite Professional v2020.2.1. The researcher lists one browser as verified:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)
Finding it
While testing the main domain, the researcher found a Host Header Injection issue. The report frames the issue in general terms. The report frames the issue in general terms, explaining that an attacker can manipulate the Host header as seen by the web application and cause it to behave in unexpected ways, and that requests with arbitrary Host headers can be sent to the first virtual host on a shared IP address.
Exploitation
The report gives the vulnerable URL as:
http://kartpay.com
It does not include the individual request and response pairs. The proof of concept is the attached video, which shows the testing in Burp Suite Professional v2020.2.1.
Step 1: Identify the redirect behaviour
The report does not describe the exact request or response. Because the header is fully client-controlled, the destination of the redirect can be influenced by the attacker.
Step 2: Send a request with a manipulated Host header
The report does not reproduce the exact request. The technique is to send a request to the application with a Host header value the attacker chooses, and observe whether the application reflects that value in the redirect it returns.
Step 3: Confirm the effect
The video is the attached proof of concept.
Root cause
The application incorporates user-controllable data, here the Host header, into redirection targets. The report's remediation guidance states the general principle directly: if possible, the application should avoid incorporating user-controllable data into redirection targets.
Impact
The report lists the following consequences of Host header tampering:
- Web Cache Poisoning: manipulating caching systems into storing a page generated with a malicious Host and serving it to others.
- Password Reset Poisoning: exploiting password reset emails and tricking them to deliver poisoned content directly to the target.
- Cross Site Scripting: XSS can be performed if the value of the Host header is used for writing links without HTML-encoding. The report gives Joomla as an example, which used to write the Host header to every page without HTML encoding like this:
<link href="http://_SERVER['HOST']">
- Access to internal hosts.
- Phishing attacks.
These are the general consequences of the class. The report does not demonstrate cache poisoning, password reset poisoning, XSS or internal host access on Kartpay itself.
Fix
The report recommends two approaches:
- Remove the redirection function from the application, and replace links to it with direct links to the relevant target URLs.
- Maintain a server-side list of all URLs that are permitted for redirection. Instead of passing the target URL as a parameter to the redirector, pass an index into this list.
Variants to test
- Send a request with a Host header pointing at a domain you control and check whether the response redirects there. A positive result is a
Locationheader containing your host. - Try the same against endpoints that issue redirects after login, logout or password reset, and check whether the redirect target follows the Host header.
- Check whether the Host value is written into page links without HTML encoding, as in the Joomla example. A positive result is an unencoded host reflected into an
hrefattribute. - Check whether responses influenced by the Host header are cached and served to other users. A positive result is a cached page containing your host being returned to a different client.
Hunting notes
This class of bug hides wherever an application builds absolute URLs or redirect targets from the incoming request rather than from configuration. During recon, look for redirect endpoints and for any response that echoes the host you sent. The report's evidence is a Burp Suite recording attached as a video.; the impact section then explains what that behaviour can lead to in the general case.
What happened, in plain words
Kartpay runs its main website at kartpay.com. A security researcher called streetdragon was testing that site and found a problem with how it handles one small piece of every web request: the Host header. The site was handling that value in a way an attacker could influence. Because the Host header comes from whoever sends the request, an attacker can put their own value in it and influence where the site sends people. The report was rated medium severity and disclosed on 10 May 2021 through HackerOne.
This article walks through the report from the beginning, explaining each idea as it appears. You only need to know how to use a browser and a computer to follow it.
Context
Every time your browser loads a page, it sends a request to a server. That request contains a few lines of text, and one of them is the Host header. It says which website the request is meant for, for example kartpay.com.
Why is that needed? Because one physical server, with one IP address (the numeric address of a machine on the internet), can host many different websites at once. Think of an apartment building: one street address, many flats. The Host header is like the flat number on an envelope. The server reads it and passes the request to the right website. Each website sharing that address is called a virtual host.
The problem in this report is that the application trusted the flat number written on the envelope.
The scope of the report was *.kartpay.com, which means any subdomain of kartpay.com was fair game for testing. The finding itself was against the main domain.
Setup
There is no special account, role or precondition described. The only tooling detail is the proof-of-concept video, which was recorded in Burp Suite Professional v2020.2.1. Burp Suite is a program that sits between your browser and a website so you can look at, and change, the requests and responses as they pass. The researcher lists one browser as verified:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)
This line is a user agent string. Browsers send it with every request to say what kind of browser and operating system they are. Here it identifies a browser on 64-bit Windows. The report gives no version number beyond what is in the string.
Finding it
While testing the main domain, the researcher found a Host Header Injection issue.
The report explains the idea in general terms. An attacker can manipulate the Host header as seen by the web application and cause the application to behave in unexpected ways. It also notes that requests with arbitrary Host headers can be sent to the first virtual host on a shared IP address. In other words, if you send a request with a made-up Host value to a server that hosts several sites, the server may hand it to the first site configured on that address, and that site may then use your made-up value.
Exploitation
The report gives the vulnerable URL as:
http://kartpay.com
This is simply the address of the main site, using http rather than https. It is the starting point for the test, not a special path or parameter. The report does not include the individual request and response pairs. The proof of concept is the attached video, which shows the testing in Burp Suite Professional v2020.2.1.
The video is the evidence for the behaviour described below.
Step 1: Identify the redirect behaviour
The report does not describe the exact request or response. A redirect is a server response that says "the thing you asked for is over there" and gives an address. Your browser then automatically goes to that address. Because the Host header is fully controlled by whoever sends the request, the destination of the redirect can be influenced by the attacker. This step matters because it establishes that the site builds an address from incoming data rather than from a fixed setting.
Step 2: Send a request with a manipulated Host header
The report does not reproduce the exact request. The technique is to send a request to the application with a Host header value the attacker chooses, and watch whether the application copies that value into the redirect it returns. You would do this in a tool like Burp Suite by intercepting a normal request and editing the Host line before forwarding it.
Step 3: Confirm the effect
The video is the attached proof of concept. In plain terms: if you tell the site your name is example.com, and the site replies "go to example.com", the site believed you instead of checking.
Root cause
The application incorporates user-controllable data, here the Host header, into redirection targets. The report's remediation guidance states the general principle directly: if possible, the application should avoid incorporating user-controllable data into redirection targets. The report does not describe the server configuration or code that produced the behaviour, so the precise implementation mistake is not stated.
Impact
The report lists the following consequences of Host header tampering:
- Web Cache Poisoning: manipulating caching systems into storing a page generated with a malicious Host and serving it to others. A cache is a copy of a page kept so it can be served faster next time; if the bad copy is stored, other visitors can receive it.
- Password Reset Poisoning: exploiting password reset emails and tricking them to deliver poisoned content directly to the target. If a reset link is built from the Host header, an attacker can make the link point at their own site.
- Cross Site Scripting: XSS can be performed if the value of the Host header is used for writing links without HTML-encoding. XSS means getting a site to run code an attacker supplied, usually JavaScript, in another visitor's browser. The report gives Joomla as an example, which used to write the Host header to every page without HTML encoding like this:
<link href="http://_SERVER['HOST']">
This line is a link tag in a web page. _SERVER['HOST'] is a placeholder for the Host value the server received. If that value is written into the page without being encoded, meaning special characters are not converted into harmless forms, an attacker can put characters that change the meaning of the HTML and inject their own code.
- Access to internal hosts. Internal hosts are machines inside an organisation's network that are not meant to be reachable from the internet.
- Phishing attacks. Phishing is tricking someone into visiting a fake site or handing over details, often by making a link look trustworthy.
These are the general consequences of this class of bug. The report does not demonstrate cache poisoning, password reset poisoning, XSS or internal host access on Kartpay itself.
Fix
The report recommends two approaches:
- Remove the redirection function from the application, and replace links to it with direct links to the relevant target URLs. In other words, if the site does not need to bounce users through a redirect, do not offer one.
- Maintain a server-side list of all URLs that are permitted for redirection. Instead of passing the target URL as a parameter to the redirector, pass an index into this list. An index is just a number: instead of saying "go to this address", the site says "go to entry number 3 on my approved list". The user cannot change the list, so they cannot choose an unapproved destination.
Variants to test
These are the same ideas applied in slightly different places, useful if you want to look for this kind of bug yourself:
- Send a request with a Host header pointing at a domain you control and check whether the response redirects there. A positive result is a
Locationheader containing your host. TheLocationheader is the line in a redirect response that carries the destination address. - Try the same against endpoints that issue redirects after login, logout or password reset, and check whether the redirect target follows the Host header. An endpoint is a specific address on a site that does a particular job, such as handling a login.
- Check whether the Host value is written into page links without HTML encoding, as in the Joomla example. A positive result is an unencoded host reflected into an
hrefattribute.hrefis the part of a link that holds its destination. - Check whether responses influenced by the Host header are cached and served to other users. A positive result is a cached page containing your host being returned to a different client.
Hunting notes
This class of bug hides wherever an application builds absolute URLs or redirect targets from the incoming request rather than from configuration. An absolute URL is a full address including the scheme and host, such as http://kartpay.com/page, as opposed to a relative one like /page. During recon, meaning the early stage of looking around a target, look for redirect endpoints and for any response that echoes the host you sent. The report's evidence is a Burp Suite recording attached as a video.; the impact section then explains what that behaviour can lead to in the general case.
Glossary
- Host header: the line in an HTTP request that names the website the request is for, used by a server that hosts several sites on one address.
- HTTP request: the message a browser sends to a server to ask for a page or to submit data.
- HTTP response: the message a server sends back, containing the page or an instruction such as a redirect.
- IP address: the numeric address of a machine on a network.
- Virtual host: one of several websites hosted on the same IP address.
- Host Header Injection: a bug where an application trusts the Host header and uses it in a way the attacker can influence, such as building a redirect.
- Redirect: a response that tells the browser to go to a different address instead.
- Redirection target: the address a redirect points to.
- Location header: the part of a redirect response that carries the destination address.
- Endpoint: a specific address on a site that performs a particular function.
- Parameter: a named value passed in a request, for example in the URL or the body.
- User-controllable data: any value in a request that the person sending it can set.
- Burp Suite Professional: a tool that intercepts and lets you inspect and modify traffic between a browser and a website.
- User agent string: a line browsers send to identify the browser and operating system.
- Scope: the set of targets a tester is allowed to test.
- Web Cache Poisoning: getting a cache to store a harmful version of a page and serve it to other visitors.
- Cache: a stored copy of a page kept to serve it faster.
- Password Reset Poisoning: abusing a password reset flow, often by influencing the link in the reset email, so it points somewhere harmful.
- Cross Site Scripting (XSS): getting a site to run attacker-supplied code, usually JavaScript, in another visitor's browser.
- HTML encoding: converting special characters into harmless forms so they cannot change the structure of a page.
href: the attribute of a link that holds its destination address.- Phishing: tricking someone into visiting a fake site or giving away details, often through a link that looks genuine.
- Internal hosts: machines inside an organisation's network that are not meant to be reachable from the internet.
- Absolute URL: a full address including scheme and host, such as
http://kartpay.com/page. - Recon: the early stage of exploring a target to find what it exposes.
- Severity: a rating of how serious a finding is, here medium.