A platform for community discussion. Free, open, simple.
SECURITY: Scope discourse-assign MessageBus broadcasts to secure topic audiences (#44086)
Isaac Janzen0fedd58d7783
diff --git a/plugins/discourse-assign/plugin.rb b/plugins/discourse-assign/plugin.rbindex 1a8cef41868..41cea73cf92 100644--- a/plugins/discourse-assign/plugin.rb+++ b/plugins/discourse-assign/plugin.rb@@ -890,20 +890,32 @@ after_initialize doassigner = ::Assigner.new(post, Discourse.system_user)assigner.unassign(silent: true, deactivate: true)end- MessageBus.publish("/topic/#{topic.id}", reload_topic: true, refresh_stream: true)+ MessageBus.publish(+ "/topic/#{topic.id}",+ { reload_topic: true, refresh_stream: true },+ topic.secure_audience_publish_messages,+ )endif SiteSetting.reassign_on_open && (status == "closed" || status == "autoclosed") && !enabled &&Assignment.inactive.exists?(topic: topic)Assignment.reactivate!(topic: topic)- MessageBus.publish("/topic/#{topic.id}", reload_topic: true, refresh_stream: true)+ MessageBus.publish(+ "/topic/#{topic.id}",+ { reload_topic: true, refresh_stream: true },+ topic.secure_audience_publish_messages,+ )endendon(:post_destroyed) do |post|if Assignment.active.exists?(target: post)post.assignment.deactivate!- MessageBus.publish("/topic/#{post.topic_id}", reload_topic: true, refresh_stream: true)+ MessageBus.publish(+ "/topic/#{post.topic_id}",+ { reload_topic: true, refresh_stream: true },+ post.topic.secure_audience_publish_messages,+ )end# small actions have to be destroyed as link is incorrect@@ -923,7 +935,11 @@ after_initialize doon(:post_recovered) do |post|if SiteSetting.reassign_on_open && Assignment.inactive.exists?(target: post)post.assignment.reactivate!- MessageBus.publish("/topic/#{post.topic_id}", reload_topic: true, refresh_stream: true)+ MessageBus.publish(+ "/topic/#{post.topic_id}",+ { reload_topic: true, refresh_stream: true },+ post.topic.secure_audience_publish_messages,+ )endenddiff --git a/plugins/discourse-assign/spec/integration/assign_spec.rb b/plugins/discourse-assign/spec/integration/assign_spec.rbindex 6181166a33d..ee69ce8e90f 100644--- a/plugins/discourse-assign/spec/integration/assign_spec.rb+++ b/plugins/discourse-assign/spec/integration/assign_spec.rb@@ -13,6 +13,50 @@ describe "integration tests" do# should not explode for nowend+ describe "private message MessageBus access" do+ fab!(:admin)+ fab!(:private_message_post) { Fabricate(:private_message_post, user: admin) }+ fab!(:private_message) { private_message_post.topic }++ before do+ SiteSetting.unassign_on_close = true+ Fabricate(+ :topic_assignment,+ topic: private_message,+ assigned_to: admin,+ assigned_by_user: admin,+ )+ end++ it "does not expose assignment refreshes for private messages to nonparticipants" do+ channel = "/topic/#{private_message.id}"+ message_id = MessageBus.last_id(channel)++ sign_in(admin)+ put "/t/#{private_message.id}/status.json", params: { status: "closed", enabled: true }++ expect(response.status).to eq(200)+ expect(private_message.reload.assignment.active).to eq(false)++ cookies.to_hash.keys.each { |key| cookies.delete(key) }+ get "/t/#{private_message.id}.json"+ expect(response.status).to eq(404)++ post "/message-bus/poll?dlp=t", params: { channel => message_id }++ expect(response.status).to eq(200)+ expect(response.parsed_body).not_to include(+ include(+ "channel" => channel,+ "data" => {+ "reload_topic" => true,+ "refresh_stream" => true,+ },+ ),+ )+ end+ end+describe "for a private message" dolet(:post) { Fabricate(:private_message_post) }let(:pm) { post.topic }diff --git a/plugins/discourse-assign/spec/integration/message_bus_security_spec.rb b/plugins/discourse-assign/spec/integration/message_bus_security_spec.rbnew file mode 100644index 00000000000..2aa7b42495b--- /dev/null+++ b/plugins/discourse-assign/spec/integration/message_bus_security_spec.rb@@ -0,0 +1,45 @@+# frozen_string_literal: true++RSpec.describe "discourse-assign MessageBus security" do+ fab!(:moderator)+ fab!(:recipient) { Fabricate(:user, refresh_auto_groups: true) }+ fab!(:topic) { Fabricate(:private_message_topic, user: moderator, recipient: recipient) }+ fab!(:assignment) { Fabricate(:topic_assignment, topic: topic, assigned_to: moderator) }++ before do+ SiteSetting.assign_enabled = true+ SiteSetting.unassign_on_close = true+ end++ it "does not expose closing an assigned private message to anonymous MessageBus clients" do+ channel = "/topic/#{topic.id}"+ message_id = MessageBus.last_id(channel)++ sign_in(moderator)+ put "/t/#{topic.id}/status.json", params: { status: "closed", enabled: "true" }++ expect(response.status).to eq(200)+ expect(topic.reload).to be_closed++ cookies.to_hash.keys.each { |key| cookies.delete(key) }+ post "/message-bus/poll?dlp=t", params: { channel => message_id }++ expect(response.status).to eq(200)+ expect(topic_reload_messages(channel)).to be_empty++ sign_in(recipient)+ post "/message-bus/poll?dlp=t", params: { channel => message_id }++ expect(response.status).to eq(200)+ expect(topic_reload_messages(channel)).to contain_exactly(+ include("data" => include("reload_topic" => true, "refresh_stream" => true)),+ )+ end++ def topic_reload_messages(channel)+ response.parsed_body.select do |message|+ message["channel"] == channel &&+ message["data"] == { "reload_topic" => true, "refresh_stream" => true }+ end+ end+end