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