A platform for community discussion. Free, open, simple.
SECURITY: Whisper metadata disclosure via stale TopicLinks (#41139)
Samfc1946e3f928
diff --git a/app/controllers/composer_messages_controller.rb b/app/controllers/composer_messages_controller.rbindex 2bb63db0e9a..7118eb4f1c8 100644--- a/app/controllers/composer_messages_controller.rb+++ b/app/controllers/composer_messages_controller.rb@@ -11,7 +11,7 @@ class ComposerMessagesController < ApplicationControllerif params[:topic_id].present?topic = Topic.where(id: params[:topic_id]).firstif guardian.can_see?(topic)- json[:extras] = { duplicate_lookup: TopicLink.duplicate_lookup(topic) }+ json[:extras] = { duplicate_lookup: TopicLink.duplicate_lookup(topic, guardian) }endenddiff --git a/app/models/topic_link.rb b/app/models/topic_link.rbindex a5d4cb7ebb8..3093d291e91 100644--- a/app/models/topic_link.rb+++ b/app/models/topic_link.rb@@ -179,14 +179,20 @@ class TopicLink < ActiveRecord::BaseTopicLink.crawl_link_title(id)end- def self.duplicate_lookup(topic)+ def self.duplicate_lookup(topic, guardian = Guardian.new)results =TopicLink.includes(:post, :user).joins(:post, :user).where("posts.id IS NOT NULL AND users.id IS NOT NULL").where(topic_id: topic.id, reflection: false)- .where(posts: { hidden: false })+ .where(+ posts: {+ deleted_at: nil,+ hidden: false,+ post_type: Topic.visible_post_types(guardian.user),+ },+ ).last(200)lookup = {}diff --git a/spec/requests/composer_messages_controller_spec.rb b/spec/requests/composer_messages_controller_spec.rbindex 72da81c66bb..a1d71a50d09 100644--- a/spec/requests/composer_messages_controller_spec.rb+++ b/spec/requests/composer_messages_controller_spec.rb@@ -47,6 +47,33 @@ RSpec.describe ComposerMessagesController doduplicate_lookup = json["extras"]["duplicate_lookup"]expect(duplicate_lookup).not_to have_key("example.com/private-doc")end++ it "does not include links from posts converted to whispers in duplicate_lookup" do+ SiteSetting.whispers_allowed_groups = Group::AUTO_GROUPS[:staff].to_s+ staff_user = Fabricate(:admin)+ whisper_url = "https://staff.example.com/private-doc"+ normalized_whisper_url = whisper_url.delete_prefix("https://")+ reply =+ Fabricate(+ :post,+ topic: topic,+ user: staff_user,+ raw: "Check out #{whisper_url} for details",+ )+ TopicLink.extract_from(reply)++ sign_in(staff_user)+ put "/posts/#{reply.id}/post_type.json", params: { post_type: Post.types[:whisper] }+ expect(response.status).to eq(200)++ sign_in(user)+ get "/composer_messages.json", params: { topic_id: topic.id, composer_action: "reply" }+ expect(response.status).to eq(200)++ json = response.parsed_body+ duplicate_lookup = json["extras"]["duplicate_lookup"]+ expect(duplicate_lookup).not_to have_key(normalized_whisper_url)+ endendend