Skip to content

A platform for community discussion. Free, open, simple.

SECURITY: Prevent TL4 users to post to staff-only categories through a topic timer

Jarek Radosz846f1696ed62
diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb
index 23e1e47daac..a0c58c79030 100644
--- a/app/controllers/topics_controller.rb
+++ b/app/controllers/topics_controller.rb
@@ -612,6 +612,12 @@ class TopicsController < ApplicationController
guardian.ensure_can_delete!(topic) if TopicTimer.destructive_types.values.include?(status_type)
+ if status_type == TopicTimer.types[:publish_to_category] && params[:category_id].present?
+ category = Category.find_by(id: params[:category_id])
+ raise Discourse::NotFound if !category
+ raise Discourse::InvalidAccess if !guardian.can_create_topic_on_category?(category)
+ end
+
options = { by_user: current_user, based_on_last_post: based_on_last_post }
options.merge!(category_id: params[:category_id]) if params[:category_id].present?
diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb
index 733b0b3260a..74b2e77348d 100644
--- a/spec/requests/topics_controller_spec.rb
+++ b/spec/requests/topics_controller_spec.rb
@@ -5677,6 +5677,25 @@ RSpec.describe TopicsController do
topic_timer = TopicTimer.last
expect(topic_timer.status_type).to eq(TopicTimer.types[:delete_replies])
end
+
+ it "raises an error when publishing to a staff-only category" do
+ user.update!(trust_level: TrustLevel[4])
+ sign_in(user)
+
+ staff_category = Fabricate(:category)
+ staff_category.set_permissions(staff: :full)
+ staff_category.save!
+
+ post "/t/#{topic.id}/timer.json",
+ params: {
+ time: 24,
+ status_type: "publish_to_category",
+ category_id: staff_category.id,
+ }
+
+ expect(response.status).to eq(403)
+ expect(response.parsed_body["error_type"]).to eq("invalid_access")
+ end
end
end