A platform for community discussion. Free, open, simple.
FIX: Use random file name for temporary uploads (#14250)
Martin Brennandd4b8c2afaa9
diff --git a/lib/file_store/base_store.rb b/lib/file_store/base_store.rbindex 865929e3b63..788e6cd5936 100644--- a/lib/file_store/base_store.rb+++ b/lib/file_store/base_store.rb@@ -42,12 +42,16 @@ module FileStoreenddef temporary_upload_path(file_name, folder_prefix: "")+ # We don't want to use the original file name as it can contain special+ # characters, which can interfere with external providers operations and+ # introduce other unexpected behaviour.+ file_name_random = "#{SecureRandom.hex}#{File.extname(file_name)}"File.join(TEMPORARY_UPLOAD_PREFIX,folder_prefix,upload_path,SecureRandom.hex,- file_name+ file_name_random)enddiff --git a/spec/multisite/s3_store_spec.rb b/spec/multisite/s3_store_spec.rbindex e86535f441a..17eb47f5557 100644--- a/spec/multisite/s3_store_spec.rb+++ b/spec/multisite/s3_store_spec.rb@@ -313,7 +313,7 @@ RSpec.describe 'Multisite s3 uploads', type: :multisite dourl = store.signed_url_for_temporary_upload("test.png")key = store.path_from_url(url)expect(url).to match(/Amz-Expires/)- expect(key).to match(/temp\/uploads\/default\/test_[0-9]\/[a-zA-z0-9]{0,32}\/test.png/)+ expect(key).to match(/temp\/uploads\/default\/test_[0-9]\/[a-zA-z0-9]{0,32}\/[a-zA-z0-9]{0,32}.png/)endit "presigned url contans the metadata when provided" do@@ -329,7 +329,7 @@ RSpec.describe 'Multisite s3 uploads', type: :multisite dourl = store.signed_url_for_temporary_upload("test.png")key = store.path_from_url(url)expect(url).to match(/Amz-Expires/)- expect(key).to match(/temp\/site\/uploads\/default\/test_[0-9]\/[a-zA-z0-9]{0,32}\/test.png/)+ expect(key).to match(/temp\/site\/uploads\/default\/test_[0-9]\/[a-zA-z0-9]{0,32}\/[a-zA-z0-9]{0,32}.png/)endend@@ -341,7 +341,7 @@ RSpec.describe 'Multisite s3 uploads', type: :multisite dourl = store.signed_url_for_temporary_upload("test.png")key = store.path_from_url(url)expect(url).to match(/Amz-Expires/)- expect(key).to match(/temp\/standard99\/uploads\/second\/test_[0-9]\/[a-zA-z0-9]{0,32}\/test.png/)+ expect(key).to match(/temp\/standard99\/uploads\/second\/test_[0-9]\/[a-zA-z0-9]{0,32}\/[a-zA-z0-9]{0,32}.png/)endendend