Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Potential XSS Vulnerability in Ruby on Rails Applications
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Aaron Patterson  
View profile  
 More options Jun 7 2011, 7:41 pm
From: Aaron Patterson <aa...@tenderlovemaking.com>
Date: Tue, 7 Jun 2011 16:41:48 -0700
Local: Tues, Jun 7 2011 7:41 pm
Subject: Potential XSS Vulnerability in Ruby on Rails Applications

# Potential XSS Vulnerability in Ruby on Rails Applications

The XSS prevention support in recent versions Ruby on Rails allows some string operations which, when combined with user supplied data, may leave an 'unsafe string' incorrectly considered safe.  It is unlikely that applications call these methods, however we are shipping new versions today which prevent their use to ensure they're not called unintentionally.

## How the XSS Prevention Works

When strings are rendered to the client, if the string is not marked as "html safe", the string will be automatically escaped and marked as "html safe". Some helper methods automatically return strings already marked as safe.

For example:

    <%= link_to('hello world', @user) %>

The `link_to` method will return a string marked as html safe.  Since `link_to` returns an "html safe" string (also known as a safe buffer), the text will be output directly, meaning the user sees a link tag rather than escaped HTML.

## The Problem

Safe buffers are allowed to be mutated in place via methods like `sub!`.  These methods can add unsafe strings to a safe buffer, and the safe buffer will continue to be marked safe.

An example problem would be something like this:

    <%= link_to('hello world', @user).sub!(/hello/, params[:xss])  %>

In the above example, an untrusted string (`params[:xss]`) is added to the safe buffer returned by `link_to`, and the untrusted content is successfully sent to the client without being escaped.  To prevent this from happening `sub!` and other similar methods will now raise an exception when they are called on a safe buffer.

In addition to the in-place versions, some of the versions of these methods which return a copy of the string will incorrectly mark strings as safe.  For example:

    <%= link_to('hello world', @user).sub(/hello/, params[:xss]) %>

The new versions will now ensure that *all* strings returned by these methods on safe buffers are marked unsafe.
## Affected versions

This problem affects all versions of rails: 3.1.0.rc1, 3.0.7, and 2.3.11.

## The Solution

Any methods that mutate the safe buffer without escaping input will now raise
an exception.

If you need to modify a safe buffer, cast it to a Ruby string first by calling
the `to_str` method:

    <%= link_to('hello world', @user).to_str.sub!(/hello/, params[:xss]) %>

## Upgrading

This problem is fixed in Rails 3.1.0.rc2, 3.0.8, and 2.3.12 (with rails_xss) (which will be
released in the next hour).  If for some reason you cannot upgrade your Rails
installation, please apply these patches (also find them attached):

  * [For 3.1.0.rc1](https://gist.github.com/89d6266cc7875614c5a5)
  * [For 3.0.7](https://gist.github.com/b2ceb626fc2bcdfe497f)
  * [For 2.3.11, specifically the rails_xss plugin](https://gist.github.com/392235903426322e0414)

## Thanks

Thanks to Bruno Michel of LinuxFr.org and Brett Valantine who each independently reported the issue to us.

--
Aaron Patterson
http://tenderlovemaking.com/

  3.1.diff
2K Download

  3.0.diff
10K Download

  rails_xss.diff
1K Download

  application_pgp-signature_part
< 1K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »