mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-06 17:46:23 +00:00
fix(web): secure rich content rendering
This commit is contained in:
+11
-2
@@ -16,6 +16,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import DOMPurify from 'dompurify'
|
||||
import { useMemo } from 'react'
|
||||
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
interface HtmlContentProps {
|
||||
@@ -24,10 +27,16 @@ interface HtmlContentProps {
|
||||
}
|
||||
|
||||
export function HtmlContent(props: HtmlContentProps) {
|
||||
const html = useMemo(() => DOMPurify.sanitize(props.content), [props.content])
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn('prose prose-neutral dark:prose-invert max-w-none', props.className)}
|
||||
dangerouslySetInnerHTML={{ __html: props.content }}
|
||||
className={cn(
|
||||
'prose prose-neutral dark:prose-invert max-w-none',
|
||||
props.className
|
||||
)}
|
||||
// eslint-disable-next-line react/no-danger -- html is sanitized above
|
||||
dangerouslySetInnerHTML={{ __html: html }}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user