Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

s3 hosts differ for pre-signed form uploads and downloads

Markus Kahl939f1d1df786
diff --git a/config/initializers/secure_headers.rb b/config/initializers/secure_headers.rb
index dfb343a85b6..6d3c231fe45 100644
--- a/config/initializers/secure_headers.rb
+++ b/config/initializers/secure_headers.rb
@@ -21,7 +21,7 @@ SecureHeaders::Configuration.default do |config|
frame_src << OpenProject::Configuration[:security_badge_url]
# Default src
- default_src = %w('self') + [OpenProject::Configuration.remote_storage_host].compact
+ default_src = %w('self') + OpenProject::Configuration.remote_storage_hosts
# Allow requests to CLI in dev mode
connect_src = default_src
diff --git a/lib/open_project/configuration/helpers.rb b/lib/open_project/configuration/helpers.rb
index 058654b5e19..ebb3ffdbda4 100644
--- a/lib/open_project/configuration/helpers.rb
+++ b/lib/open_project/configuration/helpers.rb
@@ -76,12 +76,22 @@ module OpenProject
fog_credentials[:provider] == "AWS"
end
- def remote_storage_host
+ def remote_storage_upload_host
if remote_storage_aws?
"#{fog_directory}.s3.amazonaws.com"
end
end
+ def remote_storage_download_host
+ if remote_storage_aws?
+ "#{fog_directory}.s3.#{fog_credentials[:region]}.amazonaws.com"
+ end
+ end
+
+ def remote_storage_hosts
+ [remote_storage_upload_host, remote_storage_download_host].compact
+ end
+
def attachments_storage_path
Rails.root.join(self['attachments_storage_path'] || 'files')
end
diff --git a/spec/support/shared/with_direct_uploads.rb b/spec/support/shared/with_direct_uploads.rb
index c0ebd68325c..00e18793d4f 100644
--- a/spec/support/shared/with_direct_uploads.rb
+++ b/spec/support/shared/with_direct_uploads.rb
@@ -93,7 +93,7 @@ class WithDirectUploads
end
def stub_frontend(redirect: false)
- proxy.stub("https://" + OpenProject::Configuration.remote_storage_host + ":443/", method: 'options').and_return(
+ proxy.stub("https://" + OpenProject::Configuration.remote_storage_upload_host + ":443/", method: 'options').and_return(
headers: {
'Access-Control-Allow-Methods' => 'POST',
'Access-Control-Allow-Origin' => '*'
@@ -110,7 +110,7 @@ class WithDirectUploads
def stub_with_redirect
proxy
- .stub("https://" + OpenProject::Configuration.remote_storage_host + ":443/", method: 'post')
+ .stub("https://" + OpenProject::Configuration.remote_storage_upload_host + ":443/", method: 'post')
.and_return(Proc.new { |params, headers, body, url, method|
key = body.scan(/key"\s*([^\s]+)\s/m).flatten.first
redirect_url = body.scan(/success_action_redirect"\s*(http[^\s]+)\s/m).flatten.first
@@ -129,7 +129,7 @@ class WithDirectUploads
def stub_with_status
proxy
- .stub("https://" + OpenProject::Configuration.remote_storage_host + ":443/", method: 'post')
+ .stub("https://" + OpenProject::Configuration.remote_storage_upload_host + ":443/", method: 'post')
.and_return(Proc.new { |params, headers, body, url, method|
{
code: (body =~ /X-Amz-Signature/) ? 201 : 403, # check that the expected post to AWS was made with the form fields