VYPR
Moderate severityNVD Advisory· Published Mar 24, 2024· Updated Aug 2, 2024

CarrierWave's Content-Type allowlist bypass vulnerability which possibly leads to XSS remained

CVE-2024-29034

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.

PackageAffected versionsPatched versions
carrierwaveRubyGems
>= 3.0.0, < 3.0.73.0.7
carrierwaveRubyGems
< 2.2.62.2.6

Affected products

1

Patches

1
25b1c800d45e

Fix Content-Type allowlist bypass vulnerability remained

https://github.com/carrierwaveuploader/carrierwaveMitsuhiro ShibuyaMar 20, 2024via ghsa
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

News mentions

0

No linked articles in our index yet.