From 9fd87818083fad2938f2d92fcc332d03997449fd Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Tue, 6 Sep 2022 10:40:51 -0300 Subject: [PATCH] parse deep link only if hostname matches (#6619) --- app/utils/url/index.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/utils/url/index.ts b/app/utils/url/index.ts index 86b6ab0a0..232e16bf1 100644 --- a/app/utils/url/index.ts +++ b/app/utils/url/index.ts @@ -174,20 +174,22 @@ export function matchDeepLink(url?: string, serverURL?: string, siteURL?: string } let urlToMatch = url; + const urlBase = serverURL || siteURL || ''; if (!url.startsWith('mattermost://')) { // If url doesn't contain site or server URL, tack it on. // e.g. URLs from autolink plugin. - const urlBase = serverURL || siteURL || ''; const match = new RegExp(escapeRegex(urlBase)).exec(url); if (!match) { urlToMatch = urlBase + url; } } - const parsedDeepLink = parseDeepLink(urlToMatch); - if (parsedDeepLink.type !== DeepLink.Invalid) { - return parsedDeepLink; + if (urlParse(urlToMatch).hostname === urlParse(urlBase).hostname) { + const parsedDeepLink = parseDeepLink(urlToMatch); + if (parsedDeepLink.type !== DeepLink.Invalid) { + return parsedDeepLink; + } } return null;