mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 15:28:37 +08:00
DEV: remove calls to guardian from GroupActionLogger (#13835)
We shouldn't be checking if a user is allowed to do an action in the logger. We should be checking it just before we perform the action. In fact, guardians in the logger can make things even worse in case of a security bug. Let's say we forgot to check user's permissions before performing some action, but we still have a call to the guardian in the logger. In this case, a user would perform the action anyway, and this action wouldn't even be logged! I've checked all cases and I confirm that we're safe to delete this calls from the logger. I've added two calls to guardians in admin/user_controller. We didn't have security bugs there, because regular users can't access admin/... routes at all. But it's good to have calls to guardian in these methods anyway, neighboring methods have them.
This commit is contained in:

committed by
GitHub

parent
32951ca2f4
commit
5a2ad7e386
@ -53,27 +53,18 @@ RSpec.describe GroupActionLogger do
|
||||
context 'as a normal user' do
|
||||
subject { described_class.new(user, group) }
|
||||
|
||||
describe 'user cannot freely exit group' do
|
||||
it 'should not be allowed to log the action' do
|
||||
expect { subject.log_add_user_to_group(user) }
|
||||
.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
before do
|
||||
group.update!(public_admission: true)
|
||||
end
|
||||
|
||||
describe 'user can freely exit group' do
|
||||
before do
|
||||
group.update!(public_admission: true)
|
||||
end
|
||||
it 'should create the right record' do
|
||||
subject.log_add_user_to_group(user)
|
||||
|
||||
it 'should create the right record' do
|
||||
subject.log_add_user_to_group(user)
|
||||
group_history = GroupHistory.last
|
||||
|
||||
group_history = GroupHistory.last
|
||||
|
||||
expect(group_history.action).to eq(GroupHistory.actions[:add_user_to_group])
|
||||
expect(group_history.acting_user).to eq(user)
|
||||
expect(group_history.target_user).to eq(user)
|
||||
end
|
||||
expect(group_history.action).to eq(GroupHistory.actions[:add_user_to_group])
|
||||
expect(group_history.acting_user).to eq(user)
|
||||
expect(group_history.target_user).to eq(user)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -94,27 +85,18 @@ RSpec.describe GroupActionLogger do
|
||||
context 'as a normal user' do
|
||||
subject { described_class.new(user, group) }
|
||||
|
||||
describe 'user cannot freely exit group' do
|
||||
it 'should not be allowed to log the action' do
|
||||
expect { subject.log_remove_user_from_group(user) }
|
||||
.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
before do
|
||||
group.update!(public_exit: true)
|
||||
end
|
||||
|
||||
describe 'user can freely exit group' do
|
||||
before do
|
||||
group.update!(public_exit: true)
|
||||
end
|
||||
it 'should create the right record' do
|
||||
subject.log_remove_user_from_group(user)
|
||||
|
||||
it 'should create the right record' do
|
||||
subject.log_remove_user_from_group(user)
|
||||
group_history = GroupHistory.last
|
||||
|
||||
group_history = GroupHistory.last
|
||||
|
||||
expect(group_history.action).to eq(GroupHistory.actions[:remove_user_from_group])
|
||||
expect(group_history.acting_user).to eq(user)
|
||||
expect(group_history.target_user).to eq(user)
|
||||
end
|
||||
expect(group_history.action).to eq(GroupHistory.actions[:remove_user_from_group])
|
||||
expect(group_history.acting_user).to eq(user)
|
||||
expect(group_history.target_user).to eq(user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user