Skip to content

Commit d9a2987

Browse files
Copilothuangyiirene
andcommitted
Add XSS protection with rehype-sanitize
Co-authored-by: huangyiirene <7665279+huangyiirene@users.noreply.github.com>
1 parent e517621 commit d9a2987

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

packages/components/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"react-markdown": "^10.1.0",
6161
"react-resizable-panels": "^4.4.0",
6262
"recharts": "^3.6.0",
63+
"rehype-sanitize": "^6.0.0",
6364
"remark-gfm": "^4.0.1",
6465
"sonner": "^2.0.7",
6566
"tailwind-merge": "^2.6.0",

packages/components/src/ui/markdown.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import * as React from "react"
22
import ReactMarkdown from "react-markdown"
33
import remarkGfm from "remark-gfm"
4+
import rehypeSanitize from "rehype-sanitize"
45
import { cn } from "@/lib/utils"
56

67
export interface MarkdownProps {
78
content: string
89
className?: string
910
}
1011

11-
function Markdown({ content, className, ...props }: MarkdownProps & React.ComponentProps<"div">) {
12+
function Markdown({ content, className }: MarkdownProps) {
1213
return (
1314
<div
1415
data-slot="markdown"
@@ -28,9 +29,11 @@ function Markdown({ content, className, ...props }: MarkdownProps & React.Compon
2829
"prose-img:rounded-md prose-img:border",
2930
className
3031
)}
31-
{...props}
3232
>
33-
<ReactMarkdown remarkPlugins={[remarkGfm]}>
33+
<ReactMarkdown
34+
remarkPlugins={[remarkGfm]}
35+
rehypePlugins={[rehypeSanitize]}
36+
>
3437
{content}
3538
</ReactMarkdown>
3639
</div>

pnpm-lock.yaml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)