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
Rollback #13611.
Pavel Balashou7c7102cabd3d
diff --git a/modules/storages/lib/open_project/storages/append_storages_hosts_to_csp_hook.rb b/modules/storages/lib/open_project/storages/append_storages_hosts_to_csp_hook.rbindex 9df8f5eebe2..1eaa3548009 100644--- a/modules/storages/lib/open_project/storages/append_storages_hosts_to_csp_hook.rb+++ b/modules/storages/lib/open_project/storages/append_storages_hosts_to_csp_hook.rb@@ -43,31 +43,18 @@ class ::OpenProject::Storages::AppendStoragesHostsToCspHook < OpenProject::Hook:# places of OpenProject, and we want to be able to upload in all those places# (work packages module, BCF module, notification center, boards, ...).def application_controller_before_action(context)- controller = context[:controller]-- active_nextcloud_storages_hosts = ::Storages::NextcloudStorage- .where(id: ::Storages::ProjectStorage.select(:storage_id))- .pluck(:host)- .map(&method(:remove_uri_path))-- if active_nextcloud_storages_hosts.present?- controller.append_content_security_policy_directives(- frame_ancestors: active_nextcloud_storages_hosts- )- end-storage_ids = ::Storages::ProjectStorage.where(- project_id: Project.allowed_to(User.current, :manage_file_links)+ project_id: Project.allowed_to(User.current, :manage_file_links),).select(:storage_id)storages_hosts = ::Storages::Storage- .where(id: storage_ids)- .where.not(host: nil)- .pluck(:host)- .map(&method(:remove_uri_path))+ .where(id: storage_ids)+ .where.not(host: nil)+ .pluck(:host)+ .map(&method(:remove_uri_path))if storages_hosts.present?# secure_headers gem provides this helper method to append to the current content security policy- controller.append_content_security_policy_directives(connect_src: storages_hosts)+ context[:controller].append_content_security_policy_directives(connect_src: storages_hosts)endenddiff --git a/modules/storages/spec/lib/append_storages_hosts_to_csp_hook_spec.rb b/modules/storages/spec/lib/append_storages_hosts_to_csp_hook_spec.rbindex eb7ec13f720..11d004b3dfc 100644--- a/modules/storages/spec/lib/append_storages_hosts_to_csp_hook_spec.rb+++ b/modules/storages/spec/lib/append_storages_hosts_to_csp_hook_spec.rb@@ -53,11 +53,10 @@ RSpec.describe OpenProject::Storages::AppendStoragesHostsToCspHook doendshared_examples 'content security policy directives' do- it 'adds CSP connect_src and frame_ancestors directives' do+ it 'adds CSP connect_src directives' dotrigger_application_controller_before_action_hook- expect(controller).to have_received(:append_content_security_policy_directives).with(frame_ancestors: [storage.host]).ordered- expect(controller).to have_received(:append_content_security_policy_directives).with(connect_src: [storage.host]).ordered+ expect(controller).to have_received(:append_content_security_policy_directives).with(connect_src: [storage.host])endend@@ -85,10 +84,9 @@ RSpec.describe OpenProject::Storages::AppendStoragesHostsToCspHook docontext 'when current user is a member of the project without permission to manage file links' docurrent_user { create(:user, member_in_project: project, member_with_permissions: []) }- it 'adds CSP frame_ancestors directive only' do+ it 'does not add CSP connect_src directive' dotrigger_application_controller_before_action_hook- expect(controller).to have_received(:append_content_security_policy_directives).with(frame_ancestors: [storage.host]).onceexpect(controller).not_to have_received(:append_content_security_policy_directives).with(connect_src: [storage.host])endend@@ -100,10 +98,9 @@ RSpec.describe OpenProject::Storages::AppendStoragesHostsToCspHook doproject.update(active: false)end- it 'adds CSP frame_ancestors directive only' do+ it 'does not add CSP connect_src directive' dotrigger_application_controller_before_action_hook- expect(controller).to have_received(:append_content_security_policy_directives).with(frame_ancestors: [storage.host])expect(controller).not_to have_received(:append_content_security_policy_directives).with(connect_src: [storage.host])endenddiff --git a/modules/storages/spec/requests/append_content_security_policy_spec.rb b/modules/storages/spec/requests/append_content_security_policy_spec.rbindex 9e5b1d2f038..a14ed417ba8 100644--- a/modules/storages/spec/requests/append_content_security_policy_spec.rb+++ b/modules/storages/spec/requests/append_content_security_policy_spec.rb@@ -45,21 +45,19 @@ RSpec.describe 'Appendix of default CSP for external file storage hosts' docontext 'when logged in' docurrent_user { create(:user, member_in_project: project, member_with_permissions: %i[manage_file_links]) }- it 'appends storage host to the connect-src and frame-ancestors CSP' do+ it 'appends storage host to the connect-src CSP' doget '/'csp = parse_csp(last_response.headers['Content-Security-Policy'])- expect(csp['frame-ancestors']).to eq(["'self'", storage.host])expect(csp['connect-src']).to include(storage.host)endendcontext 'when not logged in' do- it 'appends storage host to frame-ancestors CSP only' do+ it 'does not append host to connect-src CSP' doget '/'csp = parse_csp(last_response.headers['Content-Security-Policy'])- expect(csp['frame-ancestors']).to eq(["'self'", storage.host])expect(csp['connect-src']).not_to include(storage.host)endend