Bug 892866 (CVE-2013-0155) - CVE-2013-0155 rubygem-actionpack, rubygem-activerecord: Unsafe Query Generation Risk in Ruby on Rails
Summary: CVE-2013-0155 rubygem-actionpack, rubygem-activerecord: Unsafe Query Generati...
Keywords:
Status: CLOSED ERRATA
Alias: CVE-2013-0155
Product: Security Response
Classification: Other
Component: vulnerability
Version: unspecified
Hardware: All
OS: Linux
high
high
Target Milestone: ---
Assignee: Red Hat Product Security
QA Contact:
URL:
Whiteboard:
Depends On: 892873 892875 892877 893281 916342
Blocks: 893691
TreeView+ depends on / blocked
 
Reported: 2013-01-08 05:24 UTC by Kurt Seifried
Modified: 2019-09-29 12:58 UTC (History)
20 users (show)

Fixed In Version: rubygem-activerecord 3.2.11, rubygem-activerecord 3.1.10, rubygem-activerecord 3.0.19, rubygem-actionpack 3.2.11, rubygem-actionpack 3.1.10, rubygem-actionpack 3.0.19
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2013-04-10 22:29:35 UTC
Embargoed:


Attachments (Terms of Use)
actionpack-CVE-2012-0155-3-0-null_array_param.patch (7.46 KB, patch)
2013-01-08 06:01 UTC, Kurt Seifried
no flags Details | Diff
actionpack-CVE-2012-0155-3-1-null_array_param.patch (7.35 KB, patch)
2013-01-08 06:02 UTC, Kurt Seifried
no flags Details | Diff
actionpack-CVE-2012-0155-3-2-null_array_param.patch (7.33 KB, patch)
2013-01-08 06:02 UTC, Kurt Seifried
no flags Details | Diff
actionpack-CVE-2012-0155-3-2-unsafe_query.patch (7.30 KB, patch)
2013-01-08 06:02 UTC, Kurt Seifried
no flags Details | Diff
actionpack-CVE-2013-0155-3-0-null_array_param.patch (7.67 KB, patch)
2013-01-08 21:24 UTC, Kurt Seifried
no flags Details | Diff
actionpack-CVE-2013-0155-3-1-null_array_param.patch (7.56 KB, patch)
2013-01-08 21:25 UTC, Kurt Seifried
no flags Details | Diff
actionpack-CVE-2013-0155-3-2-null_array_param.patch (7.53 KB, patch)
2013-01-08 21:25 UTC, Kurt Seifried
no flags Details | Diff


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2013:0154 0 normal SHIPPED_LIVE Critical: Ruby on Rails security update 2013-01-11 01:38:55 UTC
Red Hat Product Errata RHSA-2013:0155 0 normal SHIPPED_LIVE Critical: Ruby on Rails security update 2013-01-11 03:40:25 UTC
Red Hat Product Errata RHSA-2013:0582 0 normal SHIPPED_LIVE Moderate: Red Hat OpenShift Enterprise 1.1.1 update 2013-03-01 00:05:18 UTC

Description Kurt Seifried 2013-01-08 05:24:45 UTC
Damien Mathieu (42) reports:

Unsafe Query Generation Risk in Ruby on Rails

There is a vulnerability when Active Record is used in conjunction with JSON 
parameter parsing. This vulnerability has been assigned the CVE identifier 
CVE-2013-0155.

Versions Affected:  3.x series
Not affected:       2.x series
Fixed Versions:     3.2.11, 3.1.10, 3.0.19

Impact
------

Due to the way Active Record interprets parameters in combination with the way
that JSON parameters are parsed, it is possible for an attacker to issue 
unexpected database queries with "IS NULL" or empty where clauses.  This issue 
does *not* let an attacker insert arbitrary values into an SQL query, however 
they can cause the query to check for NULL or eliminate a WHERE clause when 
most users wouldn't expect it.

For example, a system has password reset with token functionality:

    unless params[:token].nil?
      user = User.find_by_token(params[:token])
      user.reset_password!
    end

An attacker can craft a request such that `params[:token]` will return `[nil]`.
The `[nil]` value will bypass the test for nil, but will still add an 
"IN ('xyz', NULL)" clause to the SQL query.

Similarly, an attacker can craft a request such that `params[:token]` will 
return an empty hash.  An empty hash will eliminate the WHERE clause of the 
query, but can bypass the `nil?` check.

Note that this impacts not only dynamic finders (`find_by_*`) but also 
relations (`User.where(:name => params[:name])`).

All users running an affected release should either upgrade or use one of the 
work arounds immediately. All users running an affected release should upgrade
immediately. Please note, this vulnerability is a variant of CVE-2012-2660, 
and CVE-2012-2694.  Even if you upgraded to address those issues, you must 
take action again.

If this chance in behavior impacts your application, you can manually decode 
the original values from the request like so:

    ActiveSupport::JSON.decode(request.body)

Releases
--------
The FIXED releases are available at the normal locations.

Workarounds
-----------
This problem can be mitigated by casting the parameter to a string before 
passing it to Active Record.  For example:

    unless params[:token].nil? || params[:token].to_s.empty?
      user = User.find_by_token(params[:token].to_s)
      user.reset_password!
    end
An attacker can craft a request such that `params[:token]` will return `[nil]`.
The `[nil]` value will bypass the test for nil, but will still add an 
"IN ('xyz', NULL)" clause to the SQL query.

Similarly, an attacker can craft a request such that `params[:token]` will 
return an empty hash.  An empty hash will eliminate the WHERE clause of the 
query, but can bypass the `nil?` check.

Note that this impacts not only dynamic finders (`find_by_*`) but also 
relations (`User.where(:name => params[:name])`).

All users running an affected release should either upgrade or use one of the 
work arounds immediately. All users running an affected release should upgrade
immediately. Please note, this vulnerability is a variant of CVE-2012-2660, 
and CVE-2012-2694.  Even if you upgraded to address those issues, you must 
take action again.

If this chance in behavior impacts your application, you can manually decode 
the original values from the request like so:

    ActiveSupport::JSON.decode(request.body)

Releases
--------
The FIXED releases are available at the normal locations.

Workarounds
-----------
This problem can be mitigated by casting the parameter to a string before 
passing it to Active Record.  For example:

    unless params[:token].nil? || params[:token].to_s.empty?
      user = User.find_by_token(params[:token].to_s)
      user.reset_password!
    end

Note the parameter is still cast to a string before being sent to Active 
Record. This is because an array with a nil value can still bypass the 
`to_s.empty?` test:

    >> ['xyz', nil].to_s
    => "xyz"
    >> ['xyz', nil].to_s.empty?
    => false

Comment 1 Kurt Seifried 2013-01-08 06:01:39 UTC
Created attachment 674505 [details]
actionpack-CVE-2012-0155-3-0-null_array_param.patch

Comment 2 Kurt Seifried 2013-01-08 06:02:02 UTC
Created attachment 674506 [details]
actionpack-CVE-2012-0155-3-1-null_array_param.patch

Comment 3 Kurt Seifried 2013-01-08 06:02:28 UTC
Created attachment 674507 [details]
actionpack-CVE-2012-0155-3-2-null_array_param.patch

Comment 4 Kurt Seifried 2013-01-08 06:02:46 UTC
Created attachment 674508 [details]
actionpack-CVE-2012-0155-3-2-unsafe_query.patch

Comment 9 Kurt Seifried 2013-01-08 21:24:03 UTC
Created attachment 675073 [details]
actionpack-CVE-2013-0155-3-2-unsafe_query.patch

Comment 10 Kurt Seifried 2013-01-08 21:24:42 UTC
Created attachment 675074 [details]
actionpack-CVE-2013-0155-3-0-null_array_param.patch

Comment 11 Kurt Seifried 2013-01-08 21:25:30 UTC
Created attachment 675075 [details]
actionpack-CVE-2013-0155-3-1-null_array_param.patch

Comment 12 Kurt Seifried 2013-01-08 21:25:51 UTC
Created attachment 675076 [details]
actionpack-CVE-2013-0155-3-2-null_array_param.patch

Comment 13 Vincent Danen 2013-01-09 02:20:59 UTC
Created rubygem-actionpack tracking bugs for this issue

Affects: fedora-all [bug 893281]

Comment 14 Kurt Seifried 2013-01-09 06:37:26 UTC
The upstream report:

https://groups.google.com/forum/#!topic/rubyonrails-security/t1WFuuQyavI

Comment 15 Tomas Hoger 2013-01-09 12:46:55 UTC
The fix for this issue was reported to introduce a regression:

https://github.com/rails/rails/issues/8832

Comment 17 errata-xmlrpc 2013-01-10 20:42:47 UTC
This issue has been addressed in following products:

  Red Hat Subscription Asset Manager 1.1

Via RHSA-2013:0154 https://rhn.redhat.com/errata/RHSA-2013-0154.html

Comment 18 errata-xmlrpc 2013-01-10 22:41:38 UTC
This issue has been addressed in following products:

  CloudForms for RHEL 6

Via RHSA-2013:0155 https://rhn.redhat.com/errata/RHSA-2013-0155.html

Comment 19 Fedora Update System 2013-01-20 03:40:20 UTC
rubygem-actionpack-3.2.8-2.fc18, rubygem-activerecord-3.2.8-3.fc18, rubygem-activesupport-3.2.8-2.fc18 has been pushed to the Fedora 18 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 20 Fedora Update System 2013-01-23 01:33:23 UTC
rubygem-actionpack-3.0.10-10.fc16, rubygem-activerecord-3.0.10-5.fc16, rubygem-activesupport-3.0.10-5.fc16, rubygem-activemodel-3.0.10-2.fc16 has been pushed to the Fedora 16 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 21 Fedora Update System 2013-01-23 01:53:10 UTC
rubygem-actionpack-3.0.11-8.fc17, rubygem-activerecord-3.0.11-5.fc17, rubygem-activemodel-3.0.11-2.fc17, rubygem-activesupport-3.0.11-7.fc17 has been pushed to the Fedora 17 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 23 errata-xmlrpc 2013-02-28 19:08:48 UTC
This issue has been addressed in following products:

  RHEL 6 Version of OpenShift Enterprise

Via RHSA-2013:0582 https://rhn.redhat.com/errata/RHSA-2013-0582.html


Note You need to log in before you can comment on or make changes to this bug.