fix(ImagePreview): add relaxed sanitize rules for svg (#9293)

This commit is contained in:
one 2025-08-19 12:58:45 +08:00 committed by GitHub
parent 585e49ac65
commit e3c52a6174
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,5 @@
import { makeSvgSizeAdaptive } from '@renderer/utils'
import DOMPurify from 'dompurify'
/**
* Renders an SVG string inside a host element's Shadow DOM to ensure style encapsulation.
@ -14,14 +15,11 @@ export function renderSvgInShadowHost(svgContent: string, hostElement: HTMLEleme
throw new Error('Host element for SVG rendering is not available.')
}
// FIXME: Sanitize the SVG content
// const sanitizedContent = DOMPurify.sanitize(svgContent, {
// USE_PROFILES: { svg: true, svgFilters: true },
// RETURN_DOM_FRAGMENT: false,
// RETURN_DOM: false
// })
const sanitizedContent = svgContent
// Sanitize the SVG content
const sanitizedContent = DOMPurify.sanitize(svgContent, {
USE_PROFILES: { svg: true, svgFilters: true },
ADD_TAGS: ['style', 'defs', 'foreignObject']
})
const shadowRoot = hostElement.shadowRoot || hostElement.attachShadow({ mode: 'open' })