Skip to content
Open redirect Write-up Intermediate

Bypassing Safe-Redirect in Rails 7.0

Rails 7.0's safe-redirect check tried to block off-site redirects by requiring either a matching host or a nil host with a leading slash. Because Ruby's URI parser treats a triple-slash URL as having a nil host while browsers treat it as an absolute URL, an attacker could craft a redirect that passed validation but sent the victim to another domain.

Ryan Follow

Published on bountyplz.xyz

## Bypassing Safe-Redirect in Rails 7.0

Ryan, on bountyplz.xyz

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the validation relied on Ruby's URI parser, which disagrees with the WHATWG URL standard browsers follow about how many slashes after a scheme are allowed, so a URL with three slashes had a nil host in Ruby but resolved to an external host in the browser.

Impact

An attacker could bypass the safe-redirect protection and send users to an arbitrary external site, enabling open-redirect phishing, though the text does not describe any further chained impact.

What the attacker needed

A Rails 7.0 app using redirect_to; attacker controls the redirect target; victim clicks a crafted link

The fix

It was fixed in Rails.

How it was found

  1. Set up a Rails route that calls redirect_to with a user-supplied parameter.
  2. Confirm a normal relative path redirects as expected.
  3. Confirm an absolute URL to another domain raises UnsafeRedirectError.
  4. Supply a URL with three leading slashes so Ruby sees a nil host but the browser resolves it to an external domain.
  5. Observe the redirect fires to the external host without raising the exception.

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 write-up has not been written yet. The Original tab links to the source.

A redirect is when a website sends your browser to another address. Rails added a safety check so a site could only redirect you to pages on the same site, to stop attackers sending you to malicious lookalike sites. The check asked Ruby (the programming language) whether the address was local, but Ruby and browsers read some addresses differently, so a crafted address looked local to Ruby and remote to your browser.

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 by Ryan

View all

2 more disclosed reports, best first.

More from Ruby on Rails

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.