Skip to content

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

SECURITY: Escape lazy-video provider titles in Chat collapser header (#45027)

Isaac Janzen7a5682410c25
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-message-collapser.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-message-collapser.gjs
index 2d7c40ebed3..b9e1e6474a3 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-message-collapser.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-message-collapser.gjs
@@ -98,7 +98,7 @@ export default class ChatMessageCollapser extends Component {
if (this.siteSettings[`lazy_${videoAttributes.providerName}_enabled`]) {
const link = escapeExpression(videoAttributes.url);
- const title = videoAttributes.title;
+ const title = escapeExpression(videoAttributes.title);
const header = trustHTML(
`<a target="_blank" class="chat-message-collapser-link" rel="noopener noreferrer" href="${link}">${title}</a>`
);
diff --git a/plugins/chat/spec/system/chat_lazy_youtube_spec.rb b/plugins/chat/spec/system/chat_lazy_youtube_spec.rb
index 90e625f476e..ceeb0d4bbe7 100644
--- a/plugins/chat/spec/system/chat_lazy_youtube_spec.rb
+++ b/plugins/chat/spec/system/chat_lazy_youtube_spec.rb
@@ -90,6 +90,28 @@ RSpec.describe "Chat lazy YouTube videos" do
end
end
+ context "with a provider title containing markup" do
+ let(:video_title) do
+ 'Video</a><a class="provider-title-injection" href="https://attacker.example">Open account settings</a>'
+ end
+
+ let(:youtube_url) { "https://www.youtube.com/watch?v=#{video_id}" }
+
+ before do
+ stub_youtube_requests(youtube_url)
+ stub_oembed_request(youtube_url)
+ Oneboxer.invalidate(youtube_url)
+ end
+
+ it "renders the provider title as text rather than a link" do
+ chat_page.visit_channel(channel)
+ channel_page.send_message(youtube_url)
+
+ expect(page).to have_no_css(".provider-title-injection")
+ expect(page).to have_css(".chat-message-collapser-link", text: video_title)
+ end
+ end
+
context "with youtu.be URLs" do
let(:youtu_be_url) { "https://youtu.be/#{video_id}" }