CWE
284 89 264
Advisory Published
CVE Published
Advisory Published
Updated

CVE-2013-0155: SQL Injection

First published: Tue Jan 08 2013(Updated: )

Damien Mathieu (42) reports: Unsafe Query Generation Risk in Ruby on Rails There is a vulnerability when Active Record is used in conjunction with JSON parameter parsing. This vulnerability has been assigned the CVE identifier <a href="https://access.redhat.com/security/cve/CVE-2013-0155">CVE-2013-0155</a>. Versions Affected: 3.x series Not affected: 2.x series Fixed Versions: 3.2.11, 3.1.10, 3.0.19 Impact ------ Due to the way Active Record 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 =&gt; params[:name])`). All users running an affected release should either upgrade or use one of the work arounds immediately. All users running an affected release should upgrade immediately. Please note, this vulnerability is a variant of <a href="https://access.redhat.com/security/cve/CVE-2012-2660">CVE-2012-2660</a>, and <a href="https://access.redhat.com/security/cve/CVE-2012-2694">CVE-2012-2694</a>. Even if you upgraded to address those issues, you must take action again. If this chance in behavior impacts your application, you can manually decode the original values from the request like so: ActiveSupport::JSON.decode(request.body) Releases -------- The FIXED releases are available at the normal locations. Workarounds ----------- This problem can be mitigated by casting the parameter to a string before passing it to Active Record. For example: unless params[:token].nil? || params[:token].to_s.empty? user = User.find_by_token(params[:token].to_s) 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 =&gt; params[:name])`). All users running an affected release should either upgrade or use one of the work arounds immediately. All users running an affected release should upgrade immediately. Please note, this vulnerability is a variant of <a href="https://access.redhat.com/security/cve/CVE-2012-2660">CVE-2012-2660</a>, and <a href="https://access.redhat.com/security/cve/CVE-2012-2694">CVE-2012-2694</a>. Even if you upgraded to address those issues, you must take action again. If this chance in behavior impacts your application, you can manually decode the original values from the request like so: ActiveSupport::JSON.decode(request.body) Releases -------- The FIXED releases are available at the normal locations. Workarounds ----------- This problem can be mitigated by casting the parameter to a string before passing it to Active Record. For example: unless params[:token].nil? || params[:token].to_s.empty? user = User.find_by_token(params[:token].to_s) user.reset_password! end Note the parameter is still cast to a string before being sent to Active Record. This is because an array with a nil value can still bypass the `to_s.empty?` test: &gt;&gt; ['xyz', nil].to_s =&gt; "xyz" &gt;&gt; ['xyz', nil].to_s.empty? =&gt; false

Credit: secalert@redhat.com secalert@redhat.com

Affected SoftwareAffected VersionHow to fix
redhat/rubygem-actionpack<1:3.0.10-11.el6cf
1:3.0.10-11.el6cf
redhat/rubygem-activerecord<1:3.0.10-8.el6cf
1:3.0.10-8.el6cf
redhat/rubygem-activesupport<1:3.0.10-5.el6cf
1:3.0.10-5.el6cf
redhat/graphviz<0:2.26.0-10.el6
0:2.26.0-10.el6
redhat/openshift-console<0:0.0.16-1.el6
0:0.0.16-1.el6
redhat/openshift-origin-broker<0:1.0.11-1.el6
0:1.0.11-1.el6
redhat/openshift-origin-broker-util<0:1.0.15-1.el6
0:1.0.15-1.el6
redhat/openshift-origin-cartridge-cron<1.4-0:1.0.3-1.el6
1.4-0:1.0.3-1.el6
redhat/openshift-origin-cartridge-diy<0.1-0:1.0.3-1.el6
0.1-0:1.0.3-1.el6
redhat/openshift-origin-cartridge-haproxy<1.4-0:1.0.4-1.el6
1.4-0:1.0.4-1.el6
redhat/openshift-origin-cartridge-jbosseap<6.0-0:1.0.4-1.el6
6.0-0:1.0.4-1.el6
redhat/openshift-origin-cartridge-jbossews<1.0-0:1.0.13-1.el6
1.0-0:1.0.13-1.el6
redhat/openshift-origin-cartridge-jenkins<1.4-0:1.0.2-1.el6
1.4-0:1.0.2-1.el6
redhat/openshift-origin-cartridge-jenkins-client<1.4-0:1.0.2-1.el6
1.4-0:1.0.2-1.el6
redhat/openshift-origin-cartridge-mysql<5.1-0:1.0.5-1.el6
5.1-0:1.0.5-1.el6
redhat/openshift-origin-cartridge-perl<5.10-0:1.0.3-1.el6
5.10-0:1.0.3-1.el6
redhat/openshift-origin-cartridge-php<5.3-0:1.0.5-1.el6
5.3-0:1.0.5-1.el6
redhat/openshift-origin-cartridge-postgresql<8.4-0:1.0.3-2.el6
8.4-0:1.0.3-2.el6
redhat/openshift-origin-cartridge-ruby<1.8-0:1.0.7-1.el6
1.8-0:1.0.7-1.el6
redhat/openshift-origin-cartridge-ruby<1.9-scl-0:1.0.8-1.el6
1.9-scl-0:1.0.8-1.el6
redhat/openshift-origin-msg-node-mcollective<0:1.0.3-1.el6
0:1.0.3-1.el6
redhat/php<0:5.3.3-22.el6
0:5.3.3-22.el6
redhat/ruby193-ruby<0:1.9.3.327-25.el6
0:1.9.3.327-25.el6
redhat/ruby193-rubygem-actionpack<1:3.2.8-3.el6
1:3.2.8-3.el6
redhat/ruby193-rubygem-activemodel<0:3.2.8-2.el6
0:3.2.8-2.el6
redhat/ruby193-rubygem-activerecord<1:3.2.8-3.el6
1:3.2.8-3.el6
redhat/ruby193-rubygem-railties<0:3.2.8-2.el6
0:3.2.8-2.el6
redhat/rubygem-actionpack<1:3.0.13-4.el6
1:3.0.13-4.el6
redhat/rubygem-activemodel<0:3.0.13-3.el6
0:3.0.13-3.el6
redhat/rubygem-activerecord<1:3.0.13-5.el6
1:3.0.13-5.el6
redhat/rubygem-bson<0:1.8.1-2.el6
0:1.8.1-2.el6
redhat/rubygem-mongo<0:1.8.1-2.el6
0:1.8.1-2.el6
redhat/rubygem-openshift-origin-auth-remote-user<0:1.0.5-1.el6
0:1.0.5-1.el6
redhat/rubygem-openshift-origin-console<0:1.0.10-1.el6
0:1.0.10-1.el6
redhat/rubygem-openshift-origin-controller<0:1.0.12-1.el6
0:1.0.12-1.el6
redhat/rubygem-openshift-origin-node<0:1.0.11-1.el6
0:1.0.11-1.el6
redhat/rubygem-activerecord<3.2.11
3.2.11
redhat/rubygem-activerecord<3.1.10
3.1.10
redhat/rubygem-activerecord<3.0.19
3.0.19
redhat/rubygem-actionpack<3.2.11
3.2.11
redhat/rubygem-actionpack<3.1.10
3.1.10
redhat/rubygem-actionpack<3.0.19
3.0.19
Rubyonrails Rails>=3.2.0<3.2.11
Rubyonrails Ruby On Rails>=3.0.0<3.0.19
Rubyonrails Ruby On Rails>=3.1.0<3.1.10
Debian Debian Linux=6.0

Never miss a vulnerability like this again

Sign up to SecAlerts for real-time vulnerability data matched to your software, aggregated from hundreds of sources.

Reference Links

Parent vulnerabilities

(Appears in the following advisories)

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2024 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203