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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Bypass whitelist in internal services when conflicting with user
Oliver Günther15fc0846e6ca
diff --git a/app/services/attachments/create_service.rb b/app/services/attachments/create_service.rbindex 33f00f1586c..850f6c13e0e 100644--- a/app/services/attachments/create_service.rb+++ b/app/services/attachments/create_service.rb@@ -31,6 +31,18 @@ class Attachments::CreateService < ::BaseServices::Createaround_call :error_wrapped_call+ ##+ # Create an attachment service bypassing the user-provided whitelist+ # for internal purposes such as exporting data.+ #+ # @param user The user to call the service with+ # @param whitelist A custom whitelist to validate with, or empty to disable validation+ #+ # Warning: When passing an empty whitelist, this results in no validations on the content type taking place.+ def self.bypass_whitelist(user:, whitelist: [])+ new(user: user, contract_options: { whitelist: whitelist.map(&:to_s) })+ end+def persist(call)attachment = call.resultif attachment.containerdiff --git a/app/workers/backup_job.rb b/app/workers/backup_job.rbindex 964d5229ee2..9d951833398 100644--- a/app/workers/backup_job.rb+++ b/app/workers/backup_job.rb@@ -121,7 +121,7 @@ class BackupJob < ::ApplicationJobdef store_backup(file_name, backup:, user:)File.open(file_name) do |file|call = Attachments::CreateService- .new(user: user)+ .bypass_whitelist(user: user).call(container: backup, filename: file_name, file: file, description: 'OpenProject backup')call.on_success dodiff --git a/app/workers/work_packages/exports/export_job.rb b/app/workers/work_packages/exports/export_job.rbindex c0a4544b052..ea09c48680d 100644--- a/app/workers/work_packages/exports/export_job.rb+++ b/app/workers/work_packages/exports/export_job.rb@@ -90,7 +90,7 @@ module WorkPackagesdef store_attachment(container, file)call = Attachments::CreateService- .new(user: User.current)+ .bypass_whitelist(user: User.current).call(container: container, file: file, filename: File.basename(file), description: '')call.on_success dodiff --git a/modules/bim/app/controllers/bim/bcf/issues_controller.rb b/modules/bim/app/controllers/bim/bcf/issues_controller.rbindex 6c5a33097e7..3d3269dd641 100644--- a/modules/bim/app/controllers/bim/bcf/issues_controller.rb+++ b/modules/bim/app/controllers/bim/bcf/issues_controller.rb@@ -215,7 +215,7 @@ module Bimdef create_attachmentfilename = params[:bcf_file].original_filenamecall = Attachments::CreateService- .new(user: current_user)+ .bypass_whitelist(user: current_user, whitelist: %w[application/zip]).call(file: params[:bcf_file],filename: filename,description: filename)diff --git a/modules/bim/app/models/bim/ifc_models/ifc_model.rb b/modules/bim/app/models/bim/ifc_models/ifc_model.rbindex 807606a8bd1..940acb76fe1 100644--- a/modules/bim/app/models/bim/ifc_models/ifc_model.rb+++ b/modules/bim/app/models/bim/ifc_models/ifc_model.rb@@ -26,7 +26,7 @@ module Bimdelete_attachment namecall = ::Attachments::CreateService- .new(user: User.current)+ .bypass_whitelist(user: User.current).call(file: file, container: self, filename: file.original_filename, description: name)call.on_failure { Rails.logger.error "Failed to add #{name} attachment: #{call.message}" }