summaryrefslogtreecommitdiff
path: root/packages/frontend/src/scripts/sanitize-html.ts
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2024-05-07 20:19:52 +0000
committerEmber <acomputerdog@gmail.com>2024-05-07 20:19:52 +0000
commit2c40dd31f32edffcc8f1da7bea53b14589c5d2ad (patch)
tree3be0a644212a33a4d633ed40316b424cd1408c43 /packages/frontend/src/scripts/sanitize-html.ts
parentmerge: fix: `MkPageWindow` doesn't render custom emojis in the titlebar when ... (diff)
downloadsharkey-2c40dd31f32edffcc8f1da7bea53b14589c5d2ad.tar.gz
sharkey-2c40dd31f32edffcc8f1da7bea53b14589c5d2ad.tar.bz2
sharkey-2c40dd31f32edffcc8f1da7bea53b14589c5d2ad.zip
laxer HTML sanitisation for admin-controlled text - fixes #447
Diffstat (limited to 'packages/frontend/src/scripts/sanitize-html.ts')
-rw-r--r--packages/frontend/src/scripts/sanitize-html.ts18
1 files changed, 18 insertions, 0 deletions
diff --git a/packages/frontend/src/scripts/sanitize-html.ts b/packages/frontend/src/scripts/sanitize-html.ts
new file mode 100644
index 0000000000..6e1a46c746
--- /dev/null
+++ b/packages/frontend/src/scripts/sanitize-html.ts
@@ -0,0 +1,18 @@
+/*
+ * SPDX-FileCopyrightText: dakkar and other Sharkey contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+*/
+
+import original from 'sanitize-html';
+
+export default function sanitizeHtml(str: string | null): string | null {
+ if (str == null) return str;
+ return original(str, {
+ allowedTags: original.defaults.allowedTags.concat(['img', 'audio', 'video', 'center', 'details', 'summary']),
+ allowedAttributes: {
+ ...original.defaults.allowedAttributes,
+ a: original.defaults.allowedAttributes.a.concat(['style']),
+ img: original.defaults.allowedAttributes.img.concat(['style']),
+ },
+ });
+}