Data Injection Vulnerability in Active Record (CVE-2014-0080)

42 views
Skip to first unread message

Aaron Patterson

unread,
Feb 18, 2014, 2:13:47 PM2/18/14
to ruby-sec...@googlegroups.com
Data Injection Vulnerability in Active Record

There is a data injection vulnerability in Active Record. Specially
crafted strings can be used to save data in PostgreSQL array columns that may
not be intended. This vulnerability has been assigned the CVE identifier
CVE-2014-0080.

Versions Affected: 4.0.x, 4.1.0.beta1
Not affected: 3.2.x and older
Fixed Versions: 4.0.3, 4.1.0.beta2

Impact
------
Specially crafted strings may be used to save data to array columns in
PostgreSQL databases. This vulnerability cannot be used to delete data or
execute arbitrary SQL statements, but *can* be used to add data that could
have an impact on the application (such as setting an admin flag). Only array
type columns in PostgreSQL are impacted.

All users running an affected release should either upgrade or use one of the
work arounds immediately.

Releases
--------
The FIXED releases are available at the normal locations.

Workarounds
-----------
To work around this issue, apply this monkey patch:

```ruby
module ActiveRecord
module ConnectionAdapters
class PostgreSQLColumn
module Cast
alias :old_quote_and_escape :quote_and_escape

ARRAY_ESCAPE = "\\" * 2 * 2 # escape the backslash twice for PG arrays
def quote_and_escape(value)
case value
when "NULL", Numeric
value
else
value = value.gsub(/\\/, ARRAY_ESCAPE)
value.gsub!(/"/,"\\\"")
"\"#{value}\""
end
end
end
end
end
end
```

Patches
-------
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.

* 4-1-beta-array_injection.patch - Patch for 4.1-beta series
* 4-0-array_injection.patch - Patch for 4.0 series

Credits
-------

Thanks Godfrey Chan for reporting this!

--
Aaron Patterson
http://tenderlovemaking.com/
4-0-array_injection.patch
4-1-beta-array_injection.patch
Reply all
Reply to author
Forward
0 new messages