Skip to content

A platform for community discussion. Free, open, simple.

SECURITY: Omit notification `display_name` from response when `enable_names` is disabled (#43983)

jbrwdc24a92d9d42
diff --git a/app/serializers/notification_serializer.rb b/app/serializers/notification_serializer.rb
index 263fd60b994..ae04d3aac35 100644
--- a/app/serializers/notification_serializer.rb
+++ b/app/serializers/notification_serializer.rb
@@ -32,7 +32,9 @@ class NotificationSerializer < ApplicationSerializer
end
def data
- object.data_hash
+ return object.data_hash if SiteSetting.enable_names?
+
+ object.data_hash.except(:display_name)
end
def external_id
diff --git a/spec/requests/notifications_controller_spec.rb b/spec/requests/notifications_controller_spec.rb
index dd999bfefa7..10e58d9c460 100644
--- a/spec/requests/notifications_controller_spec.rb
+++ b/spec/requests/notifications_controller_spec.rb
@@ -505,6 +505,31 @@ RSpec.describe NotificationsController do
end
end
+ context "with names disabled" do
+ fab!(:mentioner) { Fabricate(:user, name: "Hidden Mentioner Name") }
+
+ before { SiteSetting.enable_names = false }
+
+ it "does not expose a mentioner's full name" do
+ post = Fabricate(:post, user: mentioner, raw: "@#{user.username}")
+ PostAlerter.post_created(post)
+
+ mention_notification =
+ user.notifications.find_by!(notification_type: Notification.types[:mentioned])
+ expect(mention_notification.data_hash[:display_name]).to eq(mentioner.name)
+
+ get "/notifications.json"
+
+ expect(response.status).to eq(200)
+ notification =
+ response.parsed_body["notifications"].find do |item|
+ item["id"] == mention_notification.id
+ end
+ expect(notification["data"]).not_to have_key("display_name")
+ expect(response.body).not_to include(mentioner.name)
+ end
+ end
+
context "with user-menu avatars enabled and names disabled" do
fab!(:liker) { Fabricate(:user, name: "Hidden Liker Name") }
fab!(:liked_post) { Fabricate(:post, user: user) }