Sunday, December 8, 2019
Home / Security / Exploits / Ruby on Rails SQL Injection Vulnerability

Ruby on Rails SQL Injection Vulnerability

SQL Injection Vulnerability in Ruby on Rails

There is a SQL injection vulnerability in Active Record, version 3.0 and later. This vulnerability has been assigned
the CVE identifier CVE-2012-2661.

Versions Affected: 3.0.0 and ALL later versions
Not affected: 2.3.14
Fixed Versions: 3.2.4, 3.1.5, 3.0.13


Due to the way Active Record handles nested query parameters, an attacker can use a specially crafted request to inject
some forms of SQL into your application’s SQL queries.

All users running an affected release should upgrade immediately.

Impacted code directly passes request params to the `where` method of an ActiveRecord class like this:

Post.where(:id => params[:id]).all

An attacker can make a request that causes `params[:id]` to return a specially crafted hash that will cause the WHERE
clause of the SQL statement to query an arbitrary table with some value.

The FIXED releases are available at the normal locations.

This issue can be mitigated by casting the parameter to an expected value. For example, change this:

Post.where(:id => params[:id]).all

to this:

Post.where(:id => params[:id].to_s).all

To aid users who aren’t able to upgrade immediately we have provided patches for the two supported release series.
They are in git-am format and consist of a single changeset. We have also provided a patch for the 3.0 series despite
the fact it is unmaintained.

* 3-0-params_sql_injection.patch – Patch for 3.0 series
* 3-1-params_sql_injection.patch – Patch for 3.1 series
* 3-2-params_sql_injection.patch – Patch for 3.2 series

Please note that only the 3.1.x and 3.2.x series are supported at present. Users of earlier unsupported releases are
advised to upgrade as soon as possible as we cannot guarantee the continued availability of security fixes for
unsupported releases.


Thanks to Ben Murphy for reporting the vulnerability to us, and to Chad Pyne of thoughtbot for helping us verify the


Attachment: 3-0-params_sql_injection.patch
 Attachment: 3-1-params_sql_injection.patch
 Attachment: 3-2-params_sql_injection.patch
 Attachment: _bin


About FastFlux

Owner of ZeroSecurity, interested in programming, malware analysis and penetration testing. If you would like to write for the ZeroSecurity team, please use the contact form above.

Check Also

Amazon hacked – hacker leaks 80,000 login credentials

A hacker going by the name 0x2Taylor has said to have breached the servers of …