A platform for community discussion. Free, open, simple.
SECURITY: Limit generic topic timer endpoint to externally settable public types (#43992)
jbrw0d59d3718991
diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rbindex 252eab8e777..8f89d804388 100644--- a/app/controllers/topics_controller.rb+++ b/app/controllers/topics_controller.rb@@ -633,7 +633,7 @@ class TopicsController < ApplicationControllerstatus_type =begin- TopicTimer.types.fetch(params[:status_type].to_sym)+ TopicTimer.public_types.fetch(params[:status_type].to_sym)rescue StandardErrorinvalid_param(:status_type)enddiff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rbindex 877ae4a8e9d..5bdff9c1b4a 100644--- a/spec/requests/topics_controller_spec.rb+++ b/spec/requests/topics_controller_spec.rb@@ -6904,6 +6904,19 @@ RSpec.describe TopicsController doexpect(topic.reload.public_topic_timer.user).to eq(user)end+ it "prevents scheduling a timer that clears slow mode" do+ topic.update!(slow_mode_seconds: 3600)++ post "/t/#{topic.id}/timer.json", params: { time: "1", status_type: "clear_slow_mode" }++ expect(response.status).to eq(400)+ expect(response.body).to include("status_type")+ expect(topic.reload.slow_mode_seconds).to eq(3600)+ expect(+ TopicTimer.find_by(topic:, status_type: TopicTimer.types[:clear_slow_mode]),+ ).to be_nil+ end+it "requires delete permissions for destructive timers" dopost "/t/#{topic.id}/timer.json", params: { time: "24", status_type: "delete" }