CVE-2021-21305: Carrierwave :RMagick Vulnerability

HIGH
Advisory Identifier: GHSA-cf3w-g86h-35x4
CVSS 7.4
CWE-94 CWE-74
Published
Advisory Summary

CVE-2021-21305 is a HIGH (CVSS 7.4) :rmagick vulnerability (CWE-94: Improper Control of Generation of Code ('Code Injection')) affecting Carrierwave libraries in the RubyGems ecosystem. The issue involves :rmagick. Remediation is available by upgrading affected packages to version 1.3.2, 2.1.1.

CVE-2021-21305 at a Glance

CVE Identifier CVE-2021-21305
GHSA Identifier GHSA-cf3w-g86h-35x4
Severity HIGH
CVSS v3.1 Base Score 7.4
CWE Classification CWE-94: Improper Control of Generation of Code ('Code Injection')
Affected Product Carrierwave
Package Ecosystem RubyGems
Published Date
Last Updated

Security Impact

CVSS: 7.4

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:C/C:L/I:L/A:L).

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

How to Fix CVE-2021-21305

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

carrierwave fixed: 1.3.2
Upgrade carrierwave to 1.3.2
carrierwave fixed: 2.1.1
Upgrade carrierwave to 2.1.1
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 carrierwave

How to Check if You Are Affected

To determine whether your application is affected by CVE-2021-21305, inspect your project dependencies for Carrierwave:

inspect dependencies for carrierwave

Analyze the terminal output to locate any version of Carrierwave in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.3.2), 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 Carrierwave, 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

### Impact [CarrierWave::RMagick](https://github.com/carrierwaveuploader/carrierwave/blob/master/lib/carrierwave/processing/rmagick.rb) has a Code Injection vulnerability. Its `#manipulate!` method inappropriately evals the content of mutation option(`:read`/`:write`), allowing attackers to craft a string that can be executed as a Ruby code. If an application developer supplies untrusted inputs to the option, it will lead to remote code execution(RCE). (But supplying untrusted input to the option itself is dangerous even in absence of this vulnerability, since is prone to DoS vulnerability - attackers can try to consume massive amounts of memory by resizing to a very large dimension) ### Proof of Concept ```ruby class MyUploader < CarrierWave::Uploader::Base include CarrierWave::RMagick end MyUploader.new.manipulate!({ read: { density: "1 }; p 'Hacked'; {" }}) # => shows "Hacked" ``` ### Patches Upgrade to [2.1.1](https://rubygems.org/gems/carrierwave/versions/2.1.1) or [1.3.2](https://rubygems.org/gems/carrierwave/versions/1.3.2). ### Workarounds Stop supplying untrusted input to `#manipulate!`'s mutation option. ### References [Code Injection Software Attack](https://owasp.org/www-community/attacks/Code_Injection) ### For more information If you have any questions or comments about this advisory: * Open an issue in [CarrierWave repo](https://github.com/carrierwaveuploader/carrierwave) * Email me at [mit.shibuya@gmail.com](mailto:mit.shibuya@gmail.com)

CVE-2021-21305 Affected Carrierwave Versions

2 component(s)
Fixed Versions:
1.3.22.1.1
Product / Package Ecosystem Affected Versions Fixed Version
carrierwave
RubyGems
< 1.3.2
1.3.2
carrierwave
RubyGems
≥ 2.0.0
< 2.1.1
2.1.1

References

Frequently Asked Questions

What is CVE-2021-21305?
CVE-2021-21305 is a security vulnerability in Carrierwave involving :RMagick under CWE-94: Improper Control of Generation of Code ('Code Injection').
Which Carrierwave versions are affected?
Affected versions include releases prior to 1.3.2, 2.1.1 across affected packages: carrierwave.
What version fixes CVE-2021-21305?
Upgrading to 1.3.2, 2.1.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is carrierwave affected?
Yes, carrierwave is affected in releases prior to 1.3.2, 2.1.1. Upgrade your dependency to 1.3.2, 2.1.1 or later.
What is the CVSS score of CVE-2021-21305?
CVE-2021-21305 has a CVSS v3.1 base score of 7.4 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:L/I:L/A:L.
What CWE is associated with CVE-2021-21305?
CVE-2021-21305 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-2021-21305?
Run the dependency tree command: 'inspect dependencies for carrierwave'. 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-cf3w-g86h-35x4",
  "modified" : "2022-04-27T19:58:17Z",
  "published" : "2021-02-08T19:16:39Z",
  "aliases" : [ "CVE-2021-21305" ],
  "summary" : "Code Injection vulnerability in CarrierWave::RMagick",
  "details" : "### Impact\n[CarrierWave::RMagick](https://github.com/carrierwaveuploader/carrierwave/blob/master/lib/carrierwave/processing/rmagick.rb) has a Code Injection vulnerability. Its `#manipulate!` method inappropriately evals the content of mutation option(`:read`/`:write`), allowing attackers to craft a string that can be executed as a Ruby code.\nIf an application developer supplies untrusted inputs to the option, it will lead to remote code execution(RCE).\n\n(But supplying untrusted input to the option itself is dangerous even in absence of this vulnerability, since is prone to DoS vulnerability - attackers can try to consume massive amounts of memory by resizing to a very large dimension)\n\n### Proof of Concept\n```ruby\nclass MyUploader < CarrierWave::Uploader::Base\n  include CarrierWave::RMagick\nend\n\nMyUploader.new.manipulate!({ read: { density: \"1 }; p 'Hacked'; {\" }}) # => shows \"Hacked\"\n```\n\n### Patches\nUpgrade to [2.1.1](https://rubygems.org/gems/carrierwave/versions/2.1.1) or [1.3.2](https://rubygems.org/gems/carrierwave/versions/1.3.2).\n\n### Workarounds\nStop supplying untrusted input to `#manipulate!`'s mutation option.\n\n### References\n[Code Injection Software Attack](https://owasp.org/www-community/attacks/Code_Injection)\n\n### For more information\nIf you have any questions or comments about this advisory:\n* Open an issue in [CarrierWave repo](https://github.com/carrierwaveuploader/carrierwave)\n* Email me at [mit.shibuya@gmail.com](mailto:mit.shibuya@gmail.com)",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:L/I:L/A:L"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "carrierwave"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.3.2"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "carrierwave"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.0.0"
      }, {
        "fixed" : "2.1.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/carrierwaveuploader/carrierwave/security/advisories/GHSA-cf3w-g86h-35x4"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-21305"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/carrierwaveuploader/carrierwave/commit/387116f5c72efa42bc3938d946b4c8d2f22181b7"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/carrierwaveuploader/carrierwave"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/carrierwaveuploader/carrierwave/blob/master/CHANGELOG.md#132---2021-02-08"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/carrierwaveuploader/carrierwave/blob/master/CHANGELOG.md#211---2021-02-08"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rubysec/ruby-advisory-db/blob/master/gems/carrierwave/CVE-2021-21305.yml"
  }, {
    "type" : "WEB",
    "url" : "https://rubygems.org/gems/carrierwave"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-74", "CWE-94" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-02-08T18:51:46Z",
    "nvd_published_at" : "2021-02-08T20:15:00Z"
  }
}