The vulnerability exists in the CarrierWave gem because it fails to properly sanitize user-provided content type strings before using them in a regular expression for its denylist (or blacklist) feature. Specifically, the denylisted_content_type? and blacklisted_content_type? functions directly interpolate strings from the denylist into a regex. This allows an attacker to use a content type with a regex metacharacter, such as image/svg+xml, where the + is interpreted as a quantifier ('one or more of the preceding character') rather than a literal plus sign. As a result, the regex fails to match the intended content type, and the denylist is bypassed, potentially leading to Cross-Site Scripting (XSS) if a malicious SVG file is uploaded.
The patch addresses this by applying Regexp.quote to the denylist items before they are used in the regex, ensuring that any special characters are treated as literals. The analysis of the patch commits 21221cc and 4c4a005 confirms these changes in lib/carrierwave/uploader/content_type_denylist.rb and lib/carrierwave/uploader/content_type_blacklist.rb, respectively. The functions check_content_type_denylist! and check_content_type_blacklist! are the entry points that trigger these vulnerable checks and would appear in a runtime profile during exploitation.