From 77dea3bd4d37e0ff36a93c0cbad0d69a6972374d Mon Sep 17 00:00:00 2001 From: Panto! Date: Mon, 10 Jul 2023 15:14:36 -0300 Subject: [PATCH] fix: sanitizer removing link target (#17) --- src/components/SanitizedHTML/index.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/components/SanitizedHTML/index.tsx b/src/components/SanitizedHTML/index.tsx index 45d1066..5565285 100644 --- a/src/components/SanitizedHTML/index.tsx +++ b/src/components/SanitizedHTML/index.tsx @@ -5,6 +5,13 @@ type Props = { }; const SanitizedHTML: React.FC = ({dirtyHTML}: Props) => { + DOMPurify.addHook("afterSanitizeAttributes", function (node) { + if ("target" in node) { + node.setAttribute("target", "_blank"); + node.setAttribute("rel", "noreferrer noopener nofollow"); + } + }); + const sanitized = DOMPurify.sanitize(dirtyHTML); return
;