diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2020-01-04 01:54:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-04 01:54:07 +0100 |
commit | 49b2f7c0a2aa41b1da77b652415078e19fcdcad8 (patch) | |
tree | 946b9723a03e26b3b3f403b83f10a198ffa1ea48 /app/models | |
parent | 500276c99bfba2a74e177f46d27d020e3f06a719 (diff) |
Fix base64-encoded file uploads not being possible (#12748)
Fix #3804, Fix #5776
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/concerns/attachmentable.rb | 11 | ||||
-rw-r--r-- | app/models/media_attachment.rb | 3 |
2 files changed, 14 insertions, 0 deletions
diff --git a/app/models/concerns/attachmentable.rb b/app/models/concerns/attachmentable.rb index 3bbc6453c..1e8c4806f 100644 --- a/app/models/concerns/attachmentable.rb +++ b/app/models/concerns/attachmentable.rb @@ -9,6 +9,7 @@ module Attachmentable GIF_MATRIX_LIMIT = 921_600 # 1280x720px included do + before_post_process :obfuscate_file_name before_post_process :set_file_extensions before_post_process :check_image_dimensions before_post_process :set_file_content_type @@ -68,4 +69,14 @@ module Attachmentable rescue Terrapin::CommandLineError '' end + + def obfuscate_file_name + self.class.attachment_definitions.each_key do |attachment_name| + attachment = send(attachment_name) + + next if attachment.blank? + + attachment.instance_write :file_name, SecureRandom.hex(8) + File.extname(attachment.instance_read(:file_name)) + end + end end diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index 573ef5dfc..1fd0adfd0 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -202,9 +202,12 @@ class MediaAttachment < ApplicationRecord end after_commit :reset_parent_cache, on: :update + before_create :prepare_description, unless: :local? before_create :set_shortcode + before_post_process :set_type_and_extension + before_save :set_meta class << self |