New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug with content type detection #2424
Comments
This is intentional, see #1942. |
I understand, but for some reason it breaks CSV files detection. |
Hi there! Any news? |
I have the same problem with CSV and plain text files. |
Example :
The original plot about using MimeMagic was to mitigate a CVE on images files, right ? type = File.open(path) do |file|
MimeMagic.by_magic(file)&.type
end
if type.match?('image/') && type != MimeMagic.by_path(path)&.type
type = 'invalid/invalid'
end
type |
Has anyone worked on a workaround on this? I used Mini Mime to fetch the content_type as set it manually. |
class DocumentUploader < CarrierWave::Uploader::Base
def content_type
type = super
# FIXME: https://github.com/carrierwaveuploader/carrierwave/pull/2474
if type == 'invalid/invalid'
type = ::MiniMime.lookup_by_filename(path).try(:content_type)
type = 'invalid/invalid' unless type.nil? || type.start_with?('text/')
end
# Carrierwave always returns a string, even when content type is missing
type.to_s
end
end |
Hi there!
I think it should be nil here :
carrierwave/lib/carrierwave/sanitized_file.rb
Line 334 in d12a289
(like in the rescue block) to let
mini_mime_content_type
have a chance to find the right mime type.The text was updated successfully, but these errors were encountered: