Skip to content
Open redirect Disclosed report Intermediate

Attacker can smuggle a malicious domain in a URI object.

Ruby's URI parser accepts a URI with four leading slashes and returns a nil host, but converting it back to a string yields a well-formed URL pointing to an attacker-controlled domain. An attacker could use this to bypass host validation and create open redirects for phishing.

djspinmonkey Follow

Originally disclosed on HackerOne

  • Triaged in 2.4 years
  • Disclosed after 6.4 years

Simple example:

user_provided_redirect_uri = "http:////malware.com/real/path"
evil_uri = URI.parse(user_provided_redirect_uri)
evil_uri.host          # => nil
evil_uri.to_s          # => "http://malware.com/real/path"

In many common URI-validation scenarios, the target system will likely parse a user provided URI, and then check the host against some internal validation criteria, eg, that it's a host owned by that system. Seeing a blank hostname will often cause the system to assume that the link only contains a path, not a domain, so any validation or checking of that domain won't happen.

However, if the URI object is turned back into a string, the resulting URI contains the malicious domain, as you can see above. The actual behavior is to remove two of the leading slashes, so starting with 4 leading slashes will give you 2 leading slashes in the output, which is a well-formed (and in this case malicious) URL.

In addition, most browsers (all that I checked on) will allow multiple slashes before the domain name -- type "http:////google.com" in to your browser, and you will go to google. So, using the original string will also result in a redirection to the malicious host.

Bottom line, this bug is almost certainly the cause of a large number of open redirect vulnerabilities in Ruby based web apps. The most obvious use would be to craft malicious URIs for phishing purposes, but it could be used to potentially circumvent any host-checking logic in a URI validator.

The cause of the bug can be seen here: https://github.com/ruby/ruby/blob/trunk/lib/uri/rfc3986_parser.rb#L6 (if you can spot it in there). The real smoking gun is comment on the line above it that says the regex is modified from the RFC to allow empty host names. A little consideration will show why this causes the above behavior, and why it ends up stripping the initial two leading slashes.

The original report as published on HackerOne, by djspinmonkey. 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

The URI parser's regular expression was modified from the RFC to allow empty host names, which causes it to treat four leading slashes as a path and drop two slashes when converting back to a string.

Impact

This could be used to craft malicious URIs for phishing and to circumvent host-checking logic in URI validators, leading to open redirect vulnerabilities in Ruby-based web apps.

What the attacker needed

User-provided URI is parsed and host-checked; application converts URI back to string

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 URI is a web address. Ruby's URI library can be tricked by extra slashes at the start: it thinks there is no domain, so security checks that look for a domain see nothing to block. But when the address is turned back into text, the extra slashes disappear and the malicious domain appears, so the user is sent to the attacker's site.

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.

More from Ruby

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Open redirect

The lesson behind this report.

A trusted site forwards users to any address an attacker picks; rarely paid alone, often the missing link in a chain.