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
Allow running turbo drive with reusing nonces in secure headers
Oliver Günther9f10cf3d53ce
diff --git a/app/helpers/secure_headers_helper.rb b/app/helpers/secure_headers_helper.rbnew file mode 100644index 00000000000..714c20a476f--- /dev/null+++ b/app/helpers/secure_headers_helper.rb@@ -0,0 +1,38 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++module SecureHeadersHelper+ ##+ # Output a rails +csp_meta_tag+ compatible tag+ # while we're still using the +secure_headers+ gem.+ def secure_header_csp_meta_tag+ tag :meta,+ name: "csp-nonce",+ content: content_security_policy_script_nonce+ end+enddiff --git a/app/views/layouts/_common_head.html.erb b/app/views/layouts/_common_head.html.erbindex 429cec0a423..ff5c3345103 100644--- a/app/views/layouts/_common_head.html.erb+++ b/app/views/layouts/_common_head.html.erb@@ -21,6 +21,7 @@<% if Setting.boards_demo_data_available %><meta name="boards_demo_data_available" content="true"/><% end %><% if Setting.demo_view_of_type_team_planner_seeded %><meta name="demo_view_of_type_team_planner_seeded" content="true"/><% end %><%= csrf_meta_tags %>+<%= secure_header_csp_meta_tag %><%= initializer_meta_tag %><!-- global meta hooks before any scripts are loaded-->diff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erbindex 0895f2c65f5..e3503accc66 100644--- a/app/views/layouts/base.html.erb+++ b/app/views/layouts/base.html.erb@@ -38,8 +38,6 @@ See COPYRIGHT and LICENSE files for more details.<!-- page specific tags --><%= content_for(:header_tags) if content_for?(:header_tags) %><meta name="current_menu_item" content="<%= current_menu_item %>"/>- <%# Disable prefetching while we have data-turbo=false on body %>- <meta name="turbo-prefetch" content="false"></head><bodyclass="<%= body_css_classes %> __overflowing_element_container __overflowing_body"diff --git a/frontend/src/turbo/setup.ts b/frontend/src/turbo/setup.tsindex f9db91d4dcf..8d3f17b5053 100644--- a/frontend/src/turbo/setup.ts+++ b/frontend/src/turbo/setup.ts@@ -8,8 +8,9 @@ import { applyTurboNavigationPatch } from './turbo-navigation-patch';import { debugLog, whenDebugging } from 'core-app/shared/helpers/debug_output';import { TURBO_EVENTS } from './constants';-// Disable default turbo-drive for now as we don't need it for now AND it breaks angular routing-Turbo.session.drive = false;+Turbo.session.drive = true;+Turbo.setProgressBarDelay(100);+// Start turboTurbo.start();diff --git a/frontend/src/turbo/turbo-event-listeners.ts b/frontend/src/turbo/turbo-event-listeners.tsindex 3e9b24c0234..b102187836c 100644--- a/frontend/src/turbo/turbo-event-listeners.ts+++ b/frontend/src/turbo/turbo-event-listeners.ts@@ -17,4 +17,12 @@ export function addTurboEventListeners() {}}});++ // Append turbo nonce for drive requests+ document.addEventListener('turbo:before-fetch-request', (event) => {+ // Turbo Drive does not send a referrer like turbolinks used to, so let's simulate it here+ const headers = event.detail.fetchOptions.headers as Record<string, string>;+ headers['Turbo-Referrer'] = window.location.href;+ headers['X-Turbo-Nonce'] = document.getElementsByName('csp-nonce')[0]?.getAttribute('content') || '';+ });}diff --git a/frontend/src/typings/shims.d.ts b/frontend/src/typings/shims.d.tsindex d00919774d9..6a151a4ae8f 100644--- a/frontend/src/typings/shims.d.ts+++ b/frontend/src/typings/shims.d.ts@@ -48,6 +48,9 @@ declare module '@hotwired/turbo' {}export function start():void;++ export function setProgressBarDelay(delay:number):void;+}declare global {diff --git a/lib/open_project/patches/secure_headers_turbo_aware_nonce.rb b/lib/open_project/patches/secure_headers_turbo_aware_nonce.rbnew file mode 100644index 00000000000..3757380c0c4--- /dev/null+++ b/lib/open_project/patches/secure_headers_turbo_aware_nonce.rb@@ -0,0 +1,42 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#+++#++module OpenProject::Patches::SecureHeadersTurboAwareNonce+ def content_security_policy_script_nonce(request)+ if request.env["HTTP_TURBO_REFERRER"].present?+ request.env["HTTP_X_TURBO_NONCE"]+ else+ super+ end+ end+end++OpenProject::Patches.patch_gem_version "secure_headers", "6.5.0" do+ SecureHeaders.singleton_class.prepend OpenProject::Patches::SecureHeadersTurboAwareNonce+end