@unicef-polymer/etools-form-builder 3.2.2 → 3.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,6 +7,7 @@ export declare class RichText extends LitElement {
7
7
  readonly: boolean;
8
8
  node: Element;
9
9
  value: string | null | undefined;
10
+ clean: any;
10
11
  render(): import("lit-html").TemplateResult<1>;
11
12
  firstUpdated(): void;
12
13
  }
@@ -4,12 +4,104 @@ import { property, customElement } from 'lit/decorators.js';
4
4
  import { fireEvent } from '../lib/utils/fire-custom-event';
5
5
  import './rich-toolbar';
6
6
  import './rich-viewer';
7
+ import DOMPurify from 'dompurify';
7
8
  let RichText = class RichText extends LitElement {
8
9
  constructor() {
9
10
  super(...arguments);
10
11
  this.selection = null;
11
12
  this.readonly = false;
12
13
  this.node = document.createElement('div');
14
+ this.clean = {
15
+ FORBID_TAGS: ['style', 'script'],
16
+ FORBID_ATTR: [
17
+ 'class',
18
+ 'onauxclick',
19
+ 'onafterprint',
20
+ 'onbeforematch',
21
+ 'onbeforeprint',
22
+ 'onbeforeunload',
23
+ 'onbeforetoggle',
24
+ 'onblur',
25
+ 'oncancel',
26
+ 'oncanplay',
27
+ 'oncanplaythrough',
28
+ 'onchange',
29
+ 'onclick',
30
+ 'onclose',
31
+ 'oncontextlost',
32
+ 'oncontextmenu',
33
+ 'oncontextrestored',
34
+ 'oncopy',
35
+ 'oncuechange',
36
+ 'oncut',
37
+ 'ondblclick',
38
+ 'ondrag',
39
+ 'ondragend',
40
+ 'ondragenter',
41
+ 'ondragleave',
42
+ 'ondragover',
43
+ 'ondragstart',
44
+ 'ondrop',
45
+ 'ondurationchange',
46
+ 'onemptied',
47
+ 'onended',
48
+ 'onerror',
49
+ 'onfocus',
50
+ 'onformdata',
51
+ 'onhashchange',
52
+ 'oninput',
53
+ 'oninvalid',
54
+ 'onkeydown',
55
+ 'onkeypress',
56
+ 'onkeyup',
57
+ 'onlanguagechange',
58
+ 'onload',
59
+ 'onloadeddata',
60
+ 'onloadedmetadata',
61
+ 'onloadstart',
62
+ 'onmessage',
63
+ 'onmessageerror',
64
+ 'onmousedown',
65
+ 'onmouseenter',
66
+ 'onmouseleave',
67
+ 'onmousemove',
68
+ 'onmouseout',
69
+ 'onmouseover',
70
+ 'onmouseup',
71
+ 'onoffline',
72
+ 'ononline',
73
+ 'onpagehide',
74
+ 'onpageshow',
75
+ 'onpaste',
76
+ 'onpause',
77
+ 'onplay',
78
+ 'onplaying',
79
+ 'onpopstate',
80
+ 'onprogress',
81
+ 'onratechange',
82
+ 'onreset',
83
+ 'onresize',
84
+ 'onrejectionhandled',
85
+ 'onscroll',
86
+ 'onscrollend',
87
+ 'onsecuritypolicyviolation',
88
+ 'onseeked',
89
+ 'onseeking',
90
+ 'onselect',
91
+ 'onslotchange',
92
+ 'onstalled',
93
+ 'onstorage',
94
+ 'onsubmit',
95
+ 'onsuspend',
96
+ 'ontimeupdate',
97
+ 'ontoggle',
98
+ 'onunhandledrejection',
99
+ 'onunload',
100
+ 'onvolumechange',
101
+ 'onwaiting',
102
+ 'onwheel'
103
+ ]
104
+ };
13
105
  }
14
106
  render() {
15
107
  const { selection, readonly, node } = this;
@@ -36,7 +128,13 @@ let RichText = class RichText extends LitElement {
36
128
  @selection=${(e) => {
37
129
  const event = e;
38
130
  this.selection = event.detail.selection;
39
- fireEvent(this, 'editor-changed', { value: event.detail.html });
131
+ let sanitizedHTML = event.detail.html || '';
132
+ // remove all mso- from styling
133
+ sanitizedHTML = sanitizedHTML.replace(/mso-[^:]+:[^;"]+;?/gi, '');
134
+ // remove all comments
135
+ sanitizedHTML = sanitizedHTML.replace(/<!--[\s\S]*?-->/g, '');
136
+ sanitizedHTML = DOMPurify.sanitize(sanitizedHTML, this.clean);
137
+ fireEvent(this, 'editor-changed', { value: sanitizedHTML });
40
138
  }}
41
139
  .node="${node}"
42
140
  >
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unicef-polymer/etools-form-builder",
3
3
  "description": "Etools FM Form Builder components",
4
- "version": "3.2.2",
4
+ "version": "3.2.3",
5
5
  "type": "module",
6
6
  "contributors": [
7
7
  "eTools Team"
@@ -26,6 +26,7 @@
26
26
  "dependencies": {
27
27
  "@shoelace-style/shoelace": "2.18.0",
28
28
  "@types/ramda": "0.30.2",
29
+ "dompurify": "^3.2.6",
29
30
  "lit": "^3.2.1",
30
31
  "ramda": "0.30.1",
31
32
  "relative-deps": "^1.0.7",