mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-19 13:54:25 +01:00
check the file content with mimemagic for project CAD files
This commit is contained in:
parent
2082f1e11c
commit
a5e1b77ce4
@ -29,4 +29,26 @@ class ProjectCaoUploader < CarrierWave::Uploader::Base
|
||||
def content_type_whitelist
|
||||
ENV['ALLOWED_MIME_TYPES'].split(' ')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_content_type_whitelist!(new_file)
|
||||
require 'mimemagic'
|
||||
|
||||
content_type = MimeMagic.by_magic(File.open(new_file.file))
|
||||
|
||||
if content_type_whitelist && !whitelisted_content_type?(content_type)
|
||||
raise CarrierWave::IntegrityError,
|
||||
I18n.translate(:'errors.messages.content_type_whitelist_error',
|
||||
content_type: content_type,
|
||||
allowed_types: Array(content_type_whitelist).join(', '))
|
||||
end
|
||||
end
|
||||
|
||||
def whitelisted_content_type?(content_type)
|
||||
Array(content_type_whitelist).any? do |item|
|
||||
item = Regexp.quote(item) if item.class != Regexp
|
||||
content_type =~ /#{item}/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -18,6 +18,7 @@ en:
|
||||
carrierwave_download_error: "could not be downloaded"
|
||||
extension_whitelist_error: "You are not allowed to upload %{extension} files, allowed types: %{allowed_types}"
|
||||
extension_blacklist_error: "You are not allowed to upload %{extension} files, prohibited types: %{prohibited_types}"
|
||||
content_type_whitelist_error: "You are not allowed to upload %{content_type} files, allowed types: %{allowed_types}"
|
||||
rmagick_processing_error: "Failed to manipulate with rmagick, maybe it is not an image? Original Error: %{e}"
|
||||
mime_types_processing_error: "Failed to process file with MIME::Types, maybe not valid content-type? Original Error: %{e}"
|
||||
mini_magick_processing_error: "Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: %{e}"
|
||||
|
@ -18,6 +18,7 @@ fr:
|
||||
carrierwave_download_error: "ne peut pas être téléchargé"
|
||||
extension_whitelist_error: "Vous n'êtes pas autorisé à envoyer des fichiers %{extension}, les types autorisés sont : %{allowed_types}"
|
||||
extension_blacklist_error: "Vous n'êtes pas autorisé à envoyer des fichiers %{extension}, les types interdits sont : %{prohibited_types}"
|
||||
content_type_whitelist_error: "Vous n'êtes pas autorisé à envoyer des fichiers de type %{content_type}, les types autorisés sont : %{allowed_types}"
|
||||
rmagick_processing_error: "La manipulation avec rmagick a échoué, peut-être ne s'agit-il pas d'une image ? Erreur d'origine : %{e}"
|
||||
mime_types_processing_error: "Le traitement avec MIME::Types a échoué, le content-type est-il correct ? Erreur d'origine : %{e}"
|
||||
mini_magick_processing_error: "La manipulation avec MiniMagick a échoué, peut-être ne s'agit-il pas d'une image ? Erreur d'origine : %{e}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user