/comments.atom: fix restricted posts being leaked.

Fix thumbnail URLs of loli/shota/banned posts being leaked in
/comments.atom. Restricted posts are now entirely hidden in
/comments.atom.

Example: https://danbooru.donmai.us/comments.atom?search[post_id]=2.
This commit is contained in:
evazion
2020-07-05 15:53:47 -05:00
parent d9b7879a4c
commit f0a573e1e5
3 changed files with 17 additions and 3 deletions

View File

@@ -97,6 +97,7 @@ class CommentsController < ApplicationController
if request.format.atom?
@comments = @comments.includes(:creator, :post)
@comments = @comments.select { |comment| comment.post.visible? }
elsif request.format.html?
@comments = @comments.includes(:creator, :updater, post: :uploader)
@comments = @comments.includes(:votes) if CurrentUser.is_member?

View File

@@ -93,9 +93,21 @@ class CommentsControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end
should "render for atom feeds" do
get comments_path(format: "atom")
assert_response :success
context "for atom feeds" do
should "render" do
@comment = as(@user) { create(:comment, post: @post) }
get comments_path(format: "atom")
assert_response :success
end
should "not show comments on restricted posts" do
@post.update!(is_banned: true)
@comment = as(@user) { create(:comment, post: @post) }
get comments_path(format: "atom")
assert_response :success
assert_equal(0, response.parsed_body.css("entry").size)
end
end
end

View File

@@ -64,6 +64,7 @@ class ActionDispatch::IntegrationTest
extend ControllerHelper
register_encoder :xml, response_parser: ->(body) { Nokogiri.XML(body) }
register_encoder :atom, response_parser: ->(body) { Nokogiri.XML(body) }
register_encoder :html, response_parser: ->(body) { Nokogiri.HTML5(body) }
def method_authenticated(method_name, url, user, **options)