A platform for community discussion. Free, open, simple.
SECURITY: Respect group visibility in category chatables when accessed by a moderator
Juan David Martinez07f66658cce8
diff --git a/plugins/chat/app/controllers/chat/api/category_chatables_controller.rb b/plugins/chat/app/controllers/chat/api/category_chatables_controller.rbindex 2104c66da4d..30e0ad4ad1f 100644--- a/plugins/chat/app/controllers/chat/api/category_chatables_controller.rb+++ b/plugins/chat/app/controllers/chat/api/category_chatables_controller.rb@@ -11,6 +11,7 @@ class Chat::Api::CategoryChatablesController < ApplicationControllerif category.read_restricted?permissions =Group+ .visible_groups(guardian.user, nil, include_everyone: true).joins(:category_groups).where(category_groups: { category_id: category.id }).where(diff --git a/plugins/chat/spec/requests/chat/api/category_chatables_controller_spec.rb b/plugins/chat/spec/requests/chat/api/category_chatables_controller_spec.rbindex 70f09768f5c..6e93711cf00 100644--- a/plugins/chat/spec/requests/chat/api/category_chatables_controller_spec.rb+++ b/plugins/chat/spec/requests/chat/api/category_chatables_controller_spec.rb@@ -97,6 +97,31 @@ describe Chat::Api::CategoryChatablesController doexpect(response.status).to eq(200)end++ it "does not include groups the moderator cannot see" do+ group.add(moderator)++ secret_group =+ Fabricate(+ :group,+ visibility_level: Group.visibility_levels[:owners],+ members_visibility_level: Group.visibility_levels[:owners],+ )+ secret_group.add(Fabricate(:user))+ Fabricate(+ :category_group,+ category: private_category,+ group: secret_group,+ permission_type: CategoryGroup.permission_types[:full],+ )++ get "/chat/api/category-chatables/#{private_category.id}/permissions"++ expect(response.status).to eq(200)+ expect(response.parsed_body["allowed_groups"]).to contain_exactly("@#{group.name}")+ expect(response.parsed_body["allowed_groups"]).not_to include("@#{secret_group.name}")+ expect(response.parsed_body["members_count"]).to eq(1)+ endendcontext "as anon" do