Invalid URL parsing '#'
Ruby's URI parser mishandled a URL containing a '#' followed by an '@' symbol, treating the text after the fragment marker as part of the hostname. An attacker could craft such a URL so that a program connects to an unintended host.
- Disclosed after 10 days
URI is not correctly parsed when "#" is included in the URL.
Therefore, could instead be tricked into connecting to a different host.
PoC
$ ruby --version
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
require 'uri'
uri = URI("http://www.example.com#@test.evil.com/test")
# => #<URI::HTTP http://www.example.com.evil.com/test>
p uri.hostname
# => "www.example.com.evil.com"
But, does not happen if use single quotes, like this.
uri = URI.parse('http://www.example.com#@evil.com/test')
p uri.hostname
# => www.example.com
However, in RFC 3986 it is defined that after "#" it is interpreted as a fragment. Therefore, this behavior is contrary to the user's intuition and easy to overlook.
Impact
The user may connect to an unintended host.
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
Root cause
Likely the URI parser did not treat '#' as the start of the fragment before processing the '@' userinfo separator, so the fragment text leaked into the hostname.
Impact
A user or program relying on the parsed hostname could be directed to connect to an unintended host.
What the attacker needed
Ruby URI library in use; attacker-supplied URL is parsed
How it was found
- Run the Ruby snippet that builds a URI from a URL containing '#' and '@'.
- Read the parsed hostname and observe it includes the text after the '#'.
- Compare with the single-quoted variant, which parses the hostname correctly.
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 URL has a host and a fragment after '#'. Ruby's URI library got confused when '#' was followed by '@', putting the wrong text into the host name, so a user may connect to an unintended host.
What is Misconfiguration?
Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.