mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 16:57:16 +08:00
SECURITY: Show only visible tags in metadata
Currently, the topic metadata show both public and private tags whereas only visible ones should be exposed.
This commit is contained in:

committed by
Loïc Guitaut

parent
5dbdcb3f23
commit
a9f2c6db64
@ -2507,6 +2507,28 @@ RSpec.describe TopicsController do
|
||||
expect(body).to have_tag(:script, src: "/assets/discourse.js")
|
||||
expect(body).to have_tag(:meta, with: { name: "fragment" })
|
||||
end
|
||||
|
||||
context "with restricted tags" do
|
||||
let(:tag_group) { Fabricate.build(:tag_group) }
|
||||
let(:tag_group_permission) { Fabricate.build(:tag_group_permission, tag_group: tag_group) }
|
||||
let(:restricted_tag) { Fabricate(:tag) }
|
||||
let(:public_tag) { Fabricate(:tag) }
|
||||
|
||||
before do
|
||||
# avoid triggering a `before_create` callback in `TagGroup` which
|
||||
# messes with permissions
|
||||
tag_group.tag_group_permissions << tag_group_permission
|
||||
tag_group.save!
|
||||
tag_group_permission.tag_group.tags << restricted_tag
|
||||
topic.tags << [public_tag, restricted_tag]
|
||||
end
|
||||
|
||||
it "doesn’t expose restricted tags" do
|
||||
get "/t/#{topic.slug}/#{topic.id}/print", headers: { HTTP_USER_AGENT: "Rails Testing" }
|
||||
expect(response.body).to match(public_tag.name)
|
||||
expect(response.body).not_to match(restricted_tag.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "records redirects" do
|
||||
|
Reference in New Issue
Block a user