Skip to content
SQL injection Write-up Intermediate

SQL Injection Vulnerability in Rails

Active Record mishandles nested query parameters, so a crafted request can make a parameter return a hash that alters the WHERE clause to query an arbitrary table. An attacker could inject some forms of SQL into the application's queries.

groups.google.com

Published on groups.google.com

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.

The author, on groups.google.com

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 properly handle nested query parameters, allowing a crafted parameter to become a hash that influenced the SQL WHERE clause.

Impact

An attacker could inject some forms of SQL into the application's queries, potentially querying an arbitrary table.

What the attacker needed

Rails 3.0.0 or later; app passes request params to where

The fix

The vulnerability was fixed in versions 3.2.4, 3.1.5 and 3.0.13; as a workaround, cast the parameter to a string before passing it to the where method.

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.

When a web app builds a database query from user input, it must treat that input as data, not as part of the query. Here, a specially shaped request could trick the framework into treating a parameter as a structure that changes which table the query reads. That lets an attacker read data they should not see.

What is SQL injection?

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.

Similar reports

View all

Same bug class and techniques, clearest first.

SQL injection

The lesson behind this report.

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.