Skip to content

Commit

Permalink
fix(math-renderer): sanitize html from katex
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsTheGlidingSquirrel committed Dec 23, 2024
1 parent b1fbe7c commit 834d64b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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 (
<span
className="inline-block py-1 [page-break-inside:avoid]"
dangerouslySetInnerHTML={{ __html: html }}
dangerouslySetInnerHTML={{ __html: sanitizedHtml }}
/>
)
}
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 834d64b

Please sign in to comment.