Skip to content

Commit

Permalink
Merge pull request #4379 from serlo/math-renderer-sanitize-html
Browse files Browse the repository at this point in the history
fix(math-renderer): sanitize html from katex
  • Loading branch information
LarsTheGlidingSquirrel authored Dec 23, 2024
2 parents b1fbe7c + 094e484 commit e66cba9
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
1 change: 0 additions & 1 deletion packages/editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"@open-iframe-resizer/react": "1.2.1",
"@serlo/katex-styles": "1.0.1",
"@vidstack/react": "next",
"dompurify": "^3.2.3",
"isomorphic-dompurify": "^2.19.0",
"lit": "^3.2.1",
"motion": "^11.11.17",
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/plugins/edusharing-asset/renderer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import EdusharingIcon from '@editor/editor-ui/assets/edusharing.svg'
import { IframeResizer } from '@open-iframe-resizer/react'
import DOMPurify from 'dompurify'
import * as t from 'io-ts'
import DOMPurify from 'isomorphic-dompurify'
import { memo, useEffect, useState } from 'react'

type EmbedType =
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 'isomorphic-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: 0 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5798,7 +5798,6 @@ __metadata:
"@vitejs/plugin-react": ^4.3.3
autoprefixer: ^10.4.20
clsx: ^2.1.1
dompurify: ^3.2.3
eslint: ^9.14.0
eslint-config-next: ^15.0.3
eslint-config-prettier: ^9.1.0
Expand Down

0 comments on commit e66cba9

Please sign in to comment.