Skip to content

Commit 05b0369

Browse files
committed
Update dompurify
1 parent 49e2e0c commit 05b0369

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

package-lock.json

Lines changed: 16 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
"@sentry/webpack-plugin": "^2.16.1",
5555
"@types/base64-arraybuffer": "^0.1.0",
5656
"@types/dedent": "^0.7.0",
57-
"@types/dompurify": "0.0.32",
5857
"@types/har-format": "^1.2.5",
5958
"@types/inline-style-prefixer": "^3.0.1",
6059
"@types/js-beautify": "^1.8.0",
@@ -92,7 +91,7 @@
9291
"date-fns": "^1.30.1",
9392
"dedent": "^0.7.0",
9493
"deserialize-error": "0.0.3",
95-
"dompurify": "^2.5.6",
94+
"dompurify": "^3.3.3",
9695
"fast-json-patch": "^3.1.1",
9796
"fast-xml-parser": "^5.5.7",
9897
"graphql": "^15.8.0",

src/model/ui/markdown.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as Remarkable from 'remarkable';
2-
import * as DOMPurify from 'dompurify';
2+
import DOMPurify from 'dompurify';
33

44
import { Html } from '../../types';
55

@@ -16,7 +16,9 @@ const linklessMarkdown = new Remarkable({
1616

1717
// Add an extra hook to DOMPurify to enforce link target. Without this, DOMPurify strips
1818
// every link target entirely.
19-
DOMPurify.addHook('afterSanitizeAttributes', function (node: Element | HTMLElement) {
19+
DOMPurify.addHook('afterSanitizeAttributes', function (node) {
20+
if (!(node instanceof Element)) return;
21+
2022
// Closely based on example from https://github.com/cure53/DOMPurify/tree/main/demos#hook-to-open-all-links-in-a-new-window-link
2123

2224
// Set all elements owning target to target=_blank
@@ -36,7 +38,9 @@ DOMPurify.addHook('afterSanitizeAttributes', function (node: Element | HTMLEleme
3638

3739
// Add an extra hook to strip relative URLs (markdown largely comes from external sources,
3840
// and so should never include relative paths!)
39-
DOMPurify.addHook('afterSanitizeAttributes', function (node: Element | HTMLElement) {
41+
DOMPurify.addHook('afterSanitizeAttributes', function (node) {
42+
if (!(node instanceof Element)) return;
43+
4044
if (node.hasAttribute('href')) {
4145
const target = node.getAttribute('href');
4246
if (target?.startsWith('/')) node.removeAttribute('href');

0 commit comments

Comments
 (0)