From 5c01944cfb661bfd8c70c9276f1eda5b5b353f63 Mon Sep 17 00:00:00 2001 From: Jamie <31554168+flaree@users.noreply.github.com> Date: Sun, 22 Aug 2021 03:39:30 -0700 Subject: [PATCH 1/4] Handle subdomains on URLs --- src/components/markdown/Renderer.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/markdown/Renderer.tsx b/src/components/markdown/Renderer.tsx index fe73b11a..c33f4a09 100644 --- a/src/components/markdown/Renderer.tsx +++ b/src/components/markdown/Renderer.tsx @@ -172,7 +172,7 @@ export default function Renderer({ content, disallowBigEmoji }: MarkdownProps) { try { const url = new URL(href, location.href); - if (url.hostname === location.hostname) { + if (url.hostname.replace(/^[^.]+\./g, "") === location.hostname.replace(/^[^.]+\./g, "")) { internal = true; element.addEventListener( "click", From 852cc22dc29c8f121037254f80b2123b39b87e59 Mon Sep 17 00:00:00 2001 From: Jamie <31554168+flaree@users.noreply.github.com> Date: Sun, 22 Aug 2021 04:31:48 -0700 Subject: [PATCH 2/4] Update Renderer.tsx --- src/components/markdown/Renderer.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/markdown/Renderer.tsx b/src/components/markdown/Renderer.tsx index c33f4a09..7065fbb7 100644 --- a/src/components/markdown/Renderer.tsx +++ b/src/components/markdown/Renderer.tsx @@ -172,7 +172,7 @@ export default function Renderer({ content, disallowBigEmoji }: MarkdownProps) { try { const url = new URL(href, location.href); - if (url.hostname.replace(/^[^.]+\./g, "") === location.hostname.replace(/^[^.]+\./g, "")) { + if (url.hostname.replace(/^[^.]+\./g, "") === location.hostname.replace(/^[^.]+\./g, "") && ["nightly.", "app.", "local."].includes(url.hostname.match(/^[^.]+\./g)?.[0] ?? "")) { internal = true; element.addEventListener( "click", From c4b881a52551e97d11e0f28487618a89406dc005 Mon Sep 17 00:00:00 2001 From: Jamie <31554168+flaree@users.noreply.github.com> Date: Mon, 23 Aug 2021 04:38:21 -0700 Subject: [PATCH 3/4] Update Renderer.tsx --- src/components/markdown/Renderer.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/markdown/Renderer.tsx b/src/components/markdown/Renderer.tsx index 7065fbb7..34e5d25f 100644 --- a/src/components/markdown/Renderer.tsx +++ b/src/components/markdown/Renderer.tsx @@ -32,6 +32,13 @@ declare global { } } +const ALLOWED_ORIGINS = [ + location.hostname, + 'app.revolt.chat', + 'nightly.revolt.chat', + 'local.revolt.chat', +]; + // Handler for code block copy. if (typeof window !== "undefined") { window.copycode = function (element: HTMLDivElement) { @@ -172,7 +179,7 @@ export default function Renderer({ content, disallowBigEmoji }: MarkdownProps) { try { const url = new URL(href, location.href); - if (url.hostname.replace(/^[^.]+\./g, "") === location.hostname.replace(/^[^.]+\./g, "") && ["nightly.", "app.", "local."].includes(url.hostname.match(/^[^.]+\./g)?.[0] ?? "")) { + if (ALLOWED_ORIGINS.includes(url.hostname)) { internal = true; element.addEventListener( "click", From 2d3afdaa83f450dedb7d96d939d6bf0ec69c8b8a Mon Sep 17 00:00:00 2001 From: Jamie <31554168+flaree@users.noreply.github.com> Date: Mon, 23 Aug 2021 04:42:18 -0700 Subject: [PATCH 4/4] fix indentation --- src/components/markdown/Renderer.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/markdown/Renderer.tsx b/src/components/markdown/Renderer.tsx index 34e5d25f..d96ef898 100644 --- a/src/components/markdown/Renderer.tsx +++ b/src/components/markdown/Renderer.tsx @@ -33,10 +33,10 @@ declare global { } const ALLOWED_ORIGINS = [ - location.hostname, - 'app.revolt.chat', - 'nightly.revolt.chat', - 'local.revolt.chat', + location.hostname, + 'app.revolt.chat', + 'nightly.revolt.chat', + 'local.revolt.chat', ]; // Handler for code block copy.