Unsafe Query Generation Affecting activerecord package, versions < 4.2.7.1, >= 4.2.0


Severity

Recommended
0.0
high
0
10

CVSS assessment made by Snyk's Security Team. Learn more

Threat Intelligence

EPSS
0.33% (71st percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications

Snyk Learn

Learn about Unsafe Query Generation vulnerabilities in an interactive lesson.

Start learning
  • Snyk IDSNYK-RUBY-ACTIVERECORD-20270
  • published10 Aug 2016
  • disclosed10 Aug 2016
  • creditjoernchen

Introduced: 10 Aug 2016

CVE-2016-6317  (opens in a new tab)
CWE-943  (opens in a new tab)

Overview

ActiveRecord is the Object-Relational Mapping (ORM) that comes out-of-the-box with Rails. It plays the role of Model in the MVC architecture employed by Rails.

There is a vulnerability when ActiveRecord is used in conjunction with JSON parameter parsing.

This vulnerability is similar to CVE-2012-2660, CVE-2012-2694 and CVE-2013-0155.

Details

Due to the way ActiveRecord 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])).

CVSS Scores

version 3.1