CarrierWave's Content-Type allowlist bypass vulnerability which possibly leads to XSS remained
Description
CarrierWave is a solution for file uploads for Rails, Sinatra and other Ruby web frameworks. The vulnerability CVE-2023-49090 wasn't fully addressed. This vulnerability is caused by the fact that when uploading to object storage, including Amazon S3, it is possible to set a Content-Type value that is interpreted by browsers to be different from what's allowed by content_type_allowlist, by providing multiple values separated by commas. This bypassed value can be used to cause XSS. Upgrade to 3.0.7 or 2.2.6.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
carrierwaveRubyGems | >= 3.0.0, < 3.0.7 | 3.0.7 |
carrierwaveRubyGems | < 2.2.6 | 2.2.6 |
Affected products
1- Range: >= 3.0.0, < 3.0.7
Patches
125b1c800d45eFix Content-Type allowlist bypass vulnerability remained
3 files changed · +28 −17
lib/carrierwave/sanitized_file.rb+1 −1 modified@@ -307,7 +307,7 @@ def sanitize(name) def declared_content_type @declared_content_type || if @file.respond_to?(:content_type) && @file.content_type - @file.content_type.to_s.chomp + Marcel::MimeType.for(declared_type: @file.content_type.to_s.chomp) end end
spec/sanitized_file_spec.rb+27 −0 modified@@ -326,6 +326,33 @@ expect { sanitized_file.content_type }.not_to raise_error end + + it "uses the first one when multiple mime types are given using a semicolon" do + file = File.open(file_path("bork.txt")) + allow(file).to receive(:content_type) { 'image/png; text/html' } + + sanitized_file = CarrierWave::SanitizedFile.new(file) + + expect(sanitized_file.content_type).to eq("image/png") + end + + it "uses the first one when multiple mime types are given using a comma" do + file = File.open(file_path("bork.txt")) + allow(file).to receive(:content_type) { 'image/png, text/html' } + + sanitized_file = CarrierWave::SanitizedFile.new(file) + + expect(sanitized_file.content_type).to eq("image/png") + end + + it "drops content type parameters" do + file = File.open(file_path("bork.txt")) + allow(file).to receive(:content_type) { 'text/html; charset=utf-8' } + + sanitized_file = CarrierWave::SanitizedFile.new(file) + + expect(sanitized_file.content_type).to eq("text/html") + end end describe "#content_type=" do
spec/uploader/content_type_allowlist_spec.rb+0 −16 modified@@ -87,22 +87,6 @@ expect { uploader.cache!(bork_file) }.to raise_error(CarrierWave::IntegrityError) end end - - context "when the allowlist contains charset" do - before do - allow(uploader).to receive(:content_type_allowlist).and_return(%r{text/plain;\s*charset=utf-8}) - end - - it "accepts the content with allowed charset" do - allow(bork_file).to receive(:content_type).and_return('text/plain; charset=utf-8') - expect { uploader.cache!(bork_file) }.not_to raise_error - end - - it "rejects the content without charset" do - allow(bork_file).to receive(:content_type).and_return('text/plain') - expect { uploader.cache!(bork_file) }.to raise_error(CarrierWave::IntegrityError) - end - end end context "when there is a whitelist" do
Vulnerability mechanics
Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
5- github.com/advisories/GHSA-vfmv-jfc5-pjjwghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2024-29034ghsaADVISORY
- github.com/carrierwaveuploader/carrierwave/commit/25b1c800d45ef8e78dc445ebe3bd8a6e3f0a3477ghsax_refsource_MISCWEB
- github.com/carrierwaveuploader/carrierwave/security/advisories/GHSA-vfmv-jfc5-pjjwghsax_refsource_CONFIRMWEB
- github.com/rubysec/ruby-advisory-db/blob/master/gems/carrierwave/CVE-2024-29034.ymlghsaWEB
News mentions
0No linked articles in our index yet.