@@ -34,10 +34,8 @@ const sanitizeSchema = {
3434 ] ,
3535 attributes : {
3636 ...defaultSchema . attributes ,
37- a : [ "href" , "title" , "target" ] ,
38- "*" : ( defaultSchema . attributes ?. [ "*" ] ?? [ ] ) . filter (
39- ( attr ) => ! ( typeof attr === "string" && attr . startsWith ( "on" ) )
40- ) ,
37+ a : [ "href" , "title" ] ,
38+ "*" : defaultSchema . attributes ?. [ "*" ] ?? [ ] ,
4139 } ,
4240} ;
4341
@@ -79,11 +77,11 @@ const components: ComponentProps<typeof ReactMarkdown>["components"] = {
7977 ) ,
8078 a : ( { children, className, style, ...props } ) => (
8179 < a
80+ { ...props }
8281 target = "_blank"
8382 rel = "noopener noreferrer"
8483 className = { clsx ( className , classes . common ) }
8584 style = { { ...style , color : palette . primary . main } }
86- { ...props }
8785 >
8886 { children }
8987 </ a >
@@ -115,7 +113,11 @@ export const InlineMarkdown = ({
115113 p : ( { children } ) => < > { children } </ > ,
116114 strong : ( { children } ) => < strong > { children } </ strong > ,
117115 em : ( { children } ) => < em > { children } </ em > ,
118- a : ( { children, href } ) => < a href = { href } > { children } </ a > ,
116+ a : ( { children, href } ) => {
117+ const safeHref =
118+ href && / ^ ( h t t p s ? | m a i l t o | i r c s ? ) : / i. test ( href ) ? href : undefined ;
119+ return < a href = { safeHref } > { children } </ a > ;
120+ } ,
119121 h1 : ( ) => null ,
120122 h2 : ( ) => null ,
121123 h3 : ( ) => null ,
@@ -197,11 +199,11 @@ const componentsInheritFonts: ComponentProps<
197199 ) ,
198200 a : ( { children, className, style, ...props } ) => (
199201 < a
202+ { ...props }
200203 className = { clsx ( className , classes . common , classes . inheritFonts ) }
201204 target = "_blank"
202205 rel = "noopener noreferrer"
203206 style = { { ...style , color : palette . primary . main } }
204- { ...props }
205207 >
206208 { children }
207209 </ a >
0 commit comments