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.

Fix broken Rack params parser in Rails >= 2.3.6

#5873

Since this change in May that was part of the 2.3.6 release, Rails has been dependent on the Rack 1.1 gem.

Unfortunately this version of Rack does bad things to query strings containing quotes which at best leads to them being stripped out of the params hash values and at worst leads to values being silently truncated.

I first had a look at this problem a few months back and as it's not been fixed in the meantime have now had chance to work on a patch which I think uses the best approach to fixing it: monkey-patching the broken code in Rack.

I appreciate we'd normally want to steer clear of monkey-patching in favour of using the fixed version of the gem, but this isn't really an option as Rack is broken in more ways than one:

Rolling back to Rack 1.0.1 also proves problematic as other parts of Rails 2.3 have been changed to work with the 1.1 release.

So to summarise the attached patch:

  • it adds a monkey-patch for the broken parsing methods in Rack::Utils using a similar pattern to the Rack::Lint patch that had been added previously

  • it removes the Rack::Lint patch as it no longer applies to Rack 1.1.0

  • and on a completely unrelated issue it tweaks a template to prevent annoying parentheses warnings when running the tests

Reported by Rob Anderton · October 27th, 2010 @ 11:56 PM

State: new
Milestone: none
Assigned to: Michael Koziarski Michael Koziarski
Importance: Low

Activity

  1. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag cleared.
    • Importance changed from to Low

    Automatic cleanup of spam.

    November 1st, 2010 @ 05:04 PM

  2. Stephen Blackstone
    Stephen Blackstone

    +1 This is impacting my production application...

    November 3rd, 2010 @ 07:51 PM

  3. Michael Koziarski
    Michael Koziarski

    For this one, could we perhaps simply update 2.3.11 to depend on 1.2? Would anything else misbehave?

    The rack team have shown no interest in doing point releases for the 1.1. release

    November 9th, 2010 @ 10:38 PM

  4. Michael Koziarski
    Michael Koziarski
    • Assigned user set to Michael Koziarski

    November 9th, 2010 @ 10:41 PM

  5. Neeraj Singh
    Neeraj Singh

    I bumped up rack to 1.2 in actionpack and all the tests are passing. Not sure if that means all is good since I don't really know how many tests go through the full stack and how many bypasses rack.

    November 10th, 2010 @ 03:49 AM

  6. Rob Anderton
    Rob Anderton

    As I said in the original ticket I looked at bumping to 1.2 but as these were also broken decided to stick with 1.1 and just patch this specific problem.

    Running with Rack 1.2.0 gives 2 failures for me (this is using Ruby 1.8.6 p383):

    • CookieTest#test_multiple_cookies fails with an incorrect cookie string as it doesn't expect a trailing newline

    • MultipartParamsParsingTest#test_parses_mixed_files fails 500 error because Rack tries to call #rewind on a string

    Rack 1.2.1 breaks immediately (the tests don't get to run at all) because Rack::Utils makes a call to the union method of Regexp which is ok with newer Ruby versions but not with 1.8.6.

    So whichever version you choose it's gonna involve monkeys :)

    November 10th, 2010 @ 09:45 AM

  7. Neeraj Singh
    Neeraj Singh

    My bad.

    I ran the tests again with rack 1.2 and I am getting the same error as reported by Rob.

    I am using.

    ruby 1.8.7 (2010-04-19 patchlevel 253) [i686-darwin10.4.0], MBARI 0x6770, Ruby Enterprise Edition 2010.02.

    November 10th, 2010 @ 09:51 AM

  8. Roel van der Hoorn
    Roel van der Hoorn

    +1 for the attached patch; nasty bug.

    If Rack 1.2 introduces other problems, it is clearly no way to go for a patch-release. Also, Rack's lack of willing to do a point release for 1.1 is really crappy.

    December 16th, 2010 @ 09:04 AM

  9. Rob Anderton
    Rob Anderton

    I'm a little concerned that something that could cause major headaches for people has been assigned a low priority - it's nearly 7 months since the bug was introduced and 2 months since I submitted a patch.

    I can only assume it hasn't created more of a furore because it's a silent killer most likely to be blamed on user error :)

    What needs to be done to ensure this gets fixed?

    December 16th, 2010 @ 09:32 AM

  10. Jonathan Wallace
  11. Trung Lê
  12. Andrew White
  13. Rob Anderton
    Rob Anderton

    afaik 1.1.1 never made it to a 'proper' release. 1.2.x also includes the fix but as discussed above this introduces new problems - patching 1.1 seems like a sensible approach to fixing this problem until Rack sorts itself out.

    Still surprised more people haven't complained about this.

    February 16th, 2011 @ 11:01 AM

  14. Rob Anderton
  15. jrochkind
    jrochkind

    This is NOT fixed in 2.3.11, right? Alas. Still keeping me from updating to a later Rails 2.x than 2.3.6. It surprises me that this hasn't received more attention and is still marked priority=low, I guess few apps need to have quotes in http query strings?

    February 16th, 2011 @ 02:37 PM

  16. Andrew White
    Andrew White

    If you use the Rack 1.1.1.pre gem with 2.3.11 it should be fixed.

    February 16th, 2011 @ 02:48 PM

  17. Rob Anderton
    Rob Anderton

    I've just run through the tests with 1.1.1 installed and the good news is it now works.

    I've attached an updated patch: same as last time although obviously no longer any need to monkey-patch rack. I have bumped the version to 1.1.1 so that people don't inadvertently run with 1.1.0 and kept the query string tests in case Rack ever goes off the rails again.

    February 16th, 2011 @ 04:01 PM