A platform for community discussion. Free, open, simple.
SECURITY: Replying to a whisper lets non-whisperers create staff-only whisper posts
discourse-patch-triage[bot]3c0fb8a875a4
diff --git a/lib/post_creator.rb b/lib/post_creator.rbindex f57111a45c0..044b2ecf3ba 100644--- a/lib/post_creator.rb+++ b/lib/post_creator.rb@@ -333,7 +333,15 @@ class PostCreatorif reply_info.present?post.reply_to_user_id ||= reply_info.user_idwhisper_type = Post.types[:whisper]- post.post_type = whisper_type if reply_info.post_type == whisper_type++ if reply_info.post_type == whisper_type+ if post.acting_user&.whisperer?+ post.post_type = whisper_type+ else+ post.errors.add(:base, I18n.t(:topic_not_found))+ throw :abort+ end+ endendenddiff --git a/spec/lib/post_creator_spec.rb b/spec/lib/post_creator_spec.rbindex a4b87cc28d9..6cdf975ec2a 100644--- a/spec/lib/post_creator_spec.rb+++ b/spec/lib/post_creator_spec.rb@@ -692,20 +692,22 @@ RSpec.describe PostCreator dodescribe "whisper" dofab!(:topic) { Fabricate(:topic, user: user) }+ before { SiteSetting.whispers_allowed_groups = "#{Group::AUTO_GROUPS[:staff]}" }+it "whispers do not mess up the public view" dofreeze_time_safe- first = PostCreator.new(user, topic_id: topic.id, raw: "this is the first post").create+ first = PostCreator.new(admin, topic_id: topic.id, raw: "this is the first post").createfreeze_time 1.year.from_now- user_stat = user.user_stat+ user_stat = admin.user_statwhisper =PostCreator.new(- user,+ admin,topic_id: topic.id,- reply_to_post_number: 1,+ reply_to_post_number: first.post_number,post_type: Post.types[:whisper],raw: "this is a whispered reply",).create@@ -718,7 +720,7 @@ RSpec.describe PostCreator dowhisper_reply =PostCreator.new(- user,+ admin,topic_id: topic.id,reply_to_post_number: whisper.post_number,post_type: Post.types[:regular],@@ -730,8 +732,8 @@ RSpec.describe PostCreator doexpect(user_stat.reload.post_count).to eq(0)- user.reload- expect(user.last_posted_at).to eq_time(1.year.ago)+ admin.reload+ expect(admin.last_posted_at).to eq_time(1.year.ago)# date is not precise enough in dbwhisper_reply.reloaddiff --git a/spec/models/user_summary_spec.rb b/spec/models/user_summary_spec.rbindex 343975875cc..7925ae6f9e0 100644--- a/spec/models/user_summary_spec.rb+++ b/spec/models/user_summary_spec.rb@@ -135,8 +135,11 @@ RSpec.describe UserSummary do# Don't include replies to whisperstopic3 = create_post(user: topic1.user).topictopic3_post = create_post(topic: topic3, post_type: Post.types[:whisper])- topic3_reply =- create_post(topic: topic3, reply_to_post_number: topic3_post.post_number, user: topic3.user)+ topic3_reply = create_post(topic: topic3, user: topic1.user)+ topic3_reply.update_columns(+ reply_to_post_number: topic3_post.post_number,+ post_type: Post.types[:whisper],+ )# Don't include replies to private messagesreplied_to_user = Fabricate(:user)diff --git a/spec/requests/posts_controller_spec.rb b/spec/requests/posts_controller_spec.rbindex 02925c7a854..4af5692c623 100644--- a/spec/requests/posts_controller_spec.rb+++ b/spec/requests/posts_controller_spec.rb@@ -1835,6 +1835,41 @@ RSpec.describe PostsController doexpect(topic.visible).to eq(true)end+ it "prevents regular users from replying to whispers" do+ sign_in(admin)+ post "/posts.json",+ params: {+ raw: "this is the first post with enough words",+ title: "this is a topic title for whispers",+ }+ expect(response.status).to eq(200)++ topic_id = response.parsed_body["topic_id"]+ post "/posts.json",+ params: {+ raw: "this is a staff-only whisper",+ topic_id: topic_id,+ reply_to_post_number: 1,+ whisper: true,+ }+ expect(response.status).to eq(200)++ whisper_post_number = response.parsed_body["post_number"]+ sign_in(user)++ expect do+ post "/posts.json",+ params: {+ raw: "replying to a whisper over http",+ topic_id: topic_id,+ reply_to_post_number: whisper_post_number,+ }+ end.not_to change { Post.count }++ expect(response.status).to eq(422)+ expect(response.parsed_body["errors"]).to include(I18n.t(:topic_not_found))+ end+describe "posts_controller_create_user modifier" dofab!(:different_user, :admin)diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rbindex 38db5ddd150..2818faff1f5 100644--- a/spec/services/post_alerter_spec.rb+++ b/spec/services/post_alerter_spec.rb@@ -1699,6 +1699,7 @@ RSpec.describe PostAlerter doendit "notifies staff user about whispered reply" do+ SiteSetting.whispers_allowed_groups = "#{Group::AUTO_GROUPS[:staff]}"admin1 = Fabricate(:admin)admin2 = Fabricate(:admin)