A platform for community discussion. Free, open, simple.
SECURITY: Ensure guardian check when creating QueryGroupBookmark
Martin Brennan3cdb52b38b63
diff --git a/app/services/base_bookmarkable.rb b/app/services/base_bookmarkable.rbindex f68748c62b3..d232c46be1d 100644--- a/app/services/base_bookmarkable.rb+++ b/app/services/base_bookmarkable.rb@@ -182,7 +182,7 @@ class BaseBookmarkable# @param [Guardian] guardian The guardian for the user which is creating the bookmark.# @param [Model] bookmarkable The ActiveRecord model which is acting as the bookmarkable for the new bookmark.def self.validate_before_create(guardian, bookmarkable)- # noop+ raise NotImplementedErrorend##diff --git a/plugins/discourse-data-explorer/lib/discourse_data_explorer/query_group_bookmarkable.rb b/plugins/discourse-data-explorer/lib/discourse_data_explorer/query_group_bookmarkable.rbindex 37dde1a38bd..7834bfcca61 100644--- a/plugins/discourse-data-explorer/lib/discourse_data_explorer/query_group_bookmarkable.rb+++ b/plugins/discourse-data-explorer/lib/discourse_data_explorer/query_group_bookmarkable.rb@@ -39,6 +39,12 @@ module DiscourseDataExplorerbookmarkable_search.call(bookmarks, "data_explorer_queries.name ILIKE ?")end+ def self.validate_before_create(guardian, bookmarkable)+ if bookmarkable.blank? || !can_see_bookmarkable?(guardian, bookmarkable)+ raise Discourse::InvalidAccess+ end+ end+def self.reminder_handler(bookmark)send_reminder_notification(bookmark,diff --git a/plugins/discourse-data-explorer/spec/lib/data_explorer/query_group_bookmarkable_spec.rb b/plugins/discourse-data-explorer/spec/lib/data_explorer/query_group_bookmarkable_spec.rbindex 9399fced1b9..42776cd0b33 100644--- a/plugins/discourse-data-explorer/spec/lib/data_explorer/query_group_bookmarkable_spec.rb+++ b/plugins/discourse-data-explorer/spec/lib/data_explorer/query_group_bookmarkable_spec.rb@@ -160,6 +160,27 @@ describe DiscourseDataExplorer::QueryGroupBookmarkable doendend+ describe "#validate_before_create" do+ it "raises InvalidAccess if the bookmarkable is blank" do+ expect { registered_bookmarkable.validate_before_create(guardian, nil) }.to raise_error(+ Discourse::InvalidAccess,+ )+ end++ it "raises InvalidAccess if the user is not a member of the bookmarkable group" do+ non_member_guardian = Guardian.new(Fabricate(:user))+ expect {+ registered_bookmarkable.validate_before_create(non_member_guardian, query_group4)+ }.to raise_error(Discourse::InvalidAccess)+ end++ it "does not raise if the user is a member of the bookmarkable group" do+ expect {+ registered_bookmarkable.validate_before_create(guardian, query_group1)+ }.not_to raise_error+ end+ end+describe "#can_see?" doit "returns false if the user is not a member of the group from which they created the bookmark" doexpect(registered_bookmarkable.can_see?(guardian, bookmark1)).to eq(true) # Query 1, Group 0