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
rename to allowlist
ulferts0ecd09b06bea
diff --git a/app/contracts/attachments/create_contract.rb b/app/contracts/attachments/create_contract.rbindex 2ec0d41d3fe..a3be099f6bc 100644--- a/app/contracts/attachments/create_contract.rb+++ b/app/contracts/attachments/create_contract.rb@@ -68,29 +68,29 @@ module Attachmentsend##- # Validates the content type, if a whitelist is set+ # Validates the content type, if a allowlist is setdef validate_content_type- # If the whitelist is empty, assume all files are allowed+ # If the allowlist is empty, assume all files are allowed# as before- unless matches_whitelist?(attachment_whitelist)- Rails.logger.info { "Uploaded file #{model.filename} with type #{model.content_type} does not match whitelist" }- errors.add :content_type, :not_whitelisted, value: model.content_type+ unless matches_allowlist?(attachment_allowlist)+ Rails.logger.info { "Uploaded file #{model.filename} with type #{model.content_type} does not match allowlist" }+ errors.add :content_type, :not_allowlisted, value: model.content_typeendend##- # Get the user-defined whitelist or a custom whitelist+ # Get the user-defined allowlist or a custom allowlist# defined for this invocation- def attachment_whitelist- Array(options.fetch(:whitelist, Setting.attachment_whitelist))+ def attachment_allowlist+ Array(options.fetch(:allowlist, Setting.attachment_whitelist))end##- # Returns whether the attachment matches the whitelist- def matches_whitelist?(whitelist)- return true if whitelist.empty?+ # Returns whether the attachment matches the allowlist+ def matches_allowlist?(allowlist)+ return true if allowlist.empty?- whitelist.include?(model.content_type) || whitelist.include?("*#{model.extension}")+ allowlist.include?(model.content_type) || allowlist.include?("*#{model.extension}")endendenddiff --git a/app/services/attachments/base_service.rb b/app/services/attachments/base_service.rbindex 3ebf934fd84..fda62e662b3 100644--- a/app/services/attachments/base_service.rb+++ b/app/services/attachments/base_service.rb@@ -36,8 +36,8 @@ module Attachments# @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:, contract_options: { whitelist: whitelist.map(&:to_s) })+ def self.bypass_allowlist(user:, allowlist: [])+ new(user:, contract_options: { allowlist: allowlist.map(&:to_s) })endendenddiff --git a/app/workers/backup_job.rb b/app/workers/backup_job.rbindex 69e75e75b58..9be533fb694 100644--- a/app/workers/backup_job.rb+++ b/app/workers/backup_job.rb@@ -134,7 +134,7 @@ class BackupJob < ApplicationJobdef store_backup(file_name, backup:, user:)File.open(file_name) do |file|call = Attachments::CreateService- .bypass_whitelist(user:)+ .bypass_allowlist(user:).call(container: backup, filename: file_name, file:, description: "OpenProject backup")call.on_success dodiff --git a/app/workers/exports/export_job.rb b/app/workers/exports/export_job.rbindex 95b28bc110e..fac92e52533 100644--- a/app/workers/exports/export_job.rb+++ b/app/workers/exports/export_job.rb@@ -117,7 +117,7 @@ module Exportsfilename = clean_filename(export_result)call = Attachments::CreateService- .bypass_whitelist(user: User.current)+ .bypass_allowlist(user: User.current).call(container:, file:, filename:, description: "")call.on_success dodiff --git a/config/locales/en.yml b/config/locales/en.ymlindex c97dc0b8886..4674703d554 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -1286,7 +1286,7 @@ en:attributes:content_type:blank: "The content type of the file cannot be blank."- not_whitelisted: "The file was rejected by an automatic filter. '%{value}' is not whitelisted for upload."+ not_allowlisted: "The file was rejected by an automatic filter. '%{value}' is not allowed for upload."format: "%{message}"capability:context:diff --git a/modules/bim/app/controllers/bim/bcf/issues_controller.rb b/modules/bim/app/controllers/bim/bcf/issues_controller.rbindex 11949e96083..178b2a7cb77 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- .bypass_whitelist(user: current_user, whitelist: %w[application/zip])+ .bypass_allowlist(user: current_user, allowlist: %w[application/zip]).call(file: params[:bcf_file],filename:,description: filename)diff --git a/modules/bim/app/controllers/bim/ifc_models/ifc_models_controller.rb b/modules/bim/app/controllers/bim/ifc_models/ifc_models_controller.rbindex 32d47c39c97..af418af6e6b 100644--- a/modules/bim/app/controllers/bim/ifc_models/ifc_models_controller.rb+++ b/modules/bim/app/controllers/bim/ifc_models/ifc_models_controller.rb@@ -49,6 +49,10 @@ module Bim.includes(:project, :uploader)end+ def show+ frontend_redirect params[:id].to_i+ end+def new@ifc_model = @project.ifc_models.buildprepare_form(@ifc_model)@@ -58,10 +62,6 @@ module Bimprepare_form(@ifc_model)end- def show- frontend_redirect params[:id].to_i- end-def defaultsfrontend_redirect @ifc_models.defaults.pluck(:id).uniqend@@ -116,7 +116,7 @@ module Bimif service_result.success?::Attachments::FinishDirectUploadJob.perform_later attachment.id,- whitelist: false+ allowlist: falseflash[:notice] = if new_modelt("ifc_models.flash_messages.upload_successful")@@ -183,7 +183,7 @@ module Bimreturn unless OpenProject::Configuration.direct_uploads?call = ::Attachments::PrepareUploadService- .bypass_whitelist(user: current_user)+ .bypass_allowlist(user: current_user).call(filename: "model.ifc", filesize: 0)call.on_failure { flash[:error] = call.message }diff --git a/modules/bim/app/models/bim/bcf/viewpoint.rb b/modules/bim/app/models/bim/bcf/viewpoint.rbindex 668ed857a09..921a6ae134c 100644--- a/modules/bim/app/models/bim/bcf/viewpoint.rb+++ b/modules/bim/app/models/bim/bcf/viewpoint.rb@@ -73,7 +73,7 @@ module Bim::Bcfdef build_snapshot(file, user: User.current)::Attachments::BuildService- .bypass_whitelist(user:)+ .bypass_allowlist(user:).call(file:, container: self, filename: file.original_filename, description: "snapshot").resultenddiff --git a/modules/bim/app/models/bim/ifc_models/ifc_model.rb b/modules/bim/app/models/bim/ifc_models/ifc_model.rbindex e878716a430..307d0b2b139 100644--- a/modules/bim/app/models/bim/ifc_models/ifc_model.rb+++ b/modules/bim/app/models/bim/ifc_models/ifc_model.rb@@ -41,7 +41,7 @@ module Bimdelete_attachment namefilename = file.respond_to?(:original_filename) ? file.original_filename : File.basename(file.path)call = ::Attachments::CreateService- .bypass_whitelist(user: User.current)+ .bypass_allowlist(user: User.current).call(file:, container: self, filename:, description: name)call.on_failure { Rails.logger.error "Failed to add #{name} attachment: #{call.message}" }diff --git a/modules/bim/app/services/bim/ifc_models/set_attributes_service.rb b/modules/bim/app/services/bim/ifc_models/set_attributes_service.rbindex 8e9cc0746d2..eb7c1e79f91 100644--- a/modules/bim/app/services/bim/ifc_models/set_attributes_service.rb+++ b/modules/bim/app/services/bim/ifc_models/set_attributes_service.rb@@ -78,7 +78,7 @@ module Bimdef build_ifc_attachment(ifc_attachment)::Attachments::BuildService- .bypass_whitelist(user:)+ .bypass_allowlist(user:).call(file: ifc_attachment, container: model, filename: ifc_attachment.original_filename, description: "ifc").on_failure do |build_attachment_result|build_attachment_result.errors.each do |error|diff --git a/modules/bim/spec/contracts/ifc_models/shared_contract_examples.rb b/modules/bim/spec/contracts/ifc_models/shared_contract_examples.rbindex 28db250bbab..50ab9b411cb 100644--- a/modules/bim/spec/contracts/ifc_models/shared_contract_examples.rb+++ b/modules/bim/spec/contracts/ifc_models/shared_contract_examples.rb@@ -102,7 +102,7 @@ RSpec.shared_examples_for "ifc model contract" dolet(:ifc_file) { FileHelpers.mock_uploaded_file name: "model.ifc", content_type: "application/binary", binary: true }let(:ifc_attachment) doAttachments::BuildService- .bypass_whitelist(user: current_user)+ .bypass_allowlist(user: current_user).call(file: ifc_file, filename: "model.ifc").resultend@@ -118,7 +118,7 @@ RSpec.shared_examples_for "ifc model contract" doendlet(:ifc_attachment) doAttachments::BuildService- .bypass_whitelist(user: current_user)+ .bypass_allowlist(user: current_user).call(file: ifc_file, filename: "model.ifc").resultenddiff --git a/modules/bim/spec/workers/work_packages/exports/export_job_spec.rb b/modules/bim/spec/workers/work_packages/exports/export_job_spec.rbindex 491f18d6798..0909582fb4b 100644--- a/modules/bim/spec/workers/work_packages/exports/export_job_spec.rb+++ b/modules/bim/spec/workers/work_packages/exports/export_job_spec.rb@@ -66,15 +66,14 @@ RSpec.describe WorkPackages::ExportJob doservice = double("attachments create service")- expect(Attachments::CreateService)- .to receive(:bypass_whitelist)- .with(user:)+ allow(Attachments::CreateService)+ .to receive(:bypass_allowlist).and_return(service)- expect(Exports::CleanupOutdatedJob)+ allow(Exports::CleanupOutdatedJob).to receive(:perform_after_grace)- expect(service)+ allow(service).to(receive(:call)).and_return(ServiceResult.success(result: attachment))@@ -85,6 +84,16 @@ RSpec.describe WorkPackages::ExportJob doexpect(subject.job_status).to be_presentexpect(subject.job_status[:status]).to eq "success"expect(subject.job_status[:payload]["download"]).to eq "/api/v3/attachments/1234/content"++ expect(Attachments::CreateService)+ .to have_received(:bypass_allowlist)+ .with(user:)++ expect(Exports::CleanupOutdatedJob)+ .to have_received(:perform_after_grace)++ expect(service)+ .to have_received(:call)endendenddiff --git a/spec/contracts/attachments/create_contract_spec.rb b/spec/contracts/attachments/create_contract_spec.rbindex e2e0367981a..723ab76823b 100644--- a/spec/contracts/attachments/create_contract_spec.rb+++ b/spec/contracts/attachments/create_contract_spec.rb@@ -104,28 +104,28 @@ RSpec.describe Attachments::CreateContract doendend- context "with an empty whitelist",+ context "with an empty allowlist",with_settings: { attachment_whitelist: %w[] } doit_behaves_like "contract is valid"end- context "with a matching mime whitelist",+ context "with a matching mime allowlist",with_settings: { attachment_whitelist: %w[image/png] } doit_behaves_like "contract is valid"end- context "with a matching extension whitelist",+ context "with a matching extension allowlist",with_settings: { attachment_whitelist: %w[*.png] } doit_behaves_like "contract is valid"end- context "with a non-matching whitelist",+ context "with a non-matching allowlist",with_settings: { attachment_whitelist: %w[*.jpg image/jpeg] } do- it_behaves_like "contract is invalid", content_type: :not_whitelisted+ it_behaves_like "contract is invalid", content_type: :not_allowlistedcontext "when disabling the whitelist check" dolet(:contract_options) do- { whitelist: [] }+ { allowlist: [] }endit_behaves_like "contract is valid"@@ -133,7 +133,7 @@ RSpec.describe Attachments::CreateContract docontext "when overriding the whitelist" dolet(:contract_options) do- { whitelist: %w[*.png] }+ { allowlist: %w[*.png] }endit_behaves_like "contract is valid"diff --git a/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb b/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rbindex 19be033f486..5391a8a539a 100644--- a/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb+++ b/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb@@ -157,7 +157,7 @@ RSpec.shared_examples "it supports direct uploads" doendend- context "with an attachment whitelist", with_settings: { attachment_whitelist: ["text/csv"] } do+ context "with an attachment allowlist", with_settings: { attachment_whitelist: ["text/csv"] } docontext "with an allowed content type" dolet(:metadata) { { fileName: "cats.csv", fileSize: file.size, contentType: "text/csv" } }@@ -171,14 +171,14 @@ RSpec.shared_examples "it supports direct uploads" doit "fails" doexpect(subject.status).to eq 422- expect(subject.body).to include "not whitelisted"+ expect(subject.body).to include "'text/plain' is not allowed for upload."endend- context "with a non-specific content type not on the whitelist" do+ context "with a non-specific content type not on the allowlist" dolet(:metadata) { { fileName: "cats.bin", fileSize: file.size, contentType: "application/binary" } }- # the actual whitelist check will be performed in the FinishDirectUpload job in this case+ # the actual allowlist check will be performed in the FinishDirectUpload job in this caseit "still succeeds" doexpect(subject.status).to eq 201enddiff --git a/spec/workers/attachments/finish_direct_upload_job_integration_spec.rb b/spec/workers/attachments/finish_direct_upload_job_integration_spec.rbindex 08097ce47d1..2df7fb0b761 100644--- a/spec/workers/attachments/finish_direct_upload_job_integration_spec.rb+++ b/spec/workers/attachments/finish_direct_upload_job_integration_spec.rb@@ -136,7 +136,7 @@ RSpec.describe Attachments::FinishDirectUploadJob, "integration", type: :job doit_behaves_like "adding a journal to the attachment in the name of the attachment's author"end- context "with an incompatible attachment whitelist",+ context "with an incompatible attachment allowlist",with_settings: { attachment_whitelist: %w[image/png] } dolet!(:container) { create(:work_package) }let!(:container_timestamp) { container.updated_at }@@ -156,9 +156,9 @@ RSpec.describe Attachments::FinishDirectUploadJob, "integration", type: :job doexpect { pending_attachment.reload }.to raise_error(ActiveRecord::RecordNotFound)end- context "when the job is getting a whitelist override" do+ context "when the job is getting a allowlist override" doit "Does save the attachment" do- job.perform(pending_attachment.id, whitelist: false)+ job.perform(pending_attachment.id, allowlist: false)container.reloaddiff --git a/spec/workers/work_packages/exports/export_job_spec.rb b/spec/workers/work_packages/exports/export_job_spec.rbindex 9480c7b2e28..114b492904b 100644--- a/spec/workers/work_packages/exports/export_job_spec.rb+++ b/spec/workers/work_packages/exports/export_job_spec.rb@@ -68,15 +68,14 @@ RSpec.describe WorkPackages::ExportJob dolet(:exporter_instance) { instance_double(exporter) }it "exports" do- expect(Attachments::CreateService)- .to receive(:bypass_whitelist)- .with(user:)+ allow(Attachments::CreateService)+ .to receive(:bypass_allowlist).and_return(service)- expect(Exports::CleanupOutdatedJob)+ allow(Exports::CleanupOutdatedJob).to receive(:perform_after_grace)- expect(service)+ allow(service).to receive(:call) do |file:, **_args|expect(File.basename(file)).to start_with "some_title"@@ -96,6 +95,13 @@ RSpec.describe WorkPackages::ExportJob doexpect(subject.job_status.reference).to eq exportexpect(subject.job_status[:status]).to eq "success"expect(subject.job_status[:payload]["download"]).to eq "/api/v3/attachments/1234/content"++ expect(Attachments::CreateService)+ .to have_received(:bypass_allowlist)+ .with(user:)++ expect(Exports::CleanupOutdatedJob)+ .to have_received(:perform_after_grace)endend