CVE-2021-21305 — Code Injection vulnerability in carrierwave
Code Injection vulnerability in CarrierWave::RMagick
What Should I Do?
Low-to-Moderate Risk
Exploitation probability is 13.21% in 30 days. Address in your next planned sprint.
Does your project use an affected carrierwave version?
Paste your Gemfile.lock to check it for CVE-2021-21305 and every other known vulnerability, with CISA KEV and EPSS on each finding. Free with no signup for up to 10 packages, or up to 500 per scan with a free account, which also keeps up to 200 packages in saved projects.
Summary
Impact
CarrierWave::RMagick 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
class MyUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
end
MyUploader.new.manipulate!({ read: { density: "1 }; p 'Hacked'; {" }}) # => shows "Hacked"
Patches
Workarounds
Stop supplying untrusted input to #manipulate!'s mutation option.
References
Code Injection Software Attack
For more information
If you have any questions or comments about this advisory:
- Open an issue in CarrierWave repo
- Email me at mit.shibuya@gmail.com
Advisory Timeline
- First published February 8, 2021 (2117 days ago).
- Last revised July 8, 2026 — 1975 days after initial publication.
Remediation
Upgrade to the fixed version using your package manager.
gem install carrierwave -v 1.3.2
gem install carrierwave -v 2.1.1
After upgrading, scan your dependencies again to confirm the vulnerability is resolved.
Affected Packages (2)
Affects 1 ecosystem: RubyGems (1).
| Package | Fixed In |
|---|---|
| carrierwave RubyGems · Affected: 0.1, 0.10.0, 0.11.0, 0.11.1 (+51 more) | 1.3.2 |
| carrierwave RubyGems · Affected: 2.0.0, 2.0.1, 2.0.2, 2.1.0 | 2.1.1 |
Vulnerability Classification
Common Weakness Enumeration (CWE) identifiers for this vulnerability type.
- CWE-74
- CWE-94Code InjectionMITRE
CVSS Score Breakdown
What the CVSS (Common Vulnerability Scoring System) 7.4 score means for each attack dimension.
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:L/I:L/A:L
References
- https://github.com/carrierwaveuploader/carrierwave/security/advisories/GHSA-cf3w-g86h-35x4WEB
- https://nvd.nist.gov/vuln/detail/CVE-2021-21305ADVISORY
- https://github.com/carrierwaveuploader/carrierwave/commit/387116f5c72efa42bc3938d946b4c8d2f22181b7WEB
- https://github.com/carrierwaveuploader/carrierwavePACKAGE
- https://github.com/carrierwaveuploader/carrierwave/blob/master/CHANGELOG.md#132---2021-02-08WEB
- https://github.com/carrierwaveuploader/carrierwave/blob/master/CHANGELOG.md#211---2021-02-08WEB
- https://github.com/rubysec/ruby-advisory-db/blob/master/gems/carrierwave/CVE-2021-21305.ymlWEB
- https://rubygems.org/gems/carrierwaveWEB
Frequently Asked Questions
- What is CVE-2021-21305?
- Code Injection vulnerability in CarrierWave::RMagick. This vulnerability has been assigned a severity rating of HIGH (CVSS score: 7.4/10).
- How do I check if my project is affected by CVE-2021-21305?
- CVE-2021-21305 affects carrierwave. It has a 13.2% probability of exploitation within 30 days (EPSS score). Use GeekWala's free vulnerability scanner to check your dependencies against CVE-2021-21305 and 200,000+ other known vulnerabilities.
Severity & Exploitability
Significant impact if exploited, or exploitable with modest effort.
This places it in the top 5% of EPSS-scored vulnerabilities — 97.1% of tracked vulnerabilities score at or below it, so it is far more likely to be exploited than nearly all other tracked vulnerabilities.
Also Known As
Related CVEs
- CVE-2026-126366HIGH
msgpack-ruby JRuby decoder makes uncapped header-count allocations; a 5-byte message forces multi-GiB OOM
- CVE-2026-126081HIGH
Action Pack: Possible Strong Parameters Bypass in Parameters#each_key
- CVE-2026-44587MEDIUM
CarrierWave has a denylisted_content_type bypass via Unescaped Regex Metacharacters
- CVE-2023-49090MEDIUM
CarrierWave Content-Type allowlist bypass vulnerability, possibly leading to XSS
- CVE-2024-29034MEDIUM
CarrierWave content-Type allowlist bypass vulnerability which possibly leads to XSS remained