@@ -4,12 +4,17 @@ import MarkdownIt, { PluginSimple } from "markdown-it";
4
4
import markdownItTextualUml from "markdown-it-textual-uml" ;
5
5
import Mermaid from "mermaid" ;
6
6
import "github-markdown-css/github-markdown-light.css" ;
7
+ import DOMPurify from 'dompurify' ;
7
8
8
9
import * as toolbox from "js/toolbox" ;
9
10
import { useEffect , useState } from "preact/hooks" ;
10
11
11
12
Mermaid . initialize ( { startOnLoad : false , theme : `default` , securityLevel : `strict` } ) ;
12
- const md = MarkdownIt ( ) . use ( markdownItTextualUml as PluginSimple ) ;
13
+ const md = MarkdownIt ( {
14
+ html : true ,
15
+ linkify : false ,
16
+ typographer : true
17
+ } ) . use ( markdownItTextualUml as PluginSimple ) ;
13
18
14
19
export default function ( { config, dom } : { dom : HTMLElement , config : any , } ) {
15
20
render ( < App reportUrl = { config . reportUrl } context = { config . reportContext } /> , dom ) ;
@@ -78,10 +83,37 @@ const MarkdownBody = (props: { markdown: string, }) => {
78
83
}
79
84
} , [ props . markdown ] ) ;
80
85
86
+ const renderedHtml = md . render ( props . markdown ) ;
87
+ const sanitizedHtml = DOMPurify . sanitize ( renderedHtml , {
88
+ ALLOWED_TAGS : [
89
+ // Basic
90
+ `details` , `summary` , `p` , `br` , `h1` , `h2` , `h3` , `h4` , `h5` , `h6` ,
91
+ `ul` , `ol` , `li` , `blockquote` , `pre` , `hr` , `div` ,
92
+ // Tables
93
+ `table` , `thead` , `tbody` , `tr` , `td` , `th` ,
94
+ //Formating
95
+ `strong` , `b` , `em` , `i` , `u` , `code` , `span` ,
96
+ `del` , `s` ,
97
+ `sup` , `sub` ,
98
+ `kbd` ,
99
+ `mark` ,
100
+ `ins` ,
101
+ `small` ,
102
+ `abbr`
103
+ ] ,
104
+ ALLOWED_ATTR : [
105
+ `title` ,
106
+ `open`
107
+ ] ,
108
+ FORBID_TAGS : [ `a` , `img` , `script` , `object` , `embed` , `iframe` , `link` ] ,
109
+ FORBID_ATTR : [ `href` , `src` , `class` , `id` , `style` , `target` ] ,
110
+ ALLOW_DATA_ATTR : false
111
+ } ) ;
112
+
81
113
return (
82
114
< div
83
115
className = "markdown-body"
84
- dangerouslySetInnerHTML = { { __html : md . render ( props . markdown ) } }
116
+ dangerouslySetInnerHTML = { { __html : sanitizedHtml } }
85
117
/>
86
118
) ;
87
119
} ;
0 commit comments