A platform for community discussion. Free, open, simple.
SECURITY: Correctly parse URLs in chat excerpts
Jan Cernik1da97de7f0b4
diff --git a/plugins/chat/app/models/chat/message.rb b/plugins/chat/app/models/chat/message.rbindex 1e92d77f931..1e03efc2db4 100644--- a/plugins/chat/app/models/chat/message.rb+++ b/plugins/chat/app/models/chat/message.rb@@ -122,7 +122,14 @@ module Chatdef build_excerpt# just show the URL if the whole message is a URL, because we cannot excerpt oneboxes- return message if UrlHelper.relaxed_parse(message).is_a?(URI)+ urls = PrettyText.extract_links(cooked).map(&:url)+ if urls.present?+ regex = %r{^[^:]+://}+ clean_urls = urls.map { |url| url.sub(regex, "") }+ if message.gsub(regex, "").split.sort == clean_urls.sort+ return PrettyText.excerpt(urls.join(" "), EXCERPT_LENGTH)+ end+ end# upload-only messages are better represented as the filenamereturn uploads.first.original_filename if cooked.blank? && uploads.present?diff --git a/plugins/chat/spec/system/chat_channel_spec.rb b/plugins/chat/spec/system/chat_channel_spec.rbindex 08583ac896b..64040cc1005 100644--- a/plugins/chat/spec/system/chat_channel_spec.rb+++ b/plugins/chat/spec/system/chat_channel_spec.rb@@ -296,6 +296,15 @@ RSpec.describe "Chat channel", type: :system do)end+ it "renders escaped HTML when including a #" do+ update_message!(message_2, user: other_user, text: "#general <abbr>not abbr</abbr>")+ chat_page.visit_channel(channel_1)++ expect(find(".chat-reply .chat-reply__excerpt")["innerHTML"].strip).to eq(+ "#general <abbr>not abbr</abbr>",+ )+ end+it "renders safe HTML like mentions (which are just links) in the reply-to" doupdate_message!(message_2,