A platform for community discussion. Free, open, simple.
SECURITY: Stale featured rows expose unlisted topic content (#41810)
Bannon Tanner262563048231
diff --git a/app/models/category_list.rb b/app/models/category_list.rbindex dab66457a36..be1d82664ac 100644--- a/app/models/category_list.rb+++ b/app/models/category_list.rb@@ -81,6 +81,7 @@ class CategoryListinclude_uncategorized: false,) # perf optimization since category featured topics can't have `category_id` set to null.listable_topics+ .visible.joins("INNER JOIN category_featured_topics ON topics.id = category_featured_topics.topic_id",)diff --git a/app/services/user_silencer.rb b/app/services/user_silencer.rbindex 184a922b678..f20b37558a1 100644--- a/app/services/user_silencer.rb+++ b/app/services/user_silencer.rb@@ -90,7 +90,10 @@ class UserSilencer.where(user_id: @user.id, post_number: 1).where("created_at > ?", 24.hours.ago).pluck(:topic_id)- Topic.where(id: topic_ids).update_all(visible: false) unless topic_ids.empty?+ unless topic_ids.empty?+ Topic.where(id: topic_ids).update_all(visible: false)+ CategoryFeaturedTopic.where(topic_id: topic_ids).delete_all+ endenddef unsilencediff --git a/spec/requests/categories_controller_spec.rb b/spec/requests/categories_controller_spec.rbindex e3cbf4dd946..f2b6d4f5886 100644--- a/spec/requests/categories_controller_spec.rb+++ b/spec/requests/categories_controller_spec.rb@@ -66,6 +66,21 @@ RSpec.describe CategoriesController do)end+ it "omits invisible topics with stale featured rows", :aggregate_failures do+ topic = Fabricate(:topic, category: category)+ CategoryFeaturedTopic.create!(category: category, topic: topic)+ topic.update_column(:visible, false)++ get "/categories.json?include_topics=true"++ expect(response).to have_http_status(:ok)+ category_response =+ response.parsed_body["category_list"]["categories"].find do |category_json|+ category_json["id"] == category.id+ end+ expect(category_response).not_to have_key("topics")+ end+it "does not returns subcategories without permission" dosubcategory = Fabricate(:category, user: admin, parent_category: category)subcategory.set_permissions(admins: :full)diff --git a/spec/services/user_silencer_spec.rb b/spec/services/user_silencer_spec.rbindex cb225ae5e39..7a98c7b5263 100644--- a/spec/services/user_silencer_spec.rb+++ b/spec/services/user_silencer_spec.rb@@ -32,6 +32,14 @@ RSpec.describe UserSilencer doexpect(count).to eq(1)end+ it "removes featured rows for hidden topics" do+ CategoryFeaturedTopic.create!(category: post.topic.category, topic: post.topic)++ expect { UserSilencer.silence(user, admin) }.to change {+ CategoryFeaturedTopic.exists?(topic_id: post.topic_id)+ }.from(true).to(false)+ end+it "skips sending the email for the silence PM via post alert" doNotificationEmailer.enableJobs.run_immediately!