From b568741d43b7ae610cffe8a10afdfee6706c665c Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 8 Jul 2022 16:01:59 -0600 Subject: [PATCH] Safely grab the OpenGraph title out of the URL preview for link safety --- src/components/views/rooms/LinkPreviewWidget.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/views/rooms/LinkPreviewWidget.tsx b/src/components/views/rooms/LinkPreviewWidget.tsx index af0b8a022e6..25d5fdd00b1 100644 --- a/src/components/views/rooms/LinkPreviewWidget.tsx +++ b/src/components/views/rooms/LinkPreviewWidget.tsx @@ -120,8 +120,9 @@ export default class LinkPreviewWidget extends React.Component { // opaque string. This does not allow any HTML to be injected into the DOM. const description = AllHtmlEntities.decode(p["og:description"] || ""); - const anchor = { p["og:title"] }; - const needsTooltip = PlatformPeg.get()?.needsUrlTooltips() && this.props.link !== p["og:title"].trim(); + const title = p["og:title"]?.trim() ?? ""; + const anchor = { title }; + const needsTooltip = PlatformPeg.get()?.needsUrlTooltips() && this.props.link !== title; return (