Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

XSS in 2.3.8 is still opt-in

#4755

My understanding is that the XSS changes that wil be in Rails 3 should still be opt-in only for Rails 2.3, as mentioned here

We’re sorry, all: HTML-safety is meant to be opt-in!

So to test this, I've installed Rails 2.3.8:

$ rvm use ree-1.8.7

info: Using ree 1.8.7 2010.01
$ rvm gemset create rails238

info: Gemset 'rails238' created.
$ rvm gemset use rails238

$ gem install rails
Successfully installed activesupport-2.3.8
Successfully installed activerecord-2.3.8
Successfully installed rack-1.1.0
Successfully installed actionpack-2.3.8
Successfully installed actionmailer-2.3.8
Successfully installed activeresource-2.3.8
Successfully installed rails-2.3.8
7 gems installed

$ gem install sqlite3-ruby
Building native extensions.  This could take a while...
Successfully installed sqlite3-ruby-1.2.5
1 gem installed

I generated an app and then I made this ERB template:

<html>
  <head>
    <%= stylesheet_link_tag("foo") + "<title>Foo</title>"  %>
  </head>
  <body>
    <%= link_to("#") + "<p>Foo</p>" %>
    <%= "<br/>" %>
  </body>
</html>

When it gets rendered as a view for an action, it produces this:

<html>
  <head>
    <link href="/stylesheets/foo.css" media="screen" rel="stylesheet" type="text/css" />&lt;title&gt;Foo&lt;/title&gt;
  </head>
  <body>
    <a href="/main">#</a>&lt;p&gt;Foo&lt;/p&gt;

    <br/>
  </body>
</html>

The <br/> is not escaped, so that's working as expected, but concatenating a string on to the result of a helper is being escaped without calling h, so that is not as expected. Is this a bug or has the behavior in 2.3.8 been changed intentionally?

Reported by Paul Barry · June 2nd, 2010 @ 10:51 PM

State: resolved
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Paul Barry
    Paul Barry

    Hmmm....looks like this may have been fixed in the latest stable/2.3.9. Here's the commit:

    http://github.com/rails/rails/commit/a815f0c5a3a873aefca76f459ce05d...

    I'll take a look at this tonight

    June 2nd, 2010 @ 10:53 PM

  2. Ryan Bigg
    Ryan Bigg
    • State changed from new to open

    I was unable to duplicate this on 2.3.8 or 2-3-stable: See the master and 2-3-stable branches for http://github.com/radar/rails-test-app

    June 2nd, 2010 @ 11:52 PM

  3. Paul Barry
    Paul Barry

    @Ryan Bigg

    I can reproduce this in your app as well with rails 2.3.8. Not sure why you can't.

    June 3rd, 2010 @ 12:30 AM

  4. Ryan Bigg
    Ryan Bigg

    I can only reproduce this when I install the rails_xss plugin.

    June 3rd, 2010 @ 12:34 AM

  5. Paul Barry
    Paul Barry

    I can confirm this is fixed in 2.3.9/2-3-stable

    June 3rd, 2010 @ 12:55 AM

  6. Ryan Bigg
    Ryan Bigg
    • State changed from open to resolved

    Great, thanks Paul!

    June 3rd, 2010 @ 01:04 AM