Skip to content

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

FIX: Apply filter_visible and guardian to list tags AI tool (#45041)

Isaac Janzen2229ff84a7dd
diff --git a/plugins/discourse-ai/lib/agents/tools/list_tags.rb b/plugins/discourse-ai/lib/agents/tools/list_tags.rb
index 83313ec88b3..3b808041b37 100644
--- a/plugins/discourse-ai/lib/agents/tools/list_tags.rb
+++ b/plugins/discourse-ai/lib/agents/tools/list_tags.rb
@@ -19,8 +19,8 @@ module DiscourseAi
column_names = { name: "Name", public_topic_count: "Topic Count" }
tags =
- Tag
- .where("public_topic_count > 0")
+ DiscourseTagging
+ .filter_visible(Tag.where("public_topic_count > 0"), Guardian.new)
.order(public_topic_count: :desc)
.limit(100)
.pluck(*column_names.keys)
diff --git a/plugins/discourse-ai/spec/lib/agents/tools/list_tags_spec.rb b/plugins/discourse-ai/spec/lib/agents/tools/list_tags_spec.rb
index 97d163bd30e..8a6c5661388 100644
--- a/plugins/discourse-ai/spec/lib/agents/tools/list_tags_spec.rb
+++ b/plugins/discourse-ai/spec/lib/agents/tools/list_tags_spec.rb
@@ -21,5 +21,16 @@ RSpec.describe DiscourseAi::Agents::Tools::ListTags do
expect(info.to_s).to include("america")
expect(info.to_s).not_to include("not_here")
end
+
+ it "does not leak hidden staff-only tag names" do
+ Fabricate(:tag, name: "america", public_topic_count: 100)
+ hidden_tag = Fabricate(:tag, name: "secret_staff_tag", public_topic_count: 50)
+ Fabricate(:tag_group, permissions: { "staff" => 1 }, tag_names: [hidden_tag.name])
+
+ info = described_class.new({}, bot_user: bot_user, llm: llm).invoke
+
+ expect(info.to_s).to include("america")
+ expect(info.to_s).not_to include("secret_staff_tag")
+ end
end
end