mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
Merge remote-tracking branch 'origin/2pcjn0j-files-format-vulnerability' into dev
This commit is contained in:
commit
68dc18a68d
@ -3,5 +3,5 @@
|
|||||||
# UserAvatar is the profile picture for an User
|
# UserAvatar is the profile picture for an User
|
||||||
class UserAvatar < Asset
|
class UserAvatar < Asset
|
||||||
include ImageValidatorConcern
|
include ImageValidatorConcern
|
||||||
mount_uploader :attachment, ProfilImageUploader
|
mount_uploader :attachment, UserAvatarUploader
|
||||||
end
|
end
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
module ContentTypeValidationFromFileContent
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
# overrides carrierwave methods to do a REAL mime type check based on content and not based on extension
|
||||||
|
|
||||||
|
included do
|
||||||
|
private
|
||||||
|
def check_content_type_whitelist!(new_file)
|
||||||
|
content_type = Marcel::MimeType.for Pathname.new(new_file.file)
|
||||||
|
|
||||||
|
if content_type_whitelist && content_type && !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
|
||||||
|
end
|
@ -8,6 +8,7 @@ class CustomAssetsUploader < CarrierWave::Uploader::Base
|
|||||||
# include CarrierWave::RMagick
|
# include CarrierWave::RMagick
|
||||||
# include CarrierWave::MiniMagick
|
# include CarrierWave::MiniMagick
|
||||||
include UploadHelper
|
include UploadHelper
|
||||||
|
include ContentTypeValidationFromFileContent
|
||||||
|
|
||||||
# Choose what kind of storage to use for this uploader:
|
# Choose what kind of storage to use for this uploader:
|
||||||
storage :file
|
storage :file
|
||||||
|
@ -6,6 +6,7 @@ class EventFileUploader < CarrierWave::Uploader::Base
|
|||||||
# include CarrierWave::RMagick
|
# include CarrierWave::RMagick
|
||||||
# include CarrierWave::MiniMagick
|
# include CarrierWave::MiniMagick
|
||||||
include UploadHelper
|
include UploadHelper
|
||||||
|
include ContentTypeValidationFromFileContent
|
||||||
|
|
||||||
# Choose what kind of storage to use for this uploader:
|
# Choose what kind of storage to use for this uploader:
|
||||||
storage :file
|
storage :file
|
||||||
|
@ -7,6 +7,7 @@ class EventImageUploader < CarrierWave::Uploader::Base
|
|||||||
# include CarrierWave::RMagick
|
# include CarrierWave::RMagick
|
||||||
include CarrierWave::MiniMagick
|
include CarrierWave::MiniMagick
|
||||||
include UploadHelper
|
include UploadHelper
|
||||||
|
include ContentTypeValidationFromFileContent
|
||||||
|
|
||||||
# Choose what kind of storage to use for this uploader:
|
# Choose what kind of storage to use for this uploader:
|
||||||
storage :file
|
storage :file
|
||||||
|
@ -6,6 +6,7 @@ class MachineFileUploader < CarrierWave::Uploader::Base
|
|||||||
# include CarrierWave::RMagick
|
# include CarrierWave::RMagick
|
||||||
# include CarrierWave::MiniMagick
|
# include CarrierWave::MiniMagick
|
||||||
include UploadHelper
|
include UploadHelper
|
||||||
|
include ContentTypeValidationFromFileContent
|
||||||
|
|
||||||
# Choose what kind of storage to use for this uploader:
|
# Choose what kind of storage to use for this uploader:
|
||||||
storage :file
|
storage :file
|
||||||
|
@ -7,6 +7,7 @@ class MachineImageUploader < CarrierWave::Uploader::Base
|
|||||||
# include CarrierWave::RMagick
|
# include CarrierWave::RMagick
|
||||||
include CarrierWave::MiniMagick
|
include CarrierWave::MiniMagick
|
||||||
include UploadHelper
|
include UploadHelper
|
||||||
|
include ContentTypeValidationFromFileContent
|
||||||
|
|
||||||
# Choose what kind of storage to use for this uploader:
|
# Choose what kind of storage to use for this uploader:
|
||||||
storage :file
|
storage :file
|
||||||
|
@ -6,6 +6,7 @@ class PlanFileUploader < CarrierWave::Uploader::Base
|
|||||||
# include CarrierWave::RMagick
|
# include CarrierWave::RMagick
|
||||||
# include CarrierWave::MiniMagick
|
# include CarrierWave::MiniMagick
|
||||||
include UploadHelper
|
include UploadHelper
|
||||||
|
include ContentTypeValidationFromFileContent
|
||||||
|
|
||||||
# Choose what kind of storage to use for this uploader:
|
# Choose what kind of storage to use for this uploader:
|
||||||
storage :file
|
storage :file
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
# This file defines the parameters for these uploads
|
# This file defines the parameters for these uploads
|
||||||
class ProjectCaoUploader < CarrierWave::Uploader::Base
|
class ProjectCaoUploader < CarrierWave::Uploader::Base
|
||||||
include UploadHelper
|
include UploadHelper
|
||||||
|
include ContentTypeValidationFromFileContent
|
||||||
|
|
||||||
# Choose what kind of storage to use for this uploader:
|
# Choose what kind of storage to use for this uploader:
|
||||||
storage :file
|
storage :file
|
||||||
@ -29,24 +30,4 @@ class ProjectCaoUploader < CarrierWave::Uploader::Base
|
|||||||
def content_type_whitelist
|
def content_type_whitelist
|
||||||
Setting.get('allowed_cad_mime_types').split(' ')
|
Setting.get('allowed_cad_mime_types').split(' ')
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def check_content_type_whitelist!(new_file)
|
|
||||||
content_type = Marcel::MimeType.for Pathname.new(new_file.file)
|
|
||||||
|
|
||||||
if content_type_whitelist && content_type && !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
|
end
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
class ProjectImageUploader < CarrierWave::Uploader::Base
|
class ProjectImageUploader < CarrierWave::Uploader::Base
|
||||||
include CarrierWave::MiniMagick
|
include CarrierWave::MiniMagick
|
||||||
include UploadHelper
|
include UploadHelper
|
||||||
|
include ContentTypeValidationFromFileContent
|
||||||
|
|
||||||
# Choose what kind of storage to use for this uploader:
|
# Choose what kind of storage to use for this uploader:
|
||||||
storage :file
|
storage :file
|
||||||
|
@ -8,6 +8,7 @@ class ProofOfIdentityFileUploader < CarrierWave::Uploader::Base
|
|||||||
# include CarrierWave::RMagick
|
# include CarrierWave::RMagick
|
||||||
# include CarrierWave::MiniMagick
|
# include CarrierWave::MiniMagick
|
||||||
include UploadHelper
|
include UploadHelper
|
||||||
|
include ContentTypeValidationFromFileContent
|
||||||
|
|
||||||
# Choose what kind of storage to use for this uploader:
|
# Choose what kind of storage to use for this uploader:
|
||||||
storage :file
|
storage :file
|
||||||
|
@ -6,6 +6,7 @@ class SpaceFileUploader < CarrierWave::Uploader::Base
|
|||||||
# include CarrierWave::RMagick
|
# include CarrierWave::RMagick
|
||||||
# include CarrierWave::MiniMagick
|
# include CarrierWave::MiniMagick
|
||||||
include UploadHelper
|
include UploadHelper
|
||||||
|
include ContentTypeValidationFromFileContent
|
||||||
|
|
||||||
# Choose what kind of storage to use for this uploader:
|
# Choose what kind of storage to use for this uploader:
|
||||||
storage :file
|
storage :file
|
||||||
|
@ -7,6 +7,7 @@ class SpaceImageUploader < CarrierWave::Uploader::Base
|
|||||||
# include CarrierWave::RMagick
|
# include CarrierWave::RMagick
|
||||||
include CarrierWave::MiniMagick
|
include CarrierWave::MiniMagick
|
||||||
include UploadHelper
|
include UploadHelper
|
||||||
|
include ContentTypeValidationFromFileContent
|
||||||
|
|
||||||
# Choose what kind of storage to use for this uploader:
|
# Choose what kind of storage to use for this uploader:
|
||||||
storage :file
|
storage :file
|
||||||
|
@ -7,6 +7,7 @@ class TrainingImageUploader < CarrierWave::Uploader::Base
|
|||||||
# include CarrierWave::RMagick
|
# include CarrierWave::RMagick
|
||||||
include CarrierWave::MiniMagick
|
include CarrierWave::MiniMagick
|
||||||
include UploadHelper
|
include UploadHelper
|
||||||
|
include ContentTypeValidationFromFileContent
|
||||||
|
|
||||||
# Choose what kind of storage to use for this uploader:
|
# Choose what kind of storage to use for this uploader:
|
||||||
storage :file
|
storage :file
|
||||||
|
@ -2,11 +2,12 @@
|
|||||||
|
|
||||||
# CarrierWave uploader for user's avatar.
|
# CarrierWave uploader for user's avatar.
|
||||||
# This file defines the parameters for these uploads.
|
# This file defines the parameters for these uploads.
|
||||||
class ProfilImageUploader < CarrierWave::Uploader::Base
|
class UserAvatarUploader < CarrierWave::Uploader::Base
|
||||||
# Include RMagick or MiniMagick support:
|
# Include RMagick or MiniMagick support:
|
||||||
# include CarrierWave::RMagick
|
# include CarrierWave::RMagick
|
||||||
include CarrierWave::MiniMagick
|
include CarrierWave::MiniMagick
|
||||||
include UploadHelper
|
include UploadHelper
|
||||||
|
include ContentTypeValidationFromFileContent
|
||||||
|
|
||||||
# Choose what kind of storage to use for this uploader:
|
# Choose what kind of storage to use for this uploader:
|
||||||
storage :file
|
storage :file
|
||||||
@ -59,7 +60,7 @@ class ProfilImageUploader < CarrierWave::Uploader::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def content_type_whitelist
|
def content_type_whitelist
|
||||||
[%r{image/}]
|
%w[image/jpeg image/gif image/png]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Override the filename of the uploaded files:
|
# Override the filename of the uploaded files:
|
Loading…
x
Reference in New Issue
Block a user