mirror of
https://github.com/discourse/discourse.git
synced 2026-08-11 05:25:16 -05:00
SECURITY: Filter unread bookmark reminders the user cannot see
There is an edge case where the following occurs: 1. The user sets a bookmark reminder on a post/topic 2. The post/topic is changed to a PM before or after the reminder fires, and the notification remains unread by the user 3. The user opens their bookmark reminder notification list and they can still see the notification even though they cannot access the topic anymore There is a very low chance for information leaking here, since the only thing that could be exposed is the topic title if it changes to something sensitive. This commit filters the bookmark unread notifications by using the bookmarkable can_see? methods and also prevents sending reminder notifications for bookmarks the user can no longer see.
This commit is contained in:
committed by
Krzysztof Kotlarek
parent
6183d9633d
commit
3c5fb871c0
@@ -11,7 +11,7 @@ module Chat
|
||||
end
|
||||
|
||||
def self.preload_associations
|
||||
[:chat_channel]
|
||||
[{ chat_channel: :chatable }]
|
||||
end
|
||||
|
||||
def self.list_query(user, guardian)
|
||||
@@ -58,7 +58,8 @@ module Chat
|
||||
end
|
||||
|
||||
def self.reminder_conditions(bookmark)
|
||||
bookmark.bookmarkable.present? && bookmark.bookmarkable.chat_channel.present?
|
||||
bookmark.bookmarkable.present? && bookmark.bookmarkable.chat_channel.present? &&
|
||||
self.can_see?(bookmark.user.guardian, bookmark)
|
||||
end
|
||||
|
||||
def self.can_see?(guardian, bookmark)
|
||||
|
||||
@@ -119,6 +119,13 @@ describe Chat::MessageBookmarkable do
|
||||
bookmark1.reload
|
||||
expect(registered_bookmarkable.can_send_reminder?(bookmark1)).to eq(false)
|
||||
end
|
||||
|
||||
it "cannot send reminder if the user cannot access the channel" do
|
||||
expect(registered_bookmarkable.can_send_reminder?(bookmark1)).to eq(true)
|
||||
bookmark1.bookmarkable.update!(chat_channel: Fabricate(:private_category_channel))
|
||||
bookmark1.reload
|
||||
expect(registered_bookmarkable.can_send_reminder?(bookmark1)).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#reminder_handler" do
|
||||
|
||||
@@ -22,4 +22,33 @@ describe UsersController do
|
||||
expect(membership.following).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#user_menu_bookmarks" do
|
||||
fab!(:chatters) { Fabricate(:group) }
|
||||
let(:current_user) { Fabricate(:user, group_ids: [chatters.id]) }
|
||||
let(:bookmark_message) { Fabricate(:chat_message) }
|
||||
let(:bookmark_user) { current_user }
|
||||
|
||||
before do
|
||||
register_test_bookmarkable(Chat::MessageBookmarkable)
|
||||
SiteSetting.chat_allowed_groups = [chatters]
|
||||
sign_in(current_user)
|
||||
end
|
||||
|
||||
it "does not return any unread notifications for chat bookmarks that the user no longer has access to" do
|
||||
bookmark_with_reminder =
|
||||
Fabricate(:bookmark, user: current_user, bookmarkable: bookmark_message)
|
||||
BookmarkReminderNotificationHandler.new(bookmark_with_reminder).send_notification
|
||||
|
||||
bookmark_with_reminder.bookmarkable.update!(
|
||||
chat_channel: Fabricate(:private_category_channel),
|
||||
)
|
||||
|
||||
get "/u/#{current_user.username}/user-menu-bookmarks"
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
notifications = response.parsed_body["notifications"]
|
||||
expect(notifications.size).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user