From 49b2f7c0a2aa41b1da77b652415078e19fcdcad8 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 4 Jan 2020 01:54:07 +0100 Subject: Fix base64-encoded file uploads not being possible (#12748) Fix #3804, Fix #5776 --- app/models/concerns/attachmentable.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'app/models/concerns/attachmentable.rb') 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 -- cgit From 3287ec8ca3bf8baad6cea0cc497753ff003d2d35 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 13 Jan 2020 12:54:33 +0100 Subject: Fix file names being obfuscated on update when file didn't change (#12857) Fix #12849 --- app/models/concerns/attachmentable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models/concerns/attachmentable.rb') diff --git a/app/models/concerns/attachmentable.rb b/app/models/concerns/attachmentable.rb index 1e8c4806f..43ff8ac12 100644 --- a/app/models/concerns/attachmentable.rb +++ b/app/models/concerns/attachmentable.rb @@ -74,7 +74,7 @@ module Attachmentable self.class.attachment_definitions.each_key do |attachment_name| attachment = send(attachment_name) - next if attachment.blank? + next if attachment.blank? || attachment.queued_for_write[:original].blank? attachment.instance_write :file_name, SecureRandom.hex(8) + File.extname(attachment.instance_read(:file_name)) end -- cgit