Ruby on Rails SQL Injection
Active Record mishandled nested query parameters, allowing an attacker to send a crafted request that made a parameter return a hash and inject SQL into the WHERE clause, querying an arbitrary table. This affected all versions of Ruby on Rails.
seclists.org
Published on seclists.org
There is a SQL injection vulnerability in Active Record, in ALL versions. This vulnerability has been assigned the CVE identifier CVE-2012-2695.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Active Record did not safely handle nested query parameters, so a crafted request could make a parameter return a hash that was used directly in the WHERE clause.
Impact
An attacker could inject some forms of SQL into the application's queries and query an arbitrary table with some value.
What the attacker needed
Application passes request params to where; attacker can send a crafted request
The fix
It was fixed in Rails 3.2.6, 3.1.6 and 3.0.14, and could be mitigated by casting the parameter to a string.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
Ruby on Rails is a web framework, and Active Record is the part that talks to the database. Normally a parameter like an id is a simple value, but Rails could be tricked into treating it as a structured object (a hash), which changed the database query. That let an attacker alter the query and read data from other tables.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.