Skip to content
Misconfiguration Disclosed report Intermediate

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.

mrtc0 Follow

Originally disclosed on HackerOne

Informational View original
  • 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

Bash
$ ruby --version
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
Ruby
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.

Ruby
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.

The original report as published on HackerOne, by mrtc0. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

  1. Run the Ruby snippet that builds a URI from a URL containing '#' and '@'.
  2. Read the parsed hostname and observe it includes the text after the '#'.
  3. 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.

More from Ruby

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Security misconfiguration

The lesson behind this report.

Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.