Skip to content

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

FIX: prevents destroy post action to leak post (#38015)

Joffrey JAFFEUX8225d94bb31f
diff --git a/app/controllers/post_actions_controller.rb b/app/controllers/post_actions_controller.rb
index 966af4d4bae..333f8258ea4 100644
--- a/app/controllers/post_actions_controller.rb
+++ b/app/controllers/post_actions_controller.rb
@@ -48,7 +48,11 @@ class PostActionsController < ApplicationController
if result.failed?
render_json_error(result)
else
- render_post_json(result.post, add_raw: false)
+ if !guardian.can_see_post?(result.post)
+ head :no_content
+ else
+ render_post_json(result.post, add_raw: false)
+ end
end
end
diff --git a/spec/requests/post_actions_controller_spec.rb b/spec/requests/post_actions_controller_spec.rb
index d23cd4a524b..92e64b9a1ff 100644
--- a/spec/requests/post_actions_controller_spec.rb
+++ b/spec/requests/post_actions_controller_spec.rb
@@ -72,6 +72,27 @@ RSpec.describe PostActionsController do
expect(response).to be_forbidden
end
+
+ it "does not return post content when the user can no longer see the post" do
+ restricted_category = Fabricate(:category, read_restricted: true)
+ post.topic.update!(category: restricted_category)
+
+ delete "/post_actions/#{post.id}.json",
+ params: {
+ post_action_type_id: PostActionType.types[:like],
+ }
+
+ expect(response.status).to eq(204)
+ expect(response.body).to be_blank
+ expect(
+ PostAction.exists?(
+ user_id: user.id,
+ post_id: post.id,
+ post_action_type_id: PostActionType.types[:like],
+ deleted_at: nil,
+ ),
+ ).to eq(false)
+ end
end
end
end