|
| 1 | +--- |
| 2 | +gem: carrierwave |
| 3 | +cve: 2024-29034 |
| 4 | +ghsa: vfmv-jfc5-pjjw |
| 5 | +url: https://github.com/carrierwaveuploader/carrierwave/security/advisories/GHSA-vfmv-jfc5-pjjw |
| 6 | +title: CarrierWave content-Type allowlist bypass vulnerability |
| 7 | + which possibly leads to XSS remained |
| 8 | +date: 2024-03-25 |
| 9 | +description: | |
| 10 | + ### Impact |
| 11 | +
|
| 12 | + The vulnerability [CVE-2023-49090](https://github.com/carrierwaveuploader/carrierwave/security/advisories/GHSA-gxhx-g4fq-49hj) |
| 13 | + wasn't fully addressed. |
| 14 | +
|
| 15 | + This vulnerability is caused by the fact that when uploading to |
| 16 | + object storage, including Amazon S3, it is possible to set a |
| 17 | + Content-Type value that is interpreted by browsers to be different |
| 18 | + from what's allowed by `content_type_allowlist`, by providing |
| 19 | + multiple values separated by commas. |
| 20 | +
|
| 21 | + This bypassed value can be used to cause XSS. |
| 22 | +
|
| 23 | + ### Patches |
| 24 | +
|
| 25 | + Upgrade to [3.0.7](https://rubygems.org/gems/carrierwave/versions/3.0.7) or [2.2.6](https://rubygems.org/gems/carrierwave/versions/2.2.6). |
| 26 | +
|
| 27 | + ### Workarounds |
| 28 | + Use the following monkey patch to let CarrierWave parse the |
| 29 | + Content-type by using `Marcel::MimeType.for`. |
| 30 | +
|
| 31 | + ```ruby |
| 32 | + # For CarrierWave 3.x |
| 33 | + CarrierWave::SanitizedFile.class_eval do |
| 34 | + def declared_content_type |
| 35 | + @declared_content_type || |
| 36 | + if @file.respond_to?(:content_type) && @file.content_type |
| 37 | + Marcel::MimeType.for(declared_type: @file.content_type.to_s.chomp) |
| 38 | + end |
| 39 | + end |
| 40 | + end |
| 41 | + ``` |
| 42 | +
|
| 43 | + ```ruby |
| 44 | + # For CarrierWave 2.x |
| 45 | + CarrierWave::SanitizedFile.class_eval do |
| 46 | + def existing_content_type |
| 47 | + if @file.respond_to?(:content_type) && @file.content_type |
| 48 | + Marcel::MimeType.for(declared_type: @file.content_type.to_s.chomp) |
| 49 | + end |
| 50 | + end |
| 51 | + end |
| 52 | + ``` |
| 53 | +
|
| 54 | + ### References |
| 55 | +
|
| 56 | + [OWASP - File Upload Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/File_Upload_Cheat_Sheet.html#content-type-validation) |
| 57 | +
|
| 58 | +cvss_v3: 6.8 |
| 59 | +patched_versions: |
| 60 | + - "~> 2.2.6" |
| 61 | + - ">= 3.0.7" |
| 62 | +related: |
| 63 | + url: |
| 64 | + - https://nvd.nist.gov/vuln/detail/CVE-2024-29034 |
| 65 | + - https://github.com/carrierwaveuploader/carrierwave/security/advisories/GHSA-vfmv-jfc5-pjjw |
| 66 | + - https://github.com/carrierwaveuploader/carrierwave/commit/25b1c800d45ef8e78dc445ebe3bd8a6e3f0a3477 |
| 67 | + - https://github.com/advisories/GHSA-vfmv-jfc5-pjjw |
0 commit comments