Skip to content

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

SECURITY: Shared-draft titles and excerpts leak through group post serialization

Isaac Janzendcec41864a08
diff --git a/app/models/group.rb b/app/models/group.rb
index 405b529d27a..5e19f831eca 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -483,6 +483,13 @@ class Group < ActiveRecord::Base
result = result.where("topics.category_id = ?", opts[:category_id].to_i)
end
+ result =
+ result.where.not(
+ topics: {
+ id: SharedDraft.select(:topic_id),
+ },
+ ) if !guardian.can_see_shared_draft?
+
result = guardian.filter_allowed_categories(result)
result = guardian.filter_hidden_posts(result)
result = result.where("posts.id < ?", opts[:before_post_id].to_i) if opts[:before_post_id]
diff --git a/spec/requests/groups_controller_spec.rb b/spec/requests/groups_controller_spec.rb
index 0cf30db510d..4e0ee1cf2f0 100644
--- a/spec/requests/groups_controller_spec.rb
+++ b/spec/requests/groups_controller_spec.rb
@@ -743,6 +743,39 @@ RSpec.describe GroupsController do
end
end
+ describe "shared draft visibility" do
+ it "omits shared draft posts from posts and mentions endpoints", :aggregate_failures do
+ SiteSetting.shared_drafts_allowed_groups = Group::AUTO_GROUPS[:staff]
+ shared_drafts_category = Fabricate(:category)
+ SiteSetting.shared_drafts_category = shared_drafts_category.id
+ shared_draft_topic =
+ Fabricate(
+ :topic,
+ title: "Secret Shared Draft Group Topic",
+ category: shared_drafts_category,
+ )
+ shared_draft_post =
+ Fabricate(
+ :post,
+ user: user,
+ topic: shared_draft_topic,
+ raw: "secret shared draft group post",
+ )
+ Fabricate(:shared_draft, topic: shared_draft_topic, category: Fabricate(:category))
+ GroupMention.create!(post: shared_draft_post, group: group)
+
+ sign_in(user2)
+ ["/groups/#{group.name}/posts.json", "/groups/#{group.name}/mentions.json"].each do |path|
+ get path
+
+ expect(response.status).to eq(200)
+ expect(response.parsed_body["posts"]).to be_empty
+ expect(response.body).not_to include(shared_draft_topic.title)
+ expect(response.body).not_to include(shared_draft_post.raw)
+ end
+ end
+ end
+
describe "#posts" do
it "ensures the group can be seen" do
sign_in(user)