A platform for community discussion. Free, open, simple.
SECURITY: Fix XSS in rich editor chat transcript channel link (#44023)
David Taylor888124f3b315
diff --git a/plugins/chat/assets/javascripts/lib/discourse-markdown/chat-transcript.js b/plugins/chat/assets/javascripts/lib/discourse-markdown/chat-transcript.jsindex ea75ea44c5e..382dfcfe69f 100644--- a/plugins/chat/assets/javascripts/lib/discourse-markdown/chat-transcript.js+++ b/plugins/chat/assets/javascripts/lib/discourse-markdown/chat-transcript.js@@ -1,4 +1,5 @@import { performEmojiUnescape } from "pretty-text/emoji";+import escape from "discourse/lib/escape";import { i18n } from "discourse-i18n";// NOTE: When updating this file you also must consider the ProseMirror rich editor extension@@ -65,7 +66,7 @@ const chatTranscriptRule = {channelToken.content = i18n("chat.quote.original_channel", {channel: unescapedChannelName,- channelLink,+ channelLink: channelLink && escape(channelLink),});state.push("div_chat_transcript_meta_close", "div", -1);}diff --git a/plugins/chat/assets/javascripts/lib/rich-editor-extension.js b/plugins/chat/assets/javascripts/lib/rich-editor-extension.jsindex 875e03ff704..8e218171315 100644--- a/plugins/chat/assets/javascripts/lib/rich-editor-extension.js+++ b/plugins/chat/assets/javascripts/lib/rich-editor-extension.js@@ -50,8 +50,13 @@ const extension = {metaElement.innerHTML = i18n("chat.quote.original_channel", {channel: dReplaceEmoji(node.attrs.channel),- channelLink,+ channelLink: "",});++ const metaLinkElement = metaElement.querySelector("a");+ if (metaLinkElement && channelLink) {+ metaLinkElement.href = channelLink;+ }} else {channelLinkElement = document.createElement("a");channelLinkElement.classList.add("chat-transcript-channel");diff --git a/plugins/chat/spec/system/rich_editor_extension_transcript_spec.rb b/plugins/chat/spec/system/rich_editor_extension_transcript_spec.rbindex e394dd315b4..0db69c74471 100644--- a/plugins/chat/spec/system/rich_editor_extension_transcript_spec.rb+++ b/plugins/chat/spec/system/rich_editor_extension_transcript_spec.rb@@ -185,5 +185,32 @@ describe "chat transcripts in rich editor" doexpect(rich).to have_css(".chat-transcript")endend++ it "keeps a channel ID which closes the href inside the href" do+ page.visit "/new-topic"+ expect(composer).to be_opened+ composer.focus++ channel_id = %q(" onmouseover="alert(1)" x=")+ markdown = <<~MARKDOWN+ [chat quote="hunter;29856;2025-03-20T07:13:04Z" channel="design" channelId='#{channel_id}' multiQuote=true]+ haha+ [/chat]+ MARKDOWN++ cdp.copy_paste(markdown, css_selector: composer.composer_input_selector)++ expect(rich).to have_css(".chat-transcript-meta a")++ attributes = page.evaluate_script(<<~JS)+ Object.fromEntries(+ Array.from(+ document.querySelector(".d-editor-input.ProseMirror .chat-transcript-meta a").attributes+ ).map((attribute) => [attribute.name, attribute.value])+ )+ JS++ expect(attributes).to eq({ "href" => "/chat/c/-/#{channel_id}" })+ endendend