A platform for community discussion. Free, open, simple.
SECURITY: only show restricted tag lists to authorized users (#20004)
Bianca Nenciu105fee978d73
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rbindex 1108b618cc7..aa5037e2ea1 100644--- a/app/controllers/tags_controller.rb+++ b/app/controllers/tags_controller.rb@@ -5,12 +5,13 @@ class TagsController < ::ApplicationControllerinclude TopicQueryParamsbefore_action :ensure_tags_enabled- before_action :ensure_visible, only: %i[show info]def self.show_methodsDiscourse.anonymous_filters.map { |f| :"show_#{f}" }end+ before_action :ensure_visible, only: [:show, :info, *show_methods]+requires_login except: [:index, :show, :tag_feed, :search, :info, *show_methods]skip_before_action :check_xhr, only: [:tag_feed, :show, :index, *show_methods]diff --git a/spec/requests/tags_controller_spec.rb b/spec/requests/tags_controller_spec.rbindex 834589618be..ac85694fc7c 100644--- a/spec/requests/tags_controller_spec.rb+++ b/spec/requests/tags_controller_spec.rb@@ -676,6 +676,18 @@ RSpec.describe TagsController doexpect(response.status).to eq(200)end+ it "returns a 404 when tag is restricted" do+ tag_group = Fabricate(:tag_group, permissions: { "staff" => 1 }, tag_names: ["test"])++ get "/tag/test/l/latest.json"+ expect(response.status).to eq(404)++ sign_in(admin)++ get "/tag/test/l/latest.json"+ expect(response.status).to eq(200)+ end+context "with muted tags" dobefore doTagUser.create!(@@ -755,6 +767,18 @@ RSpec.describe TagsController doget "/tag/#{tag.name}/l/top.json?period=decadely"expect(response.status).to eq(400)end++ it "returns a 404 if tag is restricted" do+ tag_group = Fabricate(:tag_group, permissions: { "staff" => 1 }, tag_names: ["test"])++ get "/tag/test/l/top.json"+ expect(response.status).to eq(404)++ sign_in(admin)++ get "/tag/test/l/top.json"+ expect(response.status).to eq(200)+ endenddescribe "#search" do