A platform for community discussion. Free, open, simple.
SECURITY: mentionable/messageable endpoints bypassing visibility controls (#41514)
Isaac Janzenc494752c7ed7
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rbindex 947db30c514..a2e845621ff 100644--- a/app/controllers/groups_controller.rb+++ b/app/controllers/groups_controller.rb@@ -538,7 +538,7 @@ class GroupsController < ApplicationControllerenddef mentionable- group = find_group(:name, ensure_can_see: false)+ group = find_group(:name)if grouprender json: { mentionable: Group.mentionable(current_user).where(id: group.id).present? }@@ -548,7 +548,7 @@ class GroupsController < ApplicationControllerenddef messageable- group = find_group(:name, ensure_can_see: false)+ group = find_group(:name)if grouprender json: { messageable: guardian.can_send_private_message?(group) }diff --git a/spec/requests/groups_controller_spec.rb b/spec/requests/groups_controller_spec.rbindex 75dbd1268e3..bce7efd9b56 100644--- a/spec/requests/groups_controller_spec.rb+++ b/spec/requests/groups_controller_spec.rb@@ -1072,6 +1072,39 @@ RSpec.describe GroupsController doendend+ describe "#mentionable and #messageable" do+ it "returns not found for hidden and missing groups", :aggregate_failures do+ user.change_trust_level!(1)+ hidden_group =+ Fabricate(+ :group,+ name: "hidden_support",+ mentionable_level: Group::ALIAS_LEVELS[:everyone],+ messageable_level: Group::ALIAS_LEVELS[:everyone],+ visibility_level: Group.visibility_levels[:staff],+ )+ missing_group_name = "missing_support"++ sign_in(user)++ get "/g/#{hidden_group.name}/mentionable.json"+ expect(response.status).to eq(404)+ expect(response.parsed_body["error_type"]).to eq("not_found")++ get "/g/#{missing_group_name}/mentionable.json"+ expect(response.status).to eq(404)+ expect(response.parsed_body["error_type"]).to eq("not_found")++ get "/g/#{hidden_group.name}/messageable.json"+ expect(response.status).to eq(404)+ expect(response.parsed_body["error_type"]).to eq("not_found")++ get "/g/#{missing_group_name}/messageable.json"+ expect(response.status).to eq(404)+ expect(response.parsed_body["error_type"]).to eq("not_found")+ end+ end+describe "#mentionable" doit "should return the right response" dosign_in(user)@@ -1089,7 +1122,7 @@ RSpec.describe GroupsController dogroup.update!(mentionable_level: Group::ALIAS_LEVELS[:everyone],- visibility_level: Group.visibility_levels[:staff],+ visibility_level: Group.visibility_levels[:logged_on_users],)get "/groups/#{group.name}/mentionable.json"@@ -1124,7 +1157,7 @@ RSpec.describe GroupsController dogroup.update!(messageable_level: Group::ALIAS_LEVELS[:everyone],- visibility_level: Group.visibility_levels[:staff],+ visibility_level: Group.visibility_levels[:logged_on_users],)get "/groups/#{group.name}/messageable.json"