A platform for community discussion. Free, open, simple.
SECURITY: Access control bypass in PM email recipients defeats message opt-out (#41932)
Keegan Georged92c1e56aa6e
diff --git a/lib/topic_creator.rb b/lib/topic_creator.rbindex e8179172bec..da657b12f04 100644--- a/lib/topic_creator.rb+++ b/lib/topic_creator.rb@@ -322,6 +322,8 @@ class TopicCreatordisplay_name = email.split("@").firstif user = find_or_create_user(email, display_name)+ check_can_send_permission!(topic, user)+if !@added_users.include?(user)@added_users << usertopic.topic_allowed_users.build(user_id: user.id)@@ -330,7 +332,7 @@ class TopicCreatorendendensure- rollback_with!(topic, :target_user_not_found) unless len == emails.length+ rollback_with!(topic, :target_user_not_found) if topic.errors.blank? && len != emails.lengthendenddiff --git a/spec/requests/posts_controller_spec.rb b/spec/requests/posts_controller_spec.rbindex c780ce70e0d..5ee1abac2dd 100644--- a/spec/requests/posts_controller_spec.rb+++ b/spec/requests/posts_controller_spec.rb@@ -1356,6 +1356,34 @@ RSpec.describe PostsController doexpect(new_topic.external_id).to eq("external_id")end+ it "blocks email private message recipients that disabled private messages" do+ SiteSetting.enable_staged_users = true+ SiteSetting.personal_message_enabled_groups = Group::AUTO_GROUPS[:trust_level_4]+ SiteSetting.send_email_messages_allowed_groups = Group::AUTO_GROUPS[:trust_level_4]+ sender = Fabricate(:trust_level_4, refresh_auto_groups: true)+ recipient = Fabricate(:user)+ recipient.user_option.update!(allow_private_messages: false)+ api_key = ApiKey.create!(user: sender).key++ post "/posts.json",+ params: {+ raw: "this is the test content",+ title: "this is some post",+ archetype: Archetype.private_message,+ target_recipients: recipient.email,+ },+ headers: {+ HTTP_API_USERNAME: sender.username,+ HTTP_API_KEY: api_key,+ }++ expect(response.status).to eq(422)+ expect(response.parsed_body["errors"]).to include(+ I18n.t("activerecord.errors.models.topic.attributes.base.cant_send_pm"),+ )+ expect(TopicAllowedUser.exists?(user: recipient)).to eq(false)+ end+it "prevents whispers for regular users" dopost_1 = Fabricate(:post)user_key = ApiKey.create!(user: user).key