discourse/app/serializers/concerns/user_sidebar_mixin.rb
Alan Guo Xiang Tan f122f24b35
SECURITY: Default tags to show count of topics in unrestricted categories (#19916)
Currently, `Tag#topic_count` is a count of all regular topics regardless of whether the topic is in a read restricted category or not. As a result, any users can technically poll a sensitive tag to determine if a new topic is created in a category which the user has not excess to. We classify this as a minor leak in sensitive information.

The following changes are introduced in this commit:

1. Introduce `Tag#public_topic_count` which only count topics which have been tagged with a given tag in public categories.
2. Rename `Tag#topic_count` to `Tag#staff_topic_count` which counts the same way as `Tag#topic_count`. In other words, it counts all topics tagged with a given tag regardless of the category the topic is in. The rename is also done so that we indicate that this column contains sensitive information. 
3. Change all previous spots which relied on `Topic#topic_count` to rely on `Tag.topic_column_count(guardian)` which will return the right "topic count" column to use based on the current scope. 
4. Introduce `SiteSetting.include_secure_categories_in_tag_counts` site setting to allow site administrators to always display the tag topics count using `Tag#staff_topic_count` instead.
2023-01-20 09:50:24 +08:00

53 lines
1.2 KiB
Ruby

# frozen_string_literal: true
module UserSidebarMixin
def sidebar_tags
topic_count_column = Tag.topic_count_column(scope)
object
.visible_sidebar_tags(scope)
.pluck(:name, topic_count_column, :pm_topic_count)
.reduce([]) do |tags, sidebar_tag|
tags.push(name: sidebar_tag[0], pm_only: sidebar_tag[1] == 0 && sidebar_tag[2] > 0)
end
end
def display_sidebar_tags
DiscourseTagging.filter_visible(Tag, scope).exists?
end
def include_display_sidebar_tags?
include_sidebar_tags?
end
def include_sidebar_tags?
SiteSetting.tagging_enabled && sidebar_navigation_menu?
end
def sidebar_category_ids
object.category_sidebar_section_links.pluck(:linkable_id) & scope.allowed_category_ids
end
def include_sidebar_category_ids?
sidebar_navigation_menu?
end
def sidebar_list_destination
if object.user_option.sidebar_list_none_selected?
SiteSetting.default_sidebar_list_destination
else
object.user_option.sidebar_list_destination
end
end
def include_sidebar_list_destination?
sidebar_navigation_menu?
end
private
def sidebar_navigation_menu?
!SiteSetting.legacy_navigation_menu? || options[:enable_sidebar_param] == "1"
end
end