A platform for community discussion. Free, open, simple.
SECURITY: Regular users can create global banners via archetype mass-assignment (#42210)
Isaac Janzena7a852c7d8f5
diff --git a/lib/topic_creator.rb b/lib/topic_creator.rbindex da657b12f04..af7f31f6354 100644--- a/lib/topic_creator.rb+++ b/lib/topic_creator.rb@@ -156,7 +156,7 @@ class TopicCreatorvisible: @opts[:visible],}- %i[subtype archetype import_mode advance_draft locale].each do |key|+ %i[subtype import_mode advance_draft locale].each do |key|topic_params[key] = @opts[key] if @opts[key].present?end@@ -185,6 +185,15 @@ class TopicCreatortopic_params[:external_id] = @opts[:external_id] if @opts[:external_id].present?topic_params[:featured_link] = @opts[:featured_link]+ if @opts[:archetype].present?+ topic = Topic.new(topic_params)++ if @opts[:archetype] == Archetype.private_message ||+ @guardian.can_change_archetype?(topic, @opts[:archetype])+ topic_params[:archetype] = @opts[:archetype]+ end+ end+topic_paramsenddiff --git a/spec/requests/posts_controller_spec.rb b/spec/requests/posts_controller_spec.rbindex c5294ac38fa..bf98345e785 100644--- a/spec/requests/posts_controller_spec.rb+++ b/spec/requests/posts_controller_spec.rb@@ -1244,6 +1244,37 @@ RSpec.describe PostsController doSiteSetting.whispers_allowed_groups = "#{Group::AUTO_GROUPS[:staff]}"end+ it "prevents regular users from publishing a global banner while creating a topic" do+ ApplicationLayoutPreloader.banner_json_cache.clear+ sign_in(user_trust_level_1)++ post "/posts.json",+ params: {+ raw: "this is a test banner topic body",+ title: "this is a test banner topic title",+ category: category.id,+ archetype: Archetype.banner,+ }++ creation_status = response.status+ creation_body = response.parsed_body+ created_topic = Topic.find(creation_body["topic_id"])++ sign_in(user)+ get "/site/banner.json"+ banner_status = response.status+ banner_body = response.parsed_body+ ApplicationLayoutPreloader.banner_json_cache.clear++ aggregate_failures do+ expect(creation_status).to eq(200)+ expect(creation_body["topic_id"]).to eq(created_topic.id)+ expect(created_topic.archetype).to eq(Archetype.default)+ expect(banner_status).to eq(200)+ expect(banner_body).to eq({})+ end+ end+context "with api" doit "memoizes duplicate requests" doraw = "this is a test post 123 #{SecureRandom.hash}"