diff --git a/apps/web/package.json b/apps/web/package.json index 778d993c4e..af2292215a 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -52,6 +52,7 @@ "autoprefixer": "^10.4.20", "canvas-confetti": "^1.9.3", "clsx": "^2.1.1", + "dompurify": "^3.2.3", "fast-xml-parser": "^4.5.0", "fp-ts": "^2.16.9", "graphiql": "^3.7.2", diff --git a/packages/editor/src/plugins/text/static-components/static-math.tsx b/packages/editor/src/plugins/text/static-components/static-math.tsx index 7fa9a824c0..e5d3070ef8 100644 --- a/packages/editor/src/plugins/text/static-components/static-math.tsx +++ b/packages/editor/src/plugins/text/static-components/static-math.tsx @@ -1,5 +1,6 @@ import { sanitizeLatex } from '@editor/plugins/text/utils/sanitize-latex' import { cn } from '@editor/utils/cn' +import DOMPurify from 'dompurify' import KaTeX from 'katex' // eslint-disable-next-line import/no-unassigned-import import 'katex/contrib/mhchem' @@ -67,10 +68,13 @@ export function StaticMath({ src, inline }: StaticMathProps) { }, }) : '' + + // Even though we can trust the html created by Katex we sanitize the html as a second guard against XSS. + const sanitizedHtml = DOMPurify.sanitize(html) return ( ) } diff --git a/yarn.lock b/yarn.lock index 763e227475..1d00d5f534 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5925,6 +5925,7 @@ __metadata: canvas-confetti: ^1.9.3 clsx: ^2.1.1 cross-env: ^7.0.3 + dompurify: ^3.2.3 dotenv: ^16.4.5 eslint: ^9.14.0 eslint-config-next: ^15.0.3