@@ -16,6 +16,7 @@ import { getPost } from "@/server/lib/posts";
1616import  {  getCamelCaseFromLower  }  from  "@/utils/utils" ; 
1717import  {  generateHTML  }  from  "@tiptap/html" ; 
1818import  {  TiptapExtensions  }  from  "@/components/editor/editor/extensions" ; 
19+ import  DOMPurify  from  'isomorphic-dompurify' ; 
1920
2021type  Props  =  {  params : {  slug : string  }  } ; 
2122
@@ -68,10 +69,10 @@ const parseJSON = (str: string): any | null => {
6869  } 
6970} ; 
7071
71- const  renderTiptapContent  =  ( jsonContent : JSON )  =>  { 
72-   return   generateHTML ( jsonContent ,  [ 
73-     ... TiptapExtensions , 
74-   ] ) ; 
72+ const  renderSanitizedTiptapContent  =  ( jsonContent : JSON )  =>  { 
73+   const   rawHtml   =   generateHTML ( jsonContent ,  [ ... TiptapExtensions ] ) ; 
74+   // Sanitize the HTML 
75+   return   DOMPurify . sanitize ( rawHtml ) ; 
7576} ; 
7677
7778const  ArticlePage  =  async  ( {  params } : Props )  =>  { 
@@ -83,7 +84,7 @@ const ArticlePage = async ({ params }: Props) => {
8384  const  post  =  await  getPost ( {  slug } ) ; 
8485
8586  if  ( ! post )  { 
86-     notFound ( ) ; 
87+     return   notFound ( ) ; 
8788  } 
8889
8990  const  parsedBody  =  parseJSON ( post . body ) ; 
@@ -93,7 +94,7 @@ const ArticlePage = async ({ params }: Props) => {
9394
9495  if  ( isTiptapContent  &&  parsedBody )  { 
9596    const  jsonContent  =  parsedBody ; 
96-     renderedContent  =  renderTiptapContent ( jsonContent ) ; 
97+     renderedContent  =  renderSanitizedTiptapContent ( jsonContent ) ; 
9798  }  else  { 
9899    const  ast  =  Markdoc . parse ( post . body ) ; 
99100    const  transformedContent  =  Markdoc . transform ( ast ,  config ) ; 
0 commit comments