Skip to content

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

SECURITY: prevents whispers to leak in excerpts

Joffrey JAFFEUX37681092dadd
diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb
index e9b09016e5b..23e1e47daac 100644
--- a/app/controllers/topics_controller.rb
+++ b/app/controllers/topics_controller.rb
@@ -303,6 +303,7 @@ class TopicsController < ApplicationController
@posts =
Post
+ .secured(guardian)
.where(hidden: false, deleted_at: nil, topic_id: @topic.id)
.where("posts.id in (?)", post_ids)
.joins("LEFT JOIN users u on u.id = posts.user_id")
diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb
index ce642098538..733b0b3260a 100644
--- a/spec/requests/topics_controller_spec.rb
+++ b/spec/requests/topics_controller_spec.rb
@@ -5254,6 +5254,27 @@ RSpec.describe TopicsController do
expect(json[2]["action_code"]).to eq("autobumped")
expect(json[2]["created_at"].present?).to eq(true)
end
+
+ it "does not return whisper posts to non-staff users" do
+ SiteSetting.whispers_allowed_groups = "#{Group::AUTO_GROUPS[:staff]}"
+ first_post = create_post(raw: "This is the first post")
+ whisper_post =
+ create_post(
+ raw: "This is a secret whisper",
+ topic: first_post.topic,
+ post_type: Post.types[:whisper],
+ )
+
+ sign_in(user)
+
+ get "/t/#{first_post.topic_id}/excerpts.json",
+ params: {
+ post_ids: [first_post.id, whisper_post.id],
+ }
+
+ json = response.parsed_body
+ expect(json.map { |p| p["post_id"] }).to contain_exactly(first_post.id)
+ end
end
describe "#convert_topic" do