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

Ensure max expires_in is less than 604800

Oliver Güntherdbb22fb55a79
diff --git a/app/uploaders/fog_file_uploader.rb b/app/uploaders/fog_file_uploader.rb
index 0a6ff8487fe..ecff0bca84e 100644
--- a/app/uploaders/fog_file_uploader.rb
+++ b/app/uploaders/fog_file_uploader.rb
@@ -104,7 +104,9 @@ class FogFileUploader < CarrierWave::Uploader::Base
def set_expires_at!(url_options, options:)
if options[:expires_in].present?
- url_options[:expire_at] = ::Fog::Time.now + options[:expires_in]
+ # AWS allows at max < 604800 expires time
+ expires = [options[:expires_in], 604799].min
+ url_options[:expire_at] = ::Fog::Time.now + expires
end
if options[:expires_at].present?
diff --git a/spec/models/attachment_spec.rb b/spec/models/attachment_spec.rb
index 8c3c039ec00..cc8f9a1c53b 100644
--- a/spec/models/attachment_spec.rb
+++ b/spec/models/attachment_spec.rb
@@ -276,6 +276,14 @@ describe Attachment, type: :model do
expect(query).to include "X-Amz-Expires=3600"
end
end
+
+ context 'with expiry time exeeding maximum' do
+ let(:url_options) { { expires_in: 1.year } }
+
+ it "uses the allowed max" do
+ expect(query).to include "X-Amz-Expires=604799"
+ end
+ end
end
describe "for an image file" do