@@ -16,7 +16,7 @@ import { getPost } from "@/server/lib/posts";
1616import { getCamelCaseFromLower } from "@/utils/utils" ;
1717import { generateHTML } from "@tiptap/core" ;
1818import { TiptapExtensions } from "@/components/editor/editor/extensions" ;
19- import DOMPurify from "isomorphic-dompurify " ;
19+ import sanitizeHtml from "sanitize-html " ;
2020import type { JSONContent } from "@tiptap/core" ;
2121import NotFound from "@/components/NotFound/NotFound" ;
2222
@@ -74,8 +74,26 @@ const parseJSON = (str: string): JSONContent | null => {
7474
7575const renderSanitizedTiptapContent = ( jsonContent : JSONContent ) => {
7676 const rawHtml = generateHTML ( jsonContent , [ ...TiptapExtensions ] ) ;
77- // Sanitize the HTML
78- return DOMPurify . sanitize ( rawHtml ) ;
77+ // Sanitize the HTML using sanitize-html (server-safe, no jsdom dependency)
78+ return sanitizeHtml ( rawHtml , {
79+ allowedTags : sanitizeHtml . defaults . allowedTags . concat ( [
80+ "img" ,
81+ "iframe" ,
82+ "h1" ,
83+ "h2" ,
84+ ] ) ,
85+ allowedAttributes : {
86+ ...sanitizeHtml . defaults . allowedAttributes ,
87+ img : [ "src" , "alt" , "title" , "width" , "height" , "class" ] ,
88+ iframe : [ "src" , "width" , "height" , "frameborder" , "allowfullscreen" ] ,
89+ "*" : [ "class" , "id" , "style" ] ,
90+ } ,
91+ allowedIframeHostnames : [
92+ "www.youtube.com" ,
93+ "youtube.com" ,
94+ "www.youtube-nocookie.com" ,
95+ ] ,
96+ } ) ;
7997} ;
8098
8199const ArticlePage = async ( props : Props ) => {
0 commit comments