mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-16 20:35:59 +08:00
fix: xss in render svg (#16437)
This commit is contained in:
parent
0e33a3aa5f
commit
21561df10f
@ -18,7 +18,7 @@ import ImageGallery from '@/app/components/base/image-gallery'
|
|||||||
import { useChatContext } from '@/app/components/base/chat/chat/context'
|
import { useChatContext } from '@/app/components/base/chat/chat/context'
|
||||||
import VideoGallery from '@/app/components/base/video-gallery'
|
import VideoGallery from '@/app/components/base/video-gallery'
|
||||||
import AudioGallery from '@/app/components/base/audio-gallery'
|
import AudioGallery from '@/app/components/base/audio-gallery'
|
||||||
import SVGRenderer from '@/app/components/base/svg-gallery'
|
// import SVGRenderer from '@/app/components/base/svg-gallery'
|
||||||
import MarkdownButton from '@/app/components/base/markdown-blocks/button'
|
import MarkdownButton from '@/app/components/base/markdown-blocks/button'
|
||||||
import MarkdownForm from '@/app/components/base/markdown-blocks/form'
|
import MarkdownForm from '@/app/components/base/markdown-blocks/form'
|
||||||
|
|
||||||
@ -118,13 +118,13 @@ const CodeBlock: CodeComponent = memo(({ inline, className, children, ...props }
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
else if (language === 'svg' && isSVG) {
|
// else if (language === 'svg' && isSVG) {
|
||||||
return (
|
// return (
|
||||||
<ErrorBoundary>
|
// <ErrorBoundary>
|
||||||
<SVGRenderer content={content} />
|
// <SVGRenderer content={content} />
|
||||||
</ErrorBoundary>
|
// </ErrorBoundary>
|
||||||
)
|
// )
|
||||||
}
|
// }
|
||||||
else {
|
else {
|
||||||
return (
|
return (
|
||||||
<SyntaxHighlighter
|
<SyntaxHighlighter
|
||||||
@ -224,8 +224,16 @@ const Link = ({ node, ...props }: any) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function escapeSVGTags(htmlString: string): string {
|
||||||
|
return htmlString.replace(/(<svg[\s\S]*?>)([\s\S]*?)(<\/svg>)/gi, (match: string, openTag: string, innerContent: string, closeTag: string): string => {
|
||||||
|
return openTag.replace(/</g, '<').replace(/>/g, '>')
|
||||||
|
+ innerContent.replace(/</g, '<').replace(/>/g, '>')
|
||||||
|
+ closeTag.replace(/</g, '<').replace(/>/g, '>')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export function Markdown(props: { content: string; className?: string }) {
|
export function Markdown(props: { content: string; className?: string }) {
|
||||||
const latexContent = preprocessLaTeX(props.content)
|
const latexContent = preprocessLaTeX(escapeSVGTags(props.content))
|
||||||
return (
|
return (
|
||||||
<div className={cn(props.className, 'markdown-body')}>
|
<div className={cn(props.className, 'markdown-body')}>
|
||||||
<ReactMarkdown
|
<ReactMarkdown
|
||||||
|
Loading…
x
Reference in New Issue
Block a user