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

[#64356] Image not visible in PDF export

as-op7695264b7fa6
diff --git a/app/models/exports/pdf/common/attachments.rb b/app/models/exports/pdf/common/attachments.rb
index cb71e840909..dbe6780b993 100644
--- a/app/models/exports/pdf/common/attachments.rb
+++ b/app/models/exports/pdf/common/attachments.rb
@@ -87,14 +87,17 @@ module Exports::PDF::Common::Attachments
end
def attachment_by_api_content_src(src)
- attachment_regex = %r{/attachments/(\d+)/content}
- return nil unless src&.match?(attachment_regex)
+ return nil if src.empty?
- attachments_id = src.scan(attachment_regex).first.first
-
- # return nil if the src is not an attachment url
- return nil unless api_url_helpers.attachment_content(attachments_id) == src
+ # we only accept absolute paths containing /attachments/:id/
+ # to prevent accessing hot-linked attachments from other hosts e.g. https://example.com/attachments/1/somefile.png
+ # we only accept sources like
+ # /api/v3/attachments/:id/content (our default api path)
+ # /attachments/:id/filename.ext (inserted by drag and drop from the files tab)
+ attachment_regex = %r{/attachments/(\d+)/}
+ return nil unless src.start_with?("/") && src.match?(attachment_regex)
+ attachments_id = src.scan(attachment_regex).first.first
attachment = Attachment.find_by(id: attachments_id.to_i)
return nil if attachment.nil?
return nil unless attachment.visible?