Skip to content

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

SECURITY: Don't leak hidden tag names in one-per-topic conflict reasons (#41035)

Gabriel Grubba780e6faeb90e
diff --git a/app/services/tags/search.rb b/app/services/tags/search.rb
index b46bed7c82e..9c868e10784 100644
--- a/app/services/tags/search.rb
+++ b/app/services/tags/search.rb
@@ -199,20 +199,24 @@ class Tags::Search
if group
conflicting_tag_names =
- Tag
+ visible_tags(guardian)
.where(id: selected_ids)
.joins(:tag_group_memberships)
.where(tag_group_memberships: { tag_group_id: group.id })
.order(:name)
.pluck(:name)
- return(
- I18n.t(
- "tags.forbidden.one_tag_per_topic_group",
- tag_group_name: group.name,
- tag_names: conflicting_tag_names.join(", "),
+ if conflicting_tag_names.present?
+ return(
+ I18n.t(
+ "tags.forbidden.one_tag_per_topic_group",
+ tag_group_name: group.name,
+ tag_names: conflicting_tag_names.join(", "),
+ )
)
- )
+ end
+
+ return I18n.t("tags.forbidden.one_tag_per_topic_group_without_names")
end
end
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 891c6d815aa..72040858ea3 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -5830,6 +5830,7 @@ en:
synonym: 'Please use "%{tag_name}" instead'
has_synonyms: '"%{tag_name}" cannot be used because it has synonyms.'
one_tag_per_topic_group: 'Conflicts with "%{tag_names}" (only one allowed per topic)'
+ one_tag_per_topic_group_without_names: "Conflicts with a selected tag (only one allowed per topic)"
missing_parent_tag: 'Available after adding the "%{parent_tag_name}" tag'
restricted_tags_cannot_be_used_in_category:
one: 'The "%{tags}" tag cannot be used in the "%{category}" category. Please remove it.'
diff --git a/spec/services/tags/search_spec.rb b/spec/services/tags/search_spec.rb
index b86f3a3ca26..cdb2b4357f3 100644
--- a/spec/services/tags/search_spec.rb
+++ b/spec/services/tags/search_spec.rb
@@ -115,6 +115,36 @@ RSpec.describe(Tags::Search) do
end
end
+ context "with a hidden selected tag in a one_per_topic group" do
+ fab!(:staff_group) { Group[:staff] }
+ fab!(:private_category) { Fabricate(:private_category, group: staff_group) }
+ fab!(:hidden_selected_tag) { Fabricate(:tag, name: "secret-selected") }
+ fab!(:public_sibling_tag) { Fabricate(:tag, name: "public-sibling") }
+ fab!(:tag_group) do
+ Fabricate(
+ :tag_group,
+ name: "Exclusive Group",
+ one_per_topic: true,
+ tags: [hidden_selected_tag, public_sibling_tag],
+ )
+ end
+
+ before { CategoryTag.create!(category: private_category, tag: hidden_selected_tag) }
+
+ let(:params) do
+ { q: "public", filterForInput: true, selected_tag_ids: [hidden_selected_tag.id] }
+ end
+
+ it "uses a generic one_per_topic reason instead of leaking the hidden selected tag name" do
+ disabled = result[:tags].find { |tag| tag[:name] == "public-sibling" && tag[:disabled] }
+ expect(disabled).to be_present
+ expect(disabled[:title]).not_to include(hidden_selected_tag.name)
+ expect(disabled[:title]).to eq(
+ I18n.t("tags.forbidden.one_tag_per_topic_group_without_names"),
+ )
+ end
+ end
+
context "with filterForInput returning disabled tags for missing parent tag" do
fab!(:parent_tag) { Fabricate(:tag, name: "parent") }
fab!(:child_tag) { Fabricate(:tag, name: "childtag") }