CVE-2024-29034: CarrierWave content-Type allowlist bypass vulnerability leading to XSS
Summary
CVE-2024-29034: CarrierWave content-Type allowlist bypass vulnerability which possibly leads to XSS remained. Affects carrierwave across 2 version ranges.
< 2.2.6
>= 3.0.0, < 3.0.7
Fixed in 2.2.6 or 3.0.7, depending on the release line you run. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
CarrierWave is a RubyGem that provides a simple and efficient way to upload files from web applications to various storage services, including Amazon S3. It is widely used in Ruby on Rails applications to handle file uploads. The vulnerability in CarrierWave allows an attacker to bypass the content type allowlist and potentially execute cross-site scripting (XSS) attacks. This can lead to the injection of malicious code into web pages and compromise the security of the application.
Vulnerability Detail
The vulnerability arises from the ability to set a Content-Type value during file uploads that is different from what is allowed by the content_type_allowlist configuration. By providing multiple values separated by commas, an attacker can bypass the allowlist and upload files with malicious content types. This can be exploited to execute XSS attacks, where the injected code is executed by the victim's browser. This vulnerability has a CVSS score of 6.8, indicating a moderate level of severity.
How To Fix
Latest published version: 3.1.4 as of 23 Oct 2026
gem install carrierwave -v 3.1.4
Upgrading to it may include breaking changes; the versions below are the minimum fixed release for this vulnerability.
If you can't move to the latest
The minimum fixed version depends on the release line you run.
-
< 2.2.62.2.6gem install carrierwave -v 2.2.6 -
>= 3.0.0, < 3.0.73.0.7gem install carrierwave -v 3.0.7
Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →
Workaround
If upgrading to the patched versions is not immediately feasible, a temporary workaround can be implemented using a monkey patch. The following code can be added to the application to parse the Content-Type using Marcel::MimeType.for:
# For CarrierWave 3.x
CarrierWave::SanitizedFile.class_eval do
def declared_content_type
@declared_content_type ||
if @file.respond_to?(:content_type) && @file.content_type
Marcel::MimeType.for(declared_type: @file.content_type.to_s.chomp)
end
end
end
# For CarrierWave 2.x
CarrierWave::SanitizedFile.class_eval do
def existing_content_type
if @file.respond_to?(:content_type) && @file.content_type
Marcel::MimeType.for(declared_type: @file.content_type.to_s.chomp)
end
end
end
This workaround ensures that the Content-Type is correctly parsed and validated, mitigating the risk of the vulnerability.
Conclusion
The CarrierWave content-Type allowlist bypass vulnerability poses a risk of XSS attacks and compromise of web application security. It is crucial to upgrade to the patched versions or apply the provided workaround to mitigate this vulnerability. For further assistance and support in vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for carrierwave →
FAQ
CarrierWave is a RubyGem that provides file upload functionality for web applications, particularly in Ruby on Rails. It simplifies the process of handling file uploads to various storage services.
The vulnerability allows an attacker to bypass the content type allowlist and potentially execute cross-site scripting (XSS) attacks. This can lead to the injection of malicious code into web pages and compromise the security of the application.
To fix this vulnerability, it is recommended to upgrade to CarrierWave version 3.0.7 or 2.2.6. These versions include patches that address the content-Type allowlist bypass.
Yes, a temporary workaround can be implemented using a monkey patch. The provided code snippet demonstrates how to parse the Content-Type using Marcel::MimeType.for.
The CVSS score of this vulnerability is 6.8, indicating a moderate level of severity.
References
Related vulnerabilities
Recent vulnerabilities recorded for carrierwave.