HostAuthorization middleware does not suitably sanitize the Host / X-Forwarded-For header allowing redirection.
The HostAuthorization middleware's handling of leading-dot host entries builds a regular expression that is too permissive, so a crafted Host header containing a fragment passes validation. An attacker could then cause the application to redirect a user to a hostile site.
- Triaged in 21 hours
- Fixed in 2 months
- Paid in 2 months
- Disclosed after 2 months
When a site is configured to use the .tkte.ch (leading dot) short form for domain name, ex:
config.hosts << '.tkte.ch'
it is then sanitized in sanitize_string, where it is turned into a regex:
def sanitize_string(host)
if host.start_with?(".")
/\A(.+\.)?#{Regexp.escape(host[1..-1])}\z/
else
host
end
end
The regex it is wrapped in is too permissive. It allows for things like:
❯ curl -i -H "Host: google.com#sub.tkte.ch" http://localhost:3001/
HTTP/1.1 302 Found
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
Referrer-Policy: strict-origin-when-cross-origin
Location: http://google.com#sub.tkte.ch/
Content-Type: text/html; charset=utf-8
Cache-Control: no-cache
X-Request-Id: 3b1702ac-a58f-44bf-af8a-a2933a9946fd
X-Runtime: 0.004726
Transfer-Encoding: chunked
<html><body>You are being <a href="http://google.com#sub.tkte.ch/">redirected</a>.</body></html>
Where the controller is simply:
class RedirectController < ApplicationController
def main
redirect_to action: 'main'
end
end
The host header poisoning was reported to us by a 3rd party researcher, and tracking it down led to this.
Impact
A user can be redirected to a hostile site.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
A user can be redirected to a hostile site.
What the attacker needed
App uses leading-dot host entry; attacker can set the Host header
How it was found
- Configure the application to allow a leading-dot domain entry in its hosts list.
- Send a request with a crafted Host header that includes a fragment and the allowed domain.
- Observe the application respond with a redirect to the attacker-chosen location.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A web app can be told which domain names it should answer for. When a domain is written with a leading dot, the app turns it into a pattern to match subdomains, but that pattern also accepts extra characters. By sending a specially crafted Host header, someone can make the app redirect visitors to a site they control.
What is Open redirect?
A trusted site forwards users to any address an attacker picks; rarely paid alone, often the missing link in a chain.