CVE-2022-21831: Activestorage Possible Code Injection Vulnerability Vulnerability

CRITICAL
Advisory Identifier: GHSA-w749-p3v6-hccq
CVSS 9.8
CWE-94
Published
Advisory Summary

CVE-2022-21831 is a CRITICAL (CVSS 9.8) possible code injection vulnerability vulnerability (CWE-94: Improper Control of Generation of Code ('Code Injection')) affecting Activestorage libraries in the RubyGems ecosystem. The issue involves possible code injection vulnerability in rails / active storage. Remediation is available by upgrading affected packages to version 5.2.6.3, 6.0.4.7, 6.1.4.7, 7.0.2.3.

CVE-2022-21831 at a Glance

CVE Identifier CVE-2022-21831
GHSA Identifier GHSA-w749-p3v6-hccq
Severity CRITICAL
CVSS v3.1 Base Score 9.8
CWE Classification CWE-94: Improper Control of Generation of Code ('Code Injection')
Affected Product Activestorage
Package Ecosystem RubyGems
Published Date
Last Updated

Security Impact

CVSS: 9.8

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2022-21831

To remediate this vulnerability, upgrade all affected Activestorage dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

activestorage fixed: 5.2.6.3
Upgrade activestorage to 5.2.6.3
activestorage fixed: 6.0.4.7
Upgrade activestorage to 6.0.4.7
activestorage fixed: 6.1.4.7
Upgrade activestorage to 6.1.4.7
activestorage fixed: 7.0.2.3
Upgrade activestorage to 7.0.2.3
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for activestorage

How to Check if You Are Affected

To determine whether your application is affected by CVE-2022-21831, inspect your project dependencies for Activestorage:

inspect dependencies for activestorage

Analyze the terminal output to locate any version of Activestorage in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 5.2.6.3), 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-94: Improper Control of Generation of Code ('Code Injection'), where the product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment. In Activestorage, 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

The Active Storage module of Rails starting with version 5.2.0 is possibly vulnerable to code injection. This issue was patched in versions 5.2.6.3, 6.0.4.7, 6.1.4.7, and 7.0.2.3. To work around this issue, applications should implement a strict allow-list on accepted transformation methods or arguments. Additionally, a strict ImageMagick security policy will help mitigate this issue.

CVE-2022-21831 Affected Activestorage Versions

4 component(s)
Fixed Versions:
5.2.6.36.0.4.76.1.4.77.0.2.3
Product / Package Ecosystem Affected Versions Fixed Version
activestorage
RubyGems
≥ 5.2.0
< 5.2.6.3
5.2.6.3
activestorage
RubyGems
≥ 6.0.0
< 6.0.4.7
6.0.4.7
activestorage
RubyGems
≥ 6.1.0
< 6.1.4.7
6.1.4.7
activestorage
RubyGems
≥ 7.0.0
< 7.0.2.3
7.0.2.3

References

Frequently Asked Questions

What is CVE-2022-21831?
CVE-2022-21831 is a security vulnerability in Activestorage involving Possible code injection vulnerability in Rails / Active Storage under CWE-94: Improper Control of Generation of Code ('Code Injection').
Which Activestorage versions are affected?
Affected versions include releases prior to 5.2.6.3, 6.0.4.7, 6.1.4.7, 7.0.2.3 across affected packages: activestorage.
What version fixes CVE-2022-21831?
Upgrading to 5.2.6.3, 6.0.4.7, 6.1.4.7, 7.0.2.3 (or the latest patched release for your respective branch) resolves the vulnerability.
Is activestorage affected?
Yes, activestorage is affected in releases prior to 5.2.6.3, 6.0.4.7, 6.1.4.7, 7.0.2.3. Upgrade your dependency to 5.2.6.3, 6.0.4.7, 6.1.4.7, 7.0.2.3 or later.
What is the CVSS score of CVE-2022-21831?
CVE-2022-21831 has a CVSS v3.1 base score of 9.8 (CRITICAL) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2022-21831?
CVE-2022-21831 is classified under CWE-94: Improper Control of Generation of Code ('Code Injection') (The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.).
How can I check RubyGems dependencies for CVE-2022-21831?
Run the dependency tree command: 'inspect dependencies for activestorage'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-w749-p3v6-hccq",
  "modified" : "2022-06-21T15:59:23Z",
  "published" : "2022-03-08T21:25:54Z",
  "aliases" : [ "CVE-2022-21831" ],
  "summary" : "Possible code injection vulnerability in Rails / Active Storage",
  "details" : "The Active Storage module of Rails starting with version 5.2.0 is possibly vulnerable to code injection. This issue was patched in versions 5.2.6.3, 6.0.4.7, 6.1.4.7, and 7.0.2.3. To work around this issue, applications should implement a strict allow-list on accepted transformation methods or arguments.  Additionally, a strict ImageMagick security policy will help mitigate this issue.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "activestorage"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "5.2.0"
      }, {
        "fixed" : "5.2.6.3"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 5.2.6.2"
    }
  }, {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "activestorage"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "6.0.0"
      }, {
        "fixed" : "6.0.4.7"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 6.0.4.6"
    }
  }, {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "activestorage"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "6.1.0"
      }, {
        "fixed" : "6.1.4.7"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 6.1.4.6"
    }
  }, {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "activestorage"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "7.0.0"
      }, {
        "fixed" : "7.0.2.3"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 7.0.2.2"
    }
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-21831"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rails/rails/commit/0a72f7d670e9aa77a0bb8584cb1411ddabb7546e"
  }, {
    "type" : "ADVISORY",
    "url" : "https://github.com/advisories/GHSA-w749-p3v6-hccq"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/rails/rails"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rubysec/ruby-advisory-db/blob/master/gems/activestorage/CVE-2022-21831.yml"
  }, {
    "type" : "WEB",
    "url" : "https://groups.google.com/g/rubyonrails-security/c/n-p-W1yxatI"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2022/09/msg00002.html"
  }, {
    "type" : "WEB",
    "url" : "https://rubysec.com/advisories/CVE-2022-21831"
  }, {
    "type" : "WEB",
    "url" : "https://security.netapp.com/advisory/ntap-20221118-0001"
  }, {
    "type" : "WEB",
    "url" : "https://www.debian.org/security/2023/dsa-5372"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-94" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-03-08T21:25:54Z",
    "nvd_published_at" : "2022-05-26T17:15:00Z"
  }
}