CVE-2023-22794: Activerecord SQL Injection Vulnerability
HIGHCVE-2023-22794 is a HIGH (CVSS 8.8) sql injection vulnerability (CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')) affecting Activerecord libraries in the RubyGems ecosystem. The issue involves sql injection vulnerability via activerecord comments. Remediation is available by upgrading affected packages to version 6.0.6.1, 6.1.7.1, 7.0.4.1.
CVE-2023-22794 at a Glance
Security Impact
CVSS: 8.8
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H).
How to Fix CVE-2023-22794
To remediate this vulnerability, upgrade all affected Activerecord dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
Upgrade activerecord to 6.0.6.1
Upgrade activerecord to 6.1.7.1
Upgrade activerecord to 7.0.4.1
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
inspect dependencies for activerecord
How to Check if You Are Affected
To determine whether your application is affected by CVE-2023-22794, inspect your project dependencies for Activerecord:
inspect dependencies for activerecord
Analyze the terminal output to locate any version of Activerecord in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 6.0.6.1), your application is affected.
Note: Verify declared build manifests and deployed runtime container environments.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where the product constructs all or part of an sql command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended sql command when it is sent to a downstream component. without sufficient removal or quoting of sql syntax in user-controllable inputs, the generated sql query can cause those inputs to be interpreted as sql instead of ordinary user data. In Activerecord, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2023-22794 Affected Activerecord Versions
3 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
activerecord
|
RubyGems |
≥ 6.0.0
< 6.0.6.1
|
6.0.6.1
|
|
activerecord
|
RubyGems |
≥ 6.1.0
< 6.1.7.1
|
6.1.7.1
|
|
activerecord
|
RubyGems |
≥ 7.0.0
< 7.0.4.1
|
7.0.4.1
|
References
Frequently Asked Questions
What is CVE-2023-22794?
Which Activerecord versions are affected?
What version fixes CVE-2023-22794?
Is activerecord affected?
What is the CVSS score of CVE-2023-22794?
What CWE is associated with CVE-2023-22794?
How can I check RubyGems dependencies for CVE-2023-22794?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-hq7p-j377-6v63",
"modified" : "2024-02-02T16:49:27Z",
"published" : "2023-01-18T18:20:19Z",
"aliases" : [ "CVE-2023-22794" ],
"summary" : "SQL Injection Vulnerability via ActiveRecord comments",
"details" : "There is a possible vulnerability in ActiveRecord related to the sanitization of comments. This vulnerability has been assigned the CVE identifier CVE-2023-22794.\n\nVersions Affected: >= 6.0.0 Not affected: < 6.0.0 Fixed Versions: 6.0.6.1, 6.1.7.1, 7.0.4.1\nImpact\n\nPreviously the implementation of escaping for comments was insufficient for\n\nIf 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.\n\nIn most cases these interfaces won’t be used with user input and users should avoid doing so.\n\nExample vulnerable code:\n```\nPost.where(id: 1).annotate(\"#{params[:user_input]}\")\n\nPost.where(id: 1).optimizer_hints(\"#{params[:user_input]}\")\n```\nExample vulnerable QueryLogs configuration (the default configuration is not vulnerable):\n```\nconfig.active_record.query_log_tags = [\n {\n something: -> { <some value including user input> }\n }\n]\n```\nAll users running an affected release should either upgrade or use one of the workarounds immediately.\nReleases\n\nThe FIXED releases are available at the normal locations.\nWorkarounds\n\nAvoid passing user input to annotate and avoid using QueryLogs configuration which can include user input.\nPatches\n\nTo 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.\n\n 6-0-Make-sanitize_as_sql_comment-more-strict.patch - Patch for 6.0 series\n 6-1-Make-sanitize_as_sql_comment-more-strict.patch - Patch for 6.1 series\n 7-0-Make-sanitize_as_sql_comment-more-strict.patch - Patch for 7.0 series\n\nPlease 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.",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "RubyGems",
"name" : "activerecord"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "6.0.0"
}, {
"fixed" : "6.0.6.1"
} ]
} ]
}, {
"package" : {
"ecosystem" : "RubyGems",
"name" : "activerecord"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "6.1.0"
}, {
"fixed" : "6.1.7.1"
} ]
} ]
}, {
"package" : {
"ecosystem" : "RubyGems",
"name" : "activerecord"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "7.0.0"
}, {
"fixed" : "7.0.4.1"
} ]
} ]
} ],
"references" : [ {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-22794"
}, {
"type" : "WEB",
"url" : "https://github.com/rails/rails/commit/d7aba06953f9fa789c411676b941d20df8ef73de"
}, {
"type" : "WEB",
"url" : "https://discuss.rubyonrails.org/t/cve-2023-22794-sql-injection-vulnerability-via-activerecord-comments/82117"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/rails/rails"
}, {
"type" : "WEB",
"url" : "https://github.com/rails/rails/releases/tag/v7.0.4.1"
}, {
"type" : "WEB",
"url" : "https://github.com/rubysec/ruby-advisory-db/blob/master/gems/activerecord/CVE-2023-22794.yml"
}, {
"type" : "WEB",
"url" : "https://security.netapp.com/advisory/ntap-20240202-0008"
}, {
"type" : "WEB",
"url" : "https://www.debian.org/security/2023/dsa-5372"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-89" ],
"severity" : "HIGH",
"github_reviewed" : true,
"github_reviewed_at" : "2023-01-18T18:20:19Z",
"nvd_published_at" : "2023-02-09T20:15:00Z"
}
}