From 51f23f5aa0eedbda559d18fdd646ba56e3426c2e Mon Sep 17 00:00:00 2001 From: Paul Date: Fri, 17 Sep 2021 09:37:07 +0100 Subject: [PATCH] Include noreferrer on embed links / window.open. --- src/components/markdown/Renderer.tsx | 3 +-- src/context/intermediate/Intermediate.tsx | 6 +++--- .../intermediate/modals/ExternalLinkPrompt.tsx | 17 ++++++++++------- src/pages/settings/panes/Feedback.tsx | 2 +- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/components/markdown/Renderer.tsx b/src/components/markdown/Renderer.tsx index 9656d54a..ede8dd7d 100644 --- a/src/components/markdown/Renderer.tsx +++ b/src/components/markdown/Renderer.tsx @@ -19,8 +19,6 @@ import { useCallback, useContext } from "preact/hooks"; import { internalEmit } from "../../lib/eventEmitter"; import { determineLink } from "../../lib/links"; -import { getState } from "../../redux"; - import { useIntermediate } from "../../context/intermediate/Intermediate"; import { AppContext } from "../../context/revoltjs/RevoltClient"; @@ -221,6 +219,7 @@ export default function Renderer({ content, disallowBigEmoji }: MarkdownProps) { } case "external": { element.setAttribute("target", "_blank"); + element.setAttribute("rel", "noreferrer"); break; } } diff --git a/src/context/intermediate/Intermediate.tsx b/src/context/intermediate/Intermediate.tsx index b2fb4d6d..65256730 100644 --- a/src/context/intermediate/Intermediate.tsx +++ b/src/context/intermediate/Intermediate.tsx @@ -151,15 +151,15 @@ export default function Intermediate(props: Props) { id: "external_link_prompt", link: link.href, }); + return true; } return false; } - default: { - return true; - } } + + return true; }, openScreen: (screen: Screen) => openScreen(screen), writeClipboard: (text: string) => { diff --git a/src/context/intermediate/modals/ExternalLinkPrompt.tsx b/src/context/intermediate/modals/ExternalLinkPrompt.tsx index 244e4990..68e3ea15 100644 --- a/src/context/intermediate/modals/ExternalLinkPrompt.tsx +++ b/src/context/intermediate/modals/ExternalLinkPrompt.tsx @@ -1,8 +1,9 @@ import { Text } from "preact-i18n"; -import Modal from "../../../components/ui/Modal"; import { dispatch } from "../../../redux"; +import Modal from "../../../components/ui/Modal"; + interface Props { onClose: () => void; link: string; @@ -17,7 +18,7 @@ export function ExternalLinkModal({ onClose, link }: Props) { actions={[ { onClick: () => { - window.open(link, "_blank"); + window.open(link, "_blank", "noreferrer"); onClose(); }, confirmation: true, @@ -36,15 +37,17 @@ export function ExternalLinkModal({ onClose, link }: Props) { const url = new URL(link); dispatch({ type: "TRUSTED_LINKS_ADD_DOMAIN", - domain: url.hostname + domain: url.hostname, }); - } catch(e) {} - window.open(link, "_blank"); + } catch (e) {} + window.open(link, "_blank", "noreferrer"); onClose(); }, plain: true, - children: , - } + children: ( + + ), + }, ]}>
{link} diff --git a/src/pages/settings/panes/Feedback.tsx b/src/pages/settings/panes/Feedback.tsx index b9850334..106159db 100644 --- a/src/pages/settings/panes/Feedback.tsx +++ b/src/pages/settings/panes/Feedback.tsx @@ -53,7 +53,7 @@ export function Feedback() { - +