A platform for community discussion. Free, open, simple.
FIX: Missing visibility authorization in `flag` allows flagging comments in inaccessible topics (#37856)
Sam1fa926470b12
diff --git a/plugins/discourse-post-voting/lib/post_voting/guardian_extension.rb b/plugins/discourse-post-voting/lib/post_voting/guardian_extension.rbindex 36d61339cf0..2a990ca7f6c 100644--- a/plugins/discourse-post-voting/lib/post_voting/guardian_extension.rb+++ b/plugins/discourse-post-voting/lib/post_voting/guardian_extension.rb@@ -23,6 +23,7 @@ module PostVotingdef can_flag_post_voting_comment?(comment)return false if !authenticated? || !comment || comment.trashed? || !comment.user+ return false if !can_see?(comment.post)return false if comment.user.staff? && !SiteSetting.allow_flagging_staffreturn false if comment.user_id == @user.iddiff --git a/plugins/discourse-post-voting/spec/requests/post_voting/comments_controller_spec.rb b/plugins/discourse-post-voting/spec/requests/post_voting/comments_controller_spec.rbindex 211900e2662..dd2e2df404b 100644--- a/plugins/discourse-post-voting/spec/requests/post_voting/comments_controller_spec.rb+++ b/plugins/discourse-post-voting/spec/requests/post_voting/comments_controller_spec.rb@@ -361,4 +361,23 @@ RSpec.describe PostVoting::CommentsController do).to eq(true)endend++ describe "#flag" do+ fab!(:flagger) { Fabricate(:user, group_ids: [Group::AUTO_GROUPS[:trust_level_1]]) }++ before { sign_in(flagger) }++ it "should return 403 when trying to flag a comment on a post the user cannot see" do+ category.set_permissions(group => :full)+ category.save!++ put "/post_voting/comments/flag.json",+ params: {+ comment_id: comment.id,+ flag_type_id: ReviewableScore.types[:off_topic],+ }++ expect(response.status).to eq(403)+ end+ endend