Denial of Service Vulnerability in ActiveRecord's PostgreSQL adapter
There is a potential denial of service vulnerability present in ActiveRecord's PostgreSQL adapter.
This has been assigned the CVE identifier CVE-2022-44566.
Versions Affected: All. Not affected: None.
Fixed Versions
2.3.18.47 (Rails LTS, which is a paid service and not part of the rubygem)
3.2.22.34 (Rails LTS, which is a paid service and not part of the rubygem)
4.2.11.27 (Rails LTS, which is a paid service and not part of the rubygem)
5.2.8.15 (Rails LTS, which is a paid service and not part of the rubygem)
6.1.7.1
7.0.4.1
Impact
In ActiveRecord < 7.0.4.1 and < 6.1.7.1, when a value outside the range for a 64bit signed integer is provided to the PostgreSQL connection adapter, it will treat the target column type as numeric. Comparing integer values against numeric values can result in a slow sequential scan resulting in potential Denial of Service.
Releases
The fixed releases are available at the normal locations.
Workarounds
Ensure that user supplied input which is provided to ActiveRecord clauses do not contain integers wider than a signed 64bit representation or floats.
Patches
To aid users who aren't able to upgrade immediately we have provided patches for the supported release series in accordance with our maintenance policy 1 regarding security issues. They are in git-am format and consist of a single changeset.
6-1-Added-integer-width-check-to-PostgreSQL-Quoting.patch - Patch for 6.1 series
7-0-Added-integer-width-check-to-PostgreSQL-Quoting.patch - Patch for 7.0 series
SQL Injection Vulnerability via ActiveRecord comments
There is a possible vulnerability in ActiveRecord related to the sanitization of comments. This vulnerability has been assigned the CVE identifier CVE-2023-22794.
Versions Affected: >= 6.0.0 Not affected: < 6.0.0 Fixed Versions: 6.0.6.1, 6.1.7.1, 7.0.4.1
Impact
Previously the implementation of escaping for comments was insufficient for
If malicious user input is passed to either the annotate query method, the optimizer_hints query method, or through the QueryLogs interface which automatically adds annotations, it may be sent to the database with insufficient sanitization and be able to inject SQL outside of the comment.
In most cases these interfaces won’t be used with user input and users should avoid doing so.
Example vulnerable code:
``
Post.where(id: 1).annotate("#{params[:user_input]}")
Post.where(id: 1).optimizer_hints("#{params[:user_input]}")
`
Example vulnerable QueryLogs configuration (the default configuration is not vulnerable):
`
config.active_record.query_log_tags = [
{
something: -> { <some value including user input> }
}
]
``
All users running an affected release should either upgrade or use one of the workarounds immediately.
Releases
The FIXED releases are available at the normal locations.
Workarounds
Avoid passing user input to annotate and avoid using QueryLogs configuration which can include user input.
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.
6-0-Make-sanitize_as_sql_comment-more-strict.patch - Patch for 6.0 series
6-1-Make-sanitize_as_sql_comment-more-strict.patch - Patch for 6.1 series
7-0-Make-sanitize_as_sql_comment-more-strict.patch - Patch for 7.0 series
Please note that only the 7.0.Z and 6.1.Z series are supported at present, and 6.0.Z for severe vulnerabilities. Users of earlier unsupported releases are advised to upgrade as soon as possible as we cannot guarantee the continued availability of security fixes for unsupported releases.
Path Traversal in Action View
File Content Disclosure in Action View
Impact
------
There is a possible file content disclosure vulnerability in Action View. Specially crafted accept headers in combination with calls to render file: can cause arbitrary files on the target server to be rendered, disclosing the file contents.
The impact is limited to calls to render which render file contents without a specified accept format. Impacted code in a controller looks something like this:
`` ruby
class UserController < ApplicationController
def index
render file: "#{Rails.root}/some/file"
end
end
`
Rendering templates as opposed to files is not impacted by this vulnerability.
All users running an affected release should either upgrade or use one of the workarounds immediately.
Releases
--------
The 6.0.0.beta3, 5.2.2.1, 5.1.6.2, 5.0.7.2, and 4.2.11.1 releases are available at the normal locations.
Workarounds
-----------
This vulnerability can be mitigated by specifying a format for file rendering, like this:
` ruby
class UserController < ApplicationController
def index
render file: "#{Rails.root}/some/file", formats: [:html]
end
end
`
In summary, impacted calls to render look like this:
`
render file: "#{Rails.root}/some/file"
`
The vulnerability can be mitigated by changing to this:
`
render file: "#{Rails.root}/some/file", formats: [:html]
`
Other calls to render are not impacted.
Alternatively, the following monkey patch can be applied in an initializer:
` ruby
$ cat config/initializers/formats_filter.rb
frozen_string_literal: true
ActionDispatch::Request.prepend(Module.new do
def formats
super().select do |format|
format.symbol || format.ref == "/"
end
end
end)
``
Credits
-------
Thanks to John Hawthorn <john@hawthorn.email> of GitHub
actionpack Path Traversal vulnerability
Directory traversal vulnerability in actionpack/lib/abstract_controller/base.rb in the implicit-render implementation in Ruby on Rails before 3.2.18, 4.0.x before 4.0.5, and 4.1.x before 4.1.1, when certain route globbing configurations are enabled, allows remote attackers to read arbitrary files via a crafted request.
Directory traversal vulnerability in Action View in Ruby on Rails
Directory traversal vulnerability in Action View in Ruby on Rails before 3.2.22.1, 4.0.x and 4.1.x before 4.1.14.1, 4.2.x before 4.2.5.1, and 5.x before 5.0.0.beta1.1 allows remote attackers to read arbitrary files by leveraging an application's unrestricted use of the render method and providing a .. (dot dot) in a pathname.
Rails ReDoS in HTTP Token authentication
HTTP Token authentication parsing vulnerable to ReDoS.