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

[#60144] sanitizing parameter input into settings component

Eric Schubert88826fd16a8a
diff --git a/app/components/work_packages/types/settings_component.rb b/app/components/work_packages/types/settings_component.rb
index 8cceabe49ea..948af9a38df 100644
--- a/app/components/work_packages/types/settings_component.rb
+++ b/app/components/work_packages/types/settings_component.rb
@@ -34,18 +34,29 @@ module WorkPackages
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
- def initialize(model, **options)
- @copy_workflow_from = options[:copy_workflow_from].to_i
- super
+ def initialize(model, copy_workflow_from: nil, **)
+ @copy_workflow_from = copy_workflow_from
+ super(model, **)
end
def form_options
- {
- url: model.new_record? ? types_path : type_path(id: model.id),
- method: model.new_record? ? :post : :patch,
- model:,
- copy_workflow_from: @copy_workflow_from
- }
+ if model.new_record?
+ create_form_options
+ else
+ update_form_options
+ end
+ end
+
+ private
+
+ attr_reader :copy_workflow_from
+
+ def create_form_options
+ { url: types_path, method: :post, model:, copy_workflow_from: }
+ end
+
+ def update_form_options
+ { url: type_path(id: model.id), method: :patch, model: }
end
end
end
diff --git a/app/controllers/types_controller.rb b/app/controllers/types_controller.rb
index c3cc2a5dcbf..57f61b72196 100644
--- a/app/controllers/types_controller.rb
+++ b/app/controllers/types_controller.rb
@@ -135,7 +135,7 @@ class TypesController < ApplicationController
def redirect_to_type_tab_path(type, notice)
tab = params["tab"] || "settings"
- redirect_to(edit_tab_type_path(type, tab:), notice:)
+ redirect_to(edit_tab_type_path(type, tab:), notice:, status: :see_other)
end
def render_edit_tab(type, status: :ok)
diff --git a/app/helpers/conversion_helper.rb b/app/helpers/conversion_helper.rb
new file mode 100644
index 00000000000..e4ed37cee0e
--- /dev/null
+++ b/app/helpers/conversion_helper.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 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 ConversionHelper
+ include Dry::Monads[:maybe]
+
+ def maybe_integer(value)
+ Some(Integer(value || "", 10))
+ rescue ArgumentError
+ None()
+ end
+end
diff --git a/app/views/types/new.html.erb b/app/views/types/new.html.erb
index b1094027dfc..933de72555f 100644
--- a/app/views/types/new.html.erb
+++ b/app/views/types/new.html.erb
@@ -40,9 +40,6 @@ See COPYRIGHT and LICENSE files for more details.
%>
<%=
- render WorkPackages::Types::SettingsComponent.new(
- @type,
- copy_workflow_from: params.dig(:type, :copy_workflow_from),
- params:
- )
+ copy_workflow_from = maybe_integer(params.dig(:type, :copy_workflow_from)).value_or(nil)
+ render WorkPackages::Types::SettingsComponent.new(@type, copy_workflow_from:)
%>