Skip to content

Commit

Permalink
fix(plugin-edusharing): use DomPurify to sanitize embed html from edu…
Browse files Browse the repository at this point in the history
…-sharing
  • Loading branch information
LarsTheGlidingSquirrel committed Dec 23, 2024
1 parent 9c6c86f commit 440e245
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/editor/src/plugins/edusharing-asset/renderer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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 { memo, useEffect, useState } from 'react'

Expand Down Expand Up @@ -86,8 +87,15 @@ export function EdusharingAssetRenderer(props: {

const html = buildHtml(htmlSnippet, defineContainerHeight)

const sanatizedHtml = DOMPurify.sanitize(html, {
// We allow <script> and <iframe> elements. Those are part of the html snippet we get from edu-sharing and cannot be removed or the embed will break. <script> elements cannot be manipulated by the user and we can trust them.
ADD_TAGS: ['script', 'iframe'],
// Return entire html document including <html>, <body>, ...
WHOLE_DOCUMENT: true,
})

setEmbedType(embedType)
setEmbedHtml(html)
setEmbedHtml(sanatizedHtml)
setDefineContainerHeight(defineContainerHeight)
}

Expand Down

0 comments on commit 440e245

Please sign in to comment.