A platform for community discussion. Free, open, simple.
FIX: Restrict chatable_type filtering in public channel API to supported types (#45040)
Isaac Janzenceae9f3694b7
diff --git a/plugins/chat/lib/chat/channel_fetcher.rb b/plugins/chat/lib/chat/channel_fetcher.rbindex 2a4b59ecfda..ab16215f1ab 100644--- a/plugins/chat/lib/chat/channel_fetcher.rb+++ b/plugins/chat/lib/chat/channel_fetcher.rb@@ -143,7 +143,8 @@ module Chatchannels = channels.where(status: options[:status]) if options[:status].present?- if options[:chatable_id].present? && options[:chatable_type].present?+ if options[:chatable_id].present? &&+ Chat::Channel.public_channel_chatable_types.include?(options[:chatable_type])filter_chatable = options[:chatable_type].constantize&.find_by_id(options[:chatable_id])if filter_chatable.present? && guardian.can_see_chatable?(filter_chatable)chatable_ids =diff --git a/plugins/chat/spec/requests/chat/api/channels_controller_spec.rb b/plugins/chat/spec/requests/chat/api/channels_controller_spec.rbindex 98591bd612e..3b25015ab60 100644--- a/plugins/chat/spec/requests/chat/api/channels_controller_spec.rb+++ b/plugins/chat/spec/requests/chat/api/channels_controller_spec.rb@@ -133,6 +133,35 @@ RSpec.describe Chat::Api::ChannelsController doendend+ context "when filtering with an unsupported chatable type" do+ fab!(:channel_1, :category_channel)+ fab!(:private_message_topic)++ it "does not reveal private-message topic existence" do+ get "/chat/api/channels",+ params: {+ chatable_id: private_message_topic.id,+ chatable_type: "Topic",+ }++ expect(response.status).to eq(200)+ expect(response.parsed_body["channels"].map { |channel| channel["id"] }).to eq(+ [channel_1.id],+ )++ get "/chat/api/channels",+ params: {+ chatable_id: Topic.maximum(:id) + 1,+ chatable_type: "Topic",+ }++ expect(response.status).to eq(200)+ expect(response.parsed_body["channels"].map { |channel| channel["id"] }).to eq(+ [channel_1.id],+ )+ end+ end+context "when filtering by chatable_id and chatable_type (Category)" dofab!(:category_1, :category)fab!(:category_2, :category)