]> cat aescling's git repositories - mastodon.git/commitdiff
Fix CSP when dealing with S3 hosts
authorThibaut Girka <thib@sitedethib.com>
Fri, 3 May 2019 22:14:49 +0000 (00:14 +0200)
committerThibG <thib@sitedethib.com>
Fri, 3 May 2019 22:47:51 +0000 (00:47 +0200)
config/initializers/content_security_policy.rb

index 12b764a5a8a2e89076ac28b8d02af97591f8ec17..9da38598b2b227b64fca1de8335df37cfca6f530 100644 (file)
@@ -7,9 +7,11 @@ if Rails.env.production?
   data_hosts = [assets_host]
 
   if ENV['S3_ENABLED'] == 'true'
-    attachments_host = ENV['S3_ALIAS_HOST'] || ENV['S3_CLOUDFRONT_HOST'] || ENV['S3_HOSTNAME'] || "s3-#{ENV['S3_REGION'] || 'us-east-1'}.amazonaws.com"
+    attachments_host = "https://#{ENV['S3_ALIAS_HOST'] || ENV['S3_CLOUDFRONT_HOST'] || ENV['S3_HOSTNAME'] || "s3-#{ENV['S3_REGION'] || 'us-east-1'}.amazonaws.com"}"
+    attachments_host = "https://#{Addressable::URI.parse(attachments_host).host}"
   elsif ENV['SWIFT_ENABLED'] == 'true'
     attachments_host = ENV['SWIFT_OBJECT_URL']
+    attachments_host = "https://#{Addressable::URI.parse(attachments_host).host}"
   else
     attachments_host = nil
   end