mirror of
https://github.com/discourse/discourse.git
synced 2026-08-04 10:23:17 -05:00
SECURITY: AdminDetailedUserSerializer#latest_export leaking user exports
There were no guardian checks to ensure that the `AdminDetailedUserSerializer#lastest_export` attribute can only be viewed by the right users. Follow-up: bf75bd3b0ce77750899605c2145c93cd073ef2a1
This commit is contained in:
committed by
David Taylor
parent
357febfb47
commit
8f82f1206f
@@ -185,6 +185,10 @@ class AdminDetailedUserSerializer < AdminUserSerializer
|
||||
UserExportSerializer.new(export, scope:).as_json if export
|
||||
end
|
||||
|
||||
def include_latest_export?
|
||||
scope.can_export_entity?("user_archive", object.id)
|
||||
end
|
||||
|
||||
def upcoming_changes_stats
|
||||
object.upcoming_change_stats(scope)
|
||||
end
|
||||
|
||||
@@ -14,4 +14,16 @@ RSpec.describe AdminDetailedUserSerializer do
|
||||
json = serializer.as_json
|
||||
expect(json[:name]).to be_nil
|
||||
end
|
||||
|
||||
describe "#latest_export" do
|
||||
fab!(:user_export) { UserExport.create!(file_name: "test", user:, upload: Fabricate(:upload)) }
|
||||
|
||||
it "is only included for admins" do
|
||||
serializer = described_class.new(user, scope: Guardian.new(admin), root: false)
|
||||
expect(serializer.as_json[:latest_export][:user_export][:id]).to eq(user_export.id)
|
||||
|
||||
serializer = described_class.new(user, scope: Guardian.new(moderator), root: false)
|
||||
expect(serializer.as_json[:latest_export]).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user