1
1
import sanitizeHtml from "sanitize-html" ;
2
2
import sanitizeUrl from "@braintree/sanitize-url" ;
3
+ import optionService from "./options.js" ;
4
+
5
+ // Default list of allowed HTML tags
6
+ export const DEFAULT_ALLOWED_TAGS = [
7
+ 'h1' , 'h2' , 'h3' , 'h4' , 'h5' , 'h6' , 'blockquote' , 'p' , 'a' , 'ul' , 'ol' ,
8
+ 'li' , 'b' , 'i' , 'strong' , 'em' , 'strike' , 's' , 'del' , 'abbr' , 'code' , 'hr' , 'br' , 'div' ,
9
+ 'table' , 'thead' , 'caption' , 'tbody' , 'tfoot' , 'tr' , 'th' , 'td' , 'pre' , 'section' , 'img' ,
10
+ 'figure' , 'figcaption' , 'span' , 'label' , 'input' , 'details' , 'summary' , 'address' , 'aside' , 'footer' ,
11
+ 'header' , 'hgroup' , 'main' , 'nav' , 'dl' , 'dt' , 'menu' , 'bdi' , 'bdo' , 'dfn' , 'kbd' , 'mark' , 'q' , 'time' ,
12
+ 'var' , 'wbr' , 'area' , 'map' , 'track' , 'video' , 'audio' , 'picture' , 'del' , 'ins' ,
13
+ 'en-media' , // for ENEX import
14
+ // Additional tags (https://github.com/TriliumNext/Notes/issues/567)
15
+ 'acronym' , 'article' , 'big' , 'button' , 'cite' , 'col' , 'colgroup' , 'data' , 'dd' ,
16
+ 'fieldset' , 'form' , 'legend' , 'meter' , 'noscript' , 'option' , 'progress' , 'rp' ,
17
+ 'samp' , 'small' , 'sub' , 'sup' , 'template' , 'textarea' , 'tt'
18
+ ] as const ;
3
19
4
20
// intended mainly as protection against XSS via import
5
21
// secondarily, it (partly) protects against "CSS takeover"
@@ -23,17 +39,18 @@ function sanitize(dirtyHtml: string) {
23
39
}
24
40
}
25
41
42
+ // Get allowed tags from options, with fallback to default list if option not yet set
43
+ let allowedTags ;
44
+ try {
45
+ allowedTags = JSON . parse ( optionService . getOption ( 'allowedHtmlTags' ) ) ;
46
+ } catch ( e ) {
47
+ // Fallback to default list if option doesn't exist or is invalid
48
+ allowedTags = DEFAULT_ALLOWED_TAGS ;
49
+ }
50
+
26
51
// to minimize document changes, compress H
27
52
return sanitizeHtml ( dirtyHtml , {
28
- allowedTags : [
29
- 'h1' , 'h2' , 'h3' , 'h4' , 'h5' , 'h6' , 'blockquote' , 'p' , 'a' , 'ul' , 'ol' ,
30
- 'li' , 'b' , 'i' , 'strong' , 'em' , 'strike' , 's' , 'del' , 'abbr' , 'code' , 'hr' , 'br' , 'div' ,
31
- 'table' , 'thead' , 'caption' , 'tbody' , 'tfoot' , 'tr' , 'th' , 'td' , 'pre' , 'section' , 'img' ,
32
- 'figure' , 'figcaption' , 'span' , 'label' , 'input' , 'details' , 'summary' , 'address' , 'aside' , 'footer' ,
33
- 'header' , 'hgroup' , 'main' , 'nav' , 'dl' , 'dt' , 'menu' , 'bdi' , 'bdo' , 'dfn' , 'kbd' , 'mark' , 'q' , 'time' ,
34
- 'var' , 'wbr' , 'area' , 'map' , 'track' , 'video' , 'audio' , 'picture' , 'del' , 'ins' ,
35
- 'en-media' // for ENEX import
36
- ] ,
53
+ allowedTags,
37
54
allowedAttributes : {
38
55
'*' : [ 'class' , 'style' , 'title' , 'src' , 'href' , 'hash' , 'disabled' , 'align' , 'alt' , 'center' , 'data-*' ]
39
56
} ,
0 commit comments