Skip to content
XSS Disclosed report Intermediate CVE-2023-28362

Incorrect handling of certain characters passed to the redirection functionality in Rails can lead to a single-click XSS vulnerability.

Rails' redirect_to function mishandles certain control characters in the URL, causing the Location header to be dropped. An attacker can then inject a javascript: URI into the fallback HTML link, leading to XSS if the victim clicks it.

meowday Follow

Originally disclosed on HackerOne

Medium 4.3 View original
  • Triaged in 13 days
  • Fixed in 2 months
  • Disclosed after 3 months

Overview

Incorrect handling of certain characters passed to the redirection functionality in Rails can lead to a single-click XSS vulnerability across web applications. This has been tested on the latest version of Rails as of today (7.0.4.3).

Description

Downstream parsing of values sent to the redirect_to function will cause the 'location' header to be removed from the response when certain characters are used in the URL. For example, if the \b (%08) (backspace) character is used in the URL.

When the location header is missing from the response, it is possible to control the href attribute in the HTML response that would normally be briefly shown prior to the redirect, therefore by using a javascript URI, it is possible to prevent the redirect and serve an XSS payload.

During the assessment, the %01-%08, %0b, %0c, %0e-%1f characters were found to be vulnerable, however there may be others.

We believe this may be attributed to the rack linters attempting to conform to rfc7230 (https://github.com/rack/rack/blob/f5666bc8cb13b8d731ea0222fbd3ada670f2cd55/lib/rack/lint.rb#L671)

Proof of Concept

A simple instance is as follows:

app/controllers/application_controller.rb

Ruby
class ApplicationController < ActionController::Base
  def vuln
    redirect_to params[:redirect_url], allow_other_host: true
  end
end

config/routes.rb

Ruby
Rails.application.routes.draw do
  get "/vuln" => "application#vuln"
end

And then when we retrieve: http://localhost:3000/vuln?redirect_url=javascript:alert()%08

The response will be as follows:

HTTP/1.1 302 Found
Cache-Control: no-store
Date: Thu, 06 Apr 2023 05:16:21 GMT
Connection: close
Content-Length: 100

<html><body>You are being <a href="javascript:alert(document.cookie) ">redirected</a>.</body></html>

As the page does not redirect, if the user clicks on the link (expecting the redirect for example), the payload will be triggered:

image.png
image.png From the original on HackerOne

Impact

User controlled values being sent to the redirect_to function may cause an unwanted XSS vulnerability. This was discovered in the wild and proven to be a legitimate security concern.

The original report as published on HackerOne, by meowday. 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 Rack lint middleware strips the Location header when it contains certain control characters, leaving the fallback HTML link controllable by the attacker.

Impact

An attacker could run JavaScript in the victim's browser if the victim clicks the fallback link.

What the attacker needed

Rails app uses redirect_to with user input; allow_other_host: true is set; victim clicks the fallback link

How it was found

  1. Set up a Rails controller action that calls redirect_to with a user-supplied parameter and allows other hosts.
  2. Add a route to that action.
  3. Request the endpoint with a redirect_url parameter containing a javascript: URI followed by a control character such as %08.
  4. Observe that the response lacks a Location header and contains an HTML link with the javascript: URI.
  5. Click the link to trigger the JavaScript payload.

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.

When a web app redirects you to another page, it sends a special header telling the browser where to go. If that header is missing, the app shows a clickable link instead. This report shows that by adding a hidden control character to the URL, an attacker can make the app show a link that runs malicious JavaScript when clicked.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

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.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.