Skip to content
SQL injection Write-up Advanced

Rails SQL injection vulnerability: here are the facts

A SQL injection vulnerability existed in Rails' dynamic finder methods because they accepted an options hash as the first argument, allowing an attacker who could supply a hash with symbol keys to inject SQL. The main known exploit required knowledge of the session secret to tamper with a signed cookie used by Authlogic.

blog.phusion.nl

Published on blog.phusion.nl

Yesterday a Ruby on Rails SQL injection vulnerability was announced which affects all versions. This immediately received widespread attention on Hacker News.

The author, on blog.phusion.nl

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

Impact

An attacker who knows the session secret could inject arbitrary SQL through Authlogic, but request parameters alone are not exploitable because they produce string keys.

What the attacker needed

Rails app using Authlogic; Attacker knows the session secret

The fix

It was fixed by upgrading Rails so that the first parameter of dynamic finders may not be an options hash.

How it was found

  1. Obtain the session secret for the target Rails application.
  2. Tamper with the signed session cookie to include a hash with symbol keys.
  3. Trigger Authlogic authentication so it calls a dynamic finder with that hash.
  4. The injected SQL options are executed by the database.

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.

SQL injection is when an attacker sneaks database commands into input that the program treats as data. Here, a Rails helper that looks up records could be tricked into treating a specially shaped input as database options instead of a plain value, but only if the input arrived as a particular kind of Ruby object and, in the main example, only if the attacker also knew a secret used to sign cookies.

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.