@wiris/mathtype-ckeditor5 8.11.0 → 8.12.0
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.
- package/dist/browser/index-editor.css +23 -102
- package/dist/browser/index.css +41 -111
- package/dist/browser/index.css.map +1 -1
- package/dist/browser/index.js +1452 -1988
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.umd.js +10630 -11166
- package/dist/browser/index.umd.js.map +1 -1
- package/dist/index.js +94 -31
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.js +1 -1
- package/src/plugin.js +112 -32
package/dist/browser/index.js
CHANGED
|
@@ -3,1950 +3,1335 @@ import { ButtonView } from 'ckeditor5';
|
|
|
3
3
|
import { ClickObserver, XmlDataProcessor, UpcastWriter, HtmlDataProcessor } from 'ckeditor5';
|
|
4
4
|
import { Widget, viewToModelPositionOutsideModelElement, toWidget } from 'ckeditor5';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
/*! @license DOMPurify 3.2.3 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.2.3/LICENSE */
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
const {
|
|
9
|
+
entries,
|
|
10
|
+
setPrototypeOf,
|
|
11
|
+
isFrozen,
|
|
12
|
+
getPrototypeOf,
|
|
13
|
+
getOwnPropertyDescriptor
|
|
14
|
+
} = Object;
|
|
15
|
+
let {
|
|
16
|
+
freeze,
|
|
17
|
+
seal,
|
|
18
|
+
create
|
|
19
|
+
} = Object; // eslint-disable-line import/no-mutable-exports
|
|
20
|
+
let {
|
|
21
|
+
apply,
|
|
22
|
+
construct
|
|
23
|
+
} = typeof Reflect !== 'undefined' && Reflect;
|
|
24
|
+
if (!freeze) {
|
|
25
|
+
freeze = function freeze(x) {
|
|
26
|
+
return x;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (!seal) {
|
|
30
|
+
seal = function seal(x) {
|
|
31
|
+
return x;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (!apply) {
|
|
35
|
+
apply = function apply(fun, thisValue, args) {
|
|
36
|
+
return fun.apply(thisValue, args);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
if (!construct) {
|
|
40
|
+
construct = function construct(Func, args) {
|
|
41
|
+
return new Func(...args);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const arrayForEach = unapply(Array.prototype.forEach);
|
|
45
|
+
const arrayPop = unapply(Array.prototype.pop);
|
|
46
|
+
const arrayPush = unapply(Array.prototype.push);
|
|
47
|
+
const stringToLowerCase = unapply(String.prototype.toLowerCase);
|
|
48
|
+
const stringToString = unapply(String.prototype.toString);
|
|
49
|
+
const stringMatch = unapply(String.prototype.match);
|
|
50
|
+
const stringReplace = unapply(String.prototype.replace);
|
|
51
|
+
const stringIndexOf = unapply(String.prototype.indexOf);
|
|
52
|
+
const stringTrim = unapply(String.prototype.trim);
|
|
53
|
+
const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
|
|
54
|
+
const regExpTest = unapply(RegExp.prototype.test);
|
|
55
|
+
const typeErrorCreate = unconstruct(TypeError);
|
|
56
|
+
/**
|
|
57
|
+
* Creates a new function that calls the given function with a specified thisArg and arguments.
|
|
58
|
+
*
|
|
59
|
+
* @param func - The function to be wrapped and called.
|
|
60
|
+
* @returns A new function that calls the given function with a specified thisArg and arguments.
|
|
61
|
+
*/
|
|
62
|
+
function unapply(func) {
|
|
63
|
+
return function (thisArg) {
|
|
64
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
65
|
+
args[_key - 1] = arguments[_key];
|
|
66
|
+
}
|
|
67
|
+
return apply(func, thisArg, args);
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Creates a new function that constructs an instance of the given constructor function with the provided arguments.
|
|
72
|
+
*
|
|
73
|
+
* @param func - The constructor function to be wrapped and called.
|
|
74
|
+
* @returns A new function that constructs an instance of the given constructor function with the provided arguments.
|
|
75
|
+
*/
|
|
76
|
+
function unconstruct(func) {
|
|
77
|
+
return function () {
|
|
78
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
79
|
+
args[_key2] = arguments[_key2];
|
|
80
|
+
}
|
|
81
|
+
return construct(func, args);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Add properties to a lookup table
|
|
86
|
+
*
|
|
87
|
+
* @param set - The set to which elements will be added.
|
|
88
|
+
* @param array - The array containing elements to be added to the set.
|
|
89
|
+
* @param transformCaseFunc - An optional function to transform the case of each element before adding to the set.
|
|
90
|
+
* @returns The modified set with added elements.
|
|
91
|
+
*/
|
|
92
|
+
function addToSet(set, array) {
|
|
93
|
+
let transformCaseFunc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : stringToLowerCase;
|
|
94
|
+
if (setPrototypeOf) {
|
|
95
|
+
// Make 'in' and truthy checks like Boolean(set.constructor)
|
|
96
|
+
// independent of any properties defined on Object.prototype.
|
|
97
|
+
// Prevent prototype setters from intercepting set as a this value.
|
|
98
|
+
setPrototypeOf(set, null);
|
|
99
|
+
}
|
|
100
|
+
let l = array.length;
|
|
101
|
+
while (l--) {
|
|
102
|
+
let element = array[l];
|
|
103
|
+
if (typeof element === 'string') {
|
|
104
|
+
const lcElement = transformCaseFunc(element);
|
|
105
|
+
if (lcElement !== element) {
|
|
106
|
+
// Config presets (e.g. tags.js, attrs.js) are immutable.
|
|
107
|
+
if (!isFrozen(array)) {
|
|
108
|
+
array[l] = lcElement;
|
|
109
|
+
}
|
|
110
|
+
element = lcElement;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
set[element] = true;
|
|
114
|
+
}
|
|
115
|
+
return set;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Clean up an array to harden against CSPP
|
|
119
|
+
*
|
|
120
|
+
* @param array - The array to be cleaned.
|
|
121
|
+
* @returns The cleaned version of the array
|
|
122
|
+
*/
|
|
123
|
+
function cleanArray(array) {
|
|
124
|
+
for (let index = 0; index < array.length; index++) {
|
|
125
|
+
const isPropertyExist = objectHasOwnProperty(array, index);
|
|
126
|
+
if (!isPropertyExist) {
|
|
127
|
+
array[index] = null;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return array;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Shallow clone an object
|
|
134
|
+
*
|
|
135
|
+
* @param object - The object to be cloned.
|
|
136
|
+
* @returns A new object that copies the original.
|
|
137
|
+
*/
|
|
138
|
+
function clone(object) {
|
|
139
|
+
const newObject = create(null);
|
|
140
|
+
for (const [property, value] of entries(object)) {
|
|
141
|
+
const isPropertyExist = objectHasOwnProperty(object, property);
|
|
142
|
+
if (isPropertyExist) {
|
|
143
|
+
if (Array.isArray(value)) {
|
|
144
|
+
newObject[property] = cleanArray(value);
|
|
145
|
+
} else if (value && typeof value === 'object' && value.constructor === Object) {
|
|
146
|
+
newObject[property] = clone(value);
|
|
147
|
+
} else {
|
|
148
|
+
newObject[property] = value;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return newObject;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* This method automatically checks if the prop is function or getter and behaves accordingly.
|
|
156
|
+
*
|
|
157
|
+
* @param object - The object to look up the getter function in its prototype chain.
|
|
158
|
+
* @param prop - The property name for which to find the getter function.
|
|
159
|
+
* @returns The getter function found in the prototype chain or a fallback function.
|
|
160
|
+
*/
|
|
161
|
+
function lookupGetter(object, prop) {
|
|
162
|
+
while (object !== null) {
|
|
163
|
+
const desc = getOwnPropertyDescriptor(object, prop);
|
|
164
|
+
if (desc) {
|
|
165
|
+
if (desc.get) {
|
|
166
|
+
return unapply(desc.get);
|
|
167
|
+
}
|
|
168
|
+
if (typeof desc.value === 'function') {
|
|
169
|
+
return unapply(desc.value);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
object = getPrototypeOf(object);
|
|
173
|
+
}
|
|
174
|
+
function fallbackValue() {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
return fallbackValue;
|
|
178
|
+
}
|
|
9
179
|
|
|
10
|
-
(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
'xml:space',
|
|
799
|
-
'xmlns:xlink'
|
|
800
|
-
]);
|
|
801
|
-
// eslint-disable-next-line unicorn/better-regex
|
|
802
|
-
const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
|
|
803
|
-
const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
|
|
804
|
-
const TMPLIT_EXPR = seal(/\${[\w\W]*}/gm);
|
|
805
|
-
const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]/); // eslint-disable-line no-useless-escape
|
|
806
|
-
const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
|
|
807
|
-
const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i // eslint-disable-line no-useless-escape
|
|
808
|
-
);
|
|
809
|
-
const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
|
|
810
|
-
const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
|
|
811
|
-
);
|
|
812
|
-
const DOCTYPE_NAME = seal(/^html$/i);
|
|
813
|
-
const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
|
|
814
|
-
var EXPRESSIONS = /*#__PURE__*/ Object.freeze({
|
|
815
|
-
__proto__: null,
|
|
816
|
-
MUSTACHE_EXPR: MUSTACHE_EXPR,
|
|
817
|
-
ERB_EXPR: ERB_EXPR,
|
|
818
|
-
TMPLIT_EXPR: TMPLIT_EXPR,
|
|
819
|
-
DATA_ATTR: DATA_ATTR,
|
|
820
|
-
ARIA_ATTR: ARIA_ATTR,
|
|
821
|
-
IS_ALLOWED_URI: IS_ALLOWED_URI,
|
|
822
|
-
IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
|
|
823
|
-
ATTR_WHITESPACE: ATTR_WHITESPACE,
|
|
824
|
-
DOCTYPE_NAME: DOCTYPE_NAME,
|
|
825
|
-
CUSTOM_ELEMENT: CUSTOM_ELEMENT
|
|
180
|
+
const html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'section', 'select', 'shadow', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']);
|
|
181
|
+
const svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);
|
|
182
|
+
const svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence']);
|
|
183
|
+
// List of SVG elements that are disallowed by default.
|
|
184
|
+
// We still need to know them so that we can do namespace
|
|
185
|
+
// checks properly in case one wants to add them to
|
|
186
|
+
// allow-list.
|
|
187
|
+
const svgDisallowed = freeze(['animate', 'color-profile', 'cursor', 'discard', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'foreignobject', 'hatch', 'hatchpath', 'mesh', 'meshgradient', 'meshpatch', 'meshrow', 'missing-glyph', 'script', 'set', 'solidcolor', 'unknown', 'use']);
|
|
188
|
+
const mathMl$1 = freeze(['math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mspace', 'msqrt', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover', 'mprescripts']);
|
|
189
|
+
// Similarly to SVG, we want to know all MathML elements,
|
|
190
|
+
// even those that we disallow by default.
|
|
191
|
+
const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
|
|
192
|
+
const text = freeze(['#text']);
|
|
193
|
+
|
|
194
|
+
const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns', 'slot']);
|
|
195
|
+
const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'amplitude', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'exponent', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'intercept', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'slope', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'tablevalues', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']);
|
|
196
|
+
const mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnsalign', 'columnlines', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lspace', 'lquote', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);
|
|
197
|
+
const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
|
|
198
|
+
|
|
199
|
+
// eslint-disable-next-line unicorn/better-regex
|
|
200
|
+
const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
|
|
201
|
+
const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
|
|
202
|
+
const TMPLIT_EXPR = seal(/\$\{[\w\W]*}/gm); // eslint-disable-line unicorn/better-regex
|
|
203
|
+
const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/); // eslint-disable-line no-useless-escape
|
|
204
|
+
const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
|
|
205
|
+
const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i // eslint-disable-line no-useless-escape
|
|
206
|
+
);
|
|
207
|
+
const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
|
|
208
|
+
const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
|
|
209
|
+
);
|
|
210
|
+
const DOCTYPE_NAME = seal(/^html$/i);
|
|
211
|
+
const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
|
|
212
|
+
|
|
213
|
+
var EXPRESSIONS = /*#__PURE__*/Object.freeze({
|
|
214
|
+
__proto__: null,
|
|
215
|
+
ARIA_ATTR: ARIA_ATTR,
|
|
216
|
+
ATTR_WHITESPACE: ATTR_WHITESPACE,
|
|
217
|
+
CUSTOM_ELEMENT: CUSTOM_ELEMENT,
|
|
218
|
+
DATA_ATTR: DATA_ATTR,
|
|
219
|
+
DOCTYPE_NAME: DOCTYPE_NAME,
|
|
220
|
+
ERB_EXPR: ERB_EXPR,
|
|
221
|
+
IS_ALLOWED_URI: IS_ALLOWED_URI,
|
|
222
|
+
IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
|
|
223
|
+
MUSTACHE_EXPR: MUSTACHE_EXPR,
|
|
224
|
+
TMPLIT_EXPR: TMPLIT_EXPR
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
/* eslint-disable @typescript-eslint/indent */
|
|
228
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
|
|
229
|
+
const NODE_TYPE = {
|
|
230
|
+
element: 1,
|
|
231
|
+
attribute: 2,
|
|
232
|
+
text: 3,
|
|
233
|
+
cdataSection: 4,
|
|
234
|
+
entityReference: 5,
|
|
235
|
+
// Deprecated
|
|
236
|
+
entityNode: 6,
|
|
237
|
+
// Deprecated
|
|
238
|
+
progressingInstruction: 7,
|
|
239
|
+
comment: 8,
|
|
240
|
+
document: 9,
|
|
241
|
+
documentType: 10,
|
|
242
|
+
documentFragment: 11,
|
|
243
|
+
notation: 12 // Deprecated
|
|
244
|
+
};
|
|
245
|
+
const getGlobal = function getGlobal() {
|
|
246
|
+
return typeof window === 'undefined' ? null : window;
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* Creates a no-op policy for internal use only.
|
|
250
|
+
* Don't export this function outside this module!
|
|
251
|
+
* @param trustedTypes The policy factory.
|
|
252
|
+
* @param purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).
|
|
253
|
+
* @return The policy created (or null, if Trusted Types
|
|
254
|
+
* are not supported or creating the policy failed).
|
|
255
|
+
*/
|
|
256
|
+
const _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {
|
|
257
|
+
if (typeof trustedTypes !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
// Allow the callers to control the unique policy name
|
|
261
|
+
// by adding a data-tt-policy-suffix to the script element with the DOMPurify.
|
|
262
|
+
// Policy creation with duplicate names throws in Trusted Types.
|
|
263
|
+
let suffix = null;
|
|
264
|
+
const ATTR_NAME = 'data-tt-policy-suffix';
|
|
265
|
+
if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
|
|
266
|
+
suffix = purifyHostElement.getAttribute(ATTR_NAME);
|
|
267
|
+
}
|
|
268
|
+
const policyName = 'dompurify' + (suffix ? '#' + suffix : '');
|
|
269
|
+
try {
|
|
270
|
+
return trustedTypes.createPolicy(policyName, {
|
|
271
|
+
createHTML(html) {
|
|
272
|
+
return html;
|
|
273
|
+
},
|
|
274
|
+
createScriptURL(scriptUrl) {
|
|
275
|
+
return scriptUrl;
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
} catch (_) {
|
|
279
|
+
// Policy creation failed (most likely another DOMPurify script has
|
|
280
|
+
// already run). Skip creating the policy, as this will only cause errors
|
|
281
|
+
// if TT are enforced.
|
|
282
|
+
console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
const _createHooksMap = function _createHooksMap() {
|
|
287
|
+
return {
|
|
288
|
+
afterSanitizeAttributes: [],
|
|
289
|
+
afterSanitizeElements: [],
|
|
290
|
+
afterSanitizeShadowDOM: [],
|
|
291
|
+
beforeSanitizeAttributes: [],
|
|
292
|
+
beforeSanitizeElements: [],
|
|
293
|
+
beforeSanitizeShadowDOM: [],
|
|
294
|
+
uponSanitizeAttribute: [],
|
|
295
|
+
uponSanitizeElement: [],
|
|
296
|
+
uponSanitizeShadowNode: []
|
|
297
|
+
};
|
|
298
|
+
};
|
|
299
|
+
function createDOMPurify() {
|
|
300
|
+
let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
|
|
301
|
+
const DOMPurify = root => createDOMPurify(root);
|
|
302
|
+
DOMPurify.version = '3.2.3';
|
|
303
|
+
DOMPurify.removed = [];
|
|
304
|
+
if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document) {
|
|
305
|
+
// Not running in a browser, provide a factory function
|
|
306
|
+
// so that you can pass your own Window
|
|
307
|
+
DOMPurify.isSupported = false;
|
|
308
|
+
return DOMPurify;
|
|
309
|
+
}
|
|
310
|
+
let {
|
|
311
|
+
document
|
|
312
|
+
} = window;
|
|
313
|
+
const originalDocument = document;
|
|
314
|
+
const currentScript = originalDocument.currentScript;
|
|
315
|
+
const {
|
|
316
|
+
DocumentFragment,
|
|
317
|
+
HTMLTemplateElement,
|
|
318
|
+
Node,
|
|
319
|
+
Element,
|
|
320
|
+
NodeFilter,
|
|
321
|
+
NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,
|
|
322
|
+
HTMLFormElement,
|
|
323
|
+
DOMParser,
|
|
324
|
+
trustedTypes
|
|
325
|
+
} = window;
|
|
326
|
+
const ElementPrototype = Element.prototype;
|
|
327
|
+
const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
|
|
328
|
+
const remove = lookupGetter(ElementPrototype, 'remove');
|
|
329
|
+
const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
|
|
330
|
+
const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
|
|
331
|
+
const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
|
|
332
|
+
// As per issue #47, the web-components registry is inherited by a
|
|
333
|
+
// new document created via createHTMLDocument. As per the spec
|
|
334
|
+
// (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
|
|
335
|
+
// a new empty registry is used when creating a template contents owner
|
|
336
|
+
// document, so we use that as our parent document to ensure nothing
|
|
337
|
+
// is inherited.
|
|
338
|
+
if (typeof HTMLTemplateElement === 'function') {
|
|
339
|
+
const template = document.createElement('template');
|
|
340
|
+
if (template.content && template.content.ownerDocument) {
|
|
341
|
+
document = template.content.ownerDocument;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
let trustedTypesPolicy;
|
|
345
|
+
let emptyHTML = '';
|
|
346
|
+
const {
|
|
347
|
+
implementation,
|
|
348
|
+
createNodeIterator,
|
|
349
|
+
createDocumentFragment,
|
|
350
|
+
getElementsByTagName
|
|
351
|
+
} = document;
|
|
352
|
+
const {
|
|
353
|
+
importNode
|
|
354
|
+
} = originalDocument;
|
|
355
|
+
let hooks = _createHooksMap();
|
|
356
|
+
/**
|
|
357
|
+
* Expose whether this browser supports running the full DOMPurify.
|
|
358
|
+
*/
|
|
359
|
+
DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
|
|
360
|
+
const {
|
|
361
|
+
MUSTACHE_EXPR,
|
|
362
|
+
ERB_EXPR,
|
|
363
|
+
TMPLIT_EXPR,
|
|
364
|
+
DATA_ATTR,
|
|
365
|
+
ARIA_ATTR,
|
|
366
|
+
IS_SCRIPT_OR_DATA,
|
|
367
|
+
ATTR_WHITESPACE,
|
|
368
|
+
CUSTOM_ELEMENT
|
|
369
|
+
} = EXPRESSIONS;
|
|
370
|
+
let {
|
|
371
|
+
IS_ALLOWED_URI: IS_ALLOWED_URI$1
|
|
372
|
+
} = EXPRESSIONS;
|
|
373
|
+
/**
|
|
374
|
+
* We consider the elements and attributes below to be safe. Ideally
|
|
375
|
+
* don't add any new ones but feel free to remove unwanted ones.
|
|
376
|
+
*/
|
|
377
|
+
/* allowed element names */
|
|
378
|
+
let ALLOWED_TAGS = null;
|
|
379
|
+
const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
|
|
380
|
+
/* Allowed attribute names */
|
|
381
|
+
let ALLOWED_ATTR = null;
|
|
382
|
+
const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
|
|
383
|
+
/*
|
|
384
|
+
* Configure how DOMPurify should handle custom elements and their attributes as well as customized built-in elements.
|
|
385
|
+
* @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)
|
|
386
|
+
* @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)
|
|
387
|
+
* @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.
|
|
388
|
+
*/
|
|
389
|
+
let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
|
|
390
|
+
tagNameCheck: {
|
|
391
|
+
writable: true,
|
|
392
|
+
configurable: false,
|
|
393
|
+
enumerable: true,
|
|
394
|
+
value: null
|
|
395
|
+
},
|
|
396
|
+
attributeNameCheck: {
|
|
397
|
+
writable: true,
|
|
398
|
+
configurable: false,
|
|
399
|
+
enumerable: true,
|
|
400
|
+
value: null
|
|
401
|
+
},
|
|
402
|
+
allowCustomizedBuiltInElements: {
|
|
403
|
+
writable: true,
|
|
404
|
+
configurable: false,
|
|
405
|
+
enumerable: true,
|
|
406
|
+
value: false
|
|
407
|
+
}
|
|
408
|
+
}));
|
|
409
|
+
/* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */
|
|
410
|
+
let FORBID_TAGS = null;
|
|
411
|
+
/* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */
|
|
412
|
+
let FORBID_ATTR = null;
|
|
413
|
+
/* Decide if ARIA attributes are okay */
|
|
414
|
+
let ALLOW_ARIA_ATTR = true;
|
|
415
|
+
/* Decide if custom data attributes are okay */
|
|
416
|
+
let ALLOW_DATA_ATTR = true;
|
|
417
|
+
/* Decide if unknown protocols are okay */
|
|
418
|
+
let ALLOW_UNKNOWN_PROTOCOLS = false;
|
|
419
|
+
/* Decide if self-closing tags in attributes are allowed.
|
|
420
|
+
* Usually removed due to a mXSS issue in jQuery 3.0 */
|
|
421
|
+
let ALLOW_SELF_CLOSE_IN_ATTR = true;
|
|
422
|
+
/* Output should be safe for common template engines.
|
|
423
|
+
* This means, DOMPurify removes data attributes, mustaches and ERB
|
|
424
|
+
*/
|
|
425
|
+
let SAFE_FOR_TEMPLATES = false;
|
|
426
|
+
/* Output should be safe even for XML used within HTML and alike.
|
|
427
|
+
* This means, DOMPurify removes comments when containing risky content.
|
|
428
|
+
*/
|
|
429
|
+
let SAFE_FOR_XML = true;
|
|
430
|
+
/* Decide if document with <html>... should be returned */
|
|
431
|
+
let WHOLE_DOCUMENT = false;
|
|
432
|
+
/* Track whether config is already set on this instance of DOMPurify. */
|
|
433
|
+
let SET_CONFIG = false;
|
|
434
|
+
/* Decide if all elements (e.g. style, script) must be children of
|
|
435
|
+
* document.body. By default, browsers might move them to document.head */
|
|
436
|
+
let FORCE_BODY = false;
|
|
437
|
+
/* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
|
|
438
|
+
* string (or a TrustedHTML object if Trusted Types are supported).
|
|
439
|
+
* If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
|
|
440
|
+
*/
|
|
441
|
+
let RETURN_DOM = false;
|
|
442
|
+
/* Decide if a DOM `DocumentFragment` should be returned, instead of a html
|
|
443
|
+
* string (or a TrustedHTML object if Trusted Types are supported) */
|
|
444
|
+
let RETURN_DOM_FRAGMENT = false;
|
|
445
|
+
/* Try to return a Trusted Type object instead of a string, return a string in
|
|
446
|
+
* case Trusted Types are not supported */
|
|
447
|
+
let RETURN_TRUSTED_TYPE = false;
|
|
448
|
+
/* Output should be free from DOM clobbering attacks?
|
|
449
|
+
* This sanitizes markups named with colliding, clobberable built-in DOM APIs.
|
|
450
|
+
*/
|
|
451
|
+
let SANITIZE_DOM = true;
|
|
452
|
+
/* Achieve full DOM Clobbering protection by isolating the namespace of named
|
|
453
|
+
* properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.
|
|
454
|
+
*
|
|
455
|
+
* HTML/DOM spec rules that enable DOM Clobbering:
|
|
456
|
+
* - Named Access on Window (§7.3.3)
|
|
457
|
+
* - DOM Tree Accessors (§3.1.5)
|
|
458
|
+
* - Form Element Parent-Child Relations (§4.10.3)
|
|
459
|
+
* - Iframe srcdoc / Nested WindowProxies (§4.8.5)
|
|
460
|
+
* - HTMLCollection (§4.2.10.2)
|
|
461
|
+
*
|
|
462
|
+
* Namespace isolation is implemented by prefixing `id` and `name` attributes
|
|
463
|
+
* with a constant string, i.e., `user-content-`
|
|
464
|
+
*/
|
|
465
|
+
let SANITIZE_NAMED_PROPS = false;
|
|
466
|
+
const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';
|
|
467
|
+
/* Keep element content when removing element? */
|
|
468
|
+
let KEEP_CONTENT = true;
|
|
469
|
+
/* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
|
|
470
|
+
* of importing it into a new Document and returning a sanitized copy */
|
|
471
|
+
let IN_PLACE = false;
|
|
472
|
+
/* Allow usage of profiles like html, svg and mathMl */
|
|
473
|
+
let USE_PROFILES = {};
|
|
474
|
+
/* Tags to ignore content of when KEEP_CONTENT is true */
|
|
475
|
+
let FORBID_CONTENTS = null;
|
|
476
|
+
const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
|
|
477
|
+
/* Tags that are safe for data: URIs */
|
|
478
|
+
let DATA_URI_TAGS = null;
|
|
479
|
+
const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
|
|
480
|
+
/* Attributes safe for values like "javascript:" */
|
|
481
|
+
let URI_SAFE_ATTRIBUTES = null;
|
|
482
|
+
const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);
|
|
483
|
+
const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
|
|
484
|
+
const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
|
|
485
|
+
const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
|
|
486
|
+
/* Document namespace */
|
|
487
|
+
let NAMESPACE = HTML_NAMESPACE;
|
|
488
|
+
let IS_EMPTY_INPUT = false;
|
|
489
|
+
/* Allowed XHTML+XML namespaces */
|
|
490
|
+
let ALLOWED_NAMESPACES = null;
|
|
491
|
+
const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
|
|
492
|
+
let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
|
|
493
|
+
let HTML_INTEGRATION_POINTS = addToSet({}, ['annotation-xml']);
|
|
494
|
+
// Certain elements are allowed in both SVG and HTML
|
|
495
|
+
// namespace. We need to specify them explicitly
|
|
496
|
+
// so that they don't get erroneously deleted from
|
|
497
|
+
// HTML namespace.
|
|
498
|
+
const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);
|
|
499
|
+
/* Parsing of strict XHTML documents */
|
|
500
|
+
let PARSER_MEDIA_TYPE = null;
|
|
501
|
+
const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];
|
|
502
|
+
const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
|
|
503
|
+
let transformCaseFunc = null;
|
|
504
|
+
/* Keep a reference to config to pass to hooks */
|
|
505
|
+
let CONFIG = null;
|
|
506
|
+
/* Ideally, do not touch anything below this line */
|
|
507
|
+
/* ______________________________________________ */
|
|
508
|
+
const formElement = document.createElement('form');
|
|
509
|
+
const isRegexOrFunction = function isRegexOrFunction(testValue) {
|
|
510
|
+
return testValue instanceof RegExp || testValue instanceof Function;
|
|
511
|
+
};
|
|
512
|
+
/**
|
|
513
|
+
* _parseConfig
|
|
514
|
+
*
|
|
515
|
+
* @param cfg optional config literal
|
|
516
|
+
*/
|
|
517
|
+
// eslint-disable-next-line complexity
|
|
518
|
+
const _parseConfig = function _parseConfig() {
|
|
519
|
+
let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
520
|
+
if (CONFIG && CONFIG === cfg) {
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
/* Shield configuration object from tampering */
|
|
524
|
+
if (!cfg || typeof cfg !== 'object') {
|
|
525
|
+
cfg = {};
|
|
526
|
+
}
|
|
527
|
+
/* Shield configuration object from prototype pollution */
|
|
528
|
+
cfg = clone(cfg);
|
|
529
|
+
PARSER_MEDIA_TYPE =
|
|
530
|
+
// eslint-disable-next-line unicorn/prefer-includes
|
|
531
|
+
SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
|
|
532
|
+
// HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
|
|
533
|
+
transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
|
|
534
|
+
/* Set configuration parameters */
|
|
535
|
+
ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
|
|
536
|
+
ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
|
|
537
|
+
ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
|
|
538
|
+
URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR, transformCaseFunc) : DEFAULT_URI_SAFE_ATTRIBUTES;
|
|
539
|
+
DATA_URI_TAGS = objectHasOwnProperty(cfg, 'ADD_DATA_URI_TAGS') ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS, transformCaseFunc) : DEFAULT_DATA_URI_TAGS;
|
|
540
|
+
FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
|
|
541
|
+
FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : {};
|
|
542
|
+
FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : {};
|
|
543
|
+
USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES : false;
|
|
544
|
+
ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
|
|
545
|
+
ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
|
|
546
|
+
ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
|
|
547
|
+
ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true
|
|
548
|
+
SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
|
|
549
|
+
SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false; // Default true
|
|
550
|
+
WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
|
|
551
|
+
RETURN_DOM = cfg.RETURN_DOM || false; // Default false
|
|
552
|
+
RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false
|
|
553
|
+
RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false
|
|
554
|
+
FORCE_BODY = cfg.FORCE_BODY || false; // Default false
|
|
555
|
+
SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
|
|
556
|
+
SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
|
|
557
|
+
KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
|
|
558
|
+
IN_PLACE = cfg.IN_PLACE || false; // Default false
|
|
559
|
+
IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
|
|
560
|
+
NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
|
|
561
|
+
MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;
|
|
562
|
+
HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;
|
|
563
|
+
CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
|
|
564
|
+
if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
|
|
565
|
+
CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
|
|
566
|
+
}
|
|
567
|
+
if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
|
|
568
|
+
CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
|
|
569
|
+
}
|
|
570
|
+
if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
|
|
571
|
+
CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
|
|
572
|
+
}
|
|
573
|
+
if (SAFE_FOR_TEMPLATES) {
|
|
574
|
+
ALLOW_DATA_ATTR = false;
|
|
575
|
+
}
|
|
576
|
+
if (RETURN_DOM_FRAGMENT) {
|
|
577
|
+
RETURN_DOM = true;
|
|
578
|
+
}
|
|
579
|
+
/* Parse profile info */
|
|
580
|
+
if (USE_PROFILES) {
|
|
581
|
+
ALLOWED_TAGS = addToSet({}, text);
|
|
582
|
+
ALLOWED_ATTR = [];
|
|
583
|
+
if (USE_PROFILES.html === true) {
|
|
584
|
+
addToSet(ALLOWED_TAGS, html$1);
|
|
585
|
+
addToSet(ALLOWED_ATTR, html);
|
|
586
|
+
}
|
|
587
|
+
if (USE_PROFILES.svg === true) {
|
|
588
|
+
addToSet(ALLOWED_TAGS, svg$1);
|
|
589
|
+
addToSet(ALLOWED_ATTR, svg);
|
|
590
|
+
addToSet(ALLOWED_ATTR, xml);
|
|
591
|
+
}
|
|
592
|
+
if (USE_PROFILES.svgFilters === true) {
|
|
593
|
+
addToSet(ALLOWED_TAGS, svgFilters);
|
|
594
|
+
addToSet(ALLOWED_ATTR, svg);
|
|
595
|
+
addToSet(ALLOWED_ATTR, xml);
|
|
596
|
+
}
|
|
597
|
+
if (USE_PROFILES.mathMl === true) {
|
|
598
|
+
addToSet(ALLOWED_TAGS, mathMl$1);
|
|
599
|
+
addToSet(ALLOWED_ATTR, mathMl);
|
|
600
|
+
addToSet(ALLOWED_ATTR, xml);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
/* Merge configuration parameters */
|
|
604
|
+
if (cfg.ADD_TAGS) {
|
|
605
|
+
if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
|
|
606
|
+
ALLOWED_TAGS = clone(ALLOWED_TAGS);
|
|
607
|
+
}
|
|
608
|
+
addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
|
|
609
|
+
}
|
|
610
|
+
if (cfg.ADD_ATTR) {
|
|
611
|
+
if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
|
|
612
|
+
ALLOWED_ATTR = clone(ALLOWED_ATTR);
|
|
613
|
+
}
|
|
614
|
+
addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
|
|
615
|
+
}
|
|
616
|
+
if (cfg.ADD_URI_SAFE_ATTR) {
|
|
617
|
+
addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
|
|
618
|
+
}
|
|
619
|
+
if (cfg.FORBID_CONTENTS) {
|
|
620
|
+
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
|
|
621
|
+
FORBID_CONTENTS = clone(FORBID_CONTENTS);
|
|
622
|
+
}
|
|
623
|
+
addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
|
|
624
|
+
}
|
|
625
|
+
/* Add #text in case KEEP_CONTENT is set to true */
|
|
626
|
+
if (KEEP_CONTENT) {
|
|
627
|
+
ALLOWED_TAGS['#text'] = true;
|
|
628
|
+
}
|
|
629
|
+
/* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */
|
|
630
|
+
if (WHOLE_DOCUMENT) {
|
|
631
|
+
addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);
|
|
632
|
+
}
|
|
633
|
+
/* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */
|
|
634
|
+
if (ALLOWED_TAGS.table) {
|
|
635
|
+
addToSet(ALLOWED_TAGS, ['tbody']);
|
|
636
|
+
delete FORBID_TAGS.tbody;
|
|
637
|
+
}
|
|
638
|
+
if (cfg.TRUSTED_TYPES_POLICY) {
|
|
639
|
+
if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
|
|
640
|
+
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
|
|
641
|
+
}
|
|
642
|
+
if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
|
|
643
|
+
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
|
|
644
|
+
}
|
|
645
|
+
// Overwrite existing TrustedTypes policy.
|
|
646
|
+
trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
|
|
647
|
+
// Sign local variables required by `sanitize`.
|
|
648
|
+
emptyHTML = trustedTypesPolicy.createHTML('');
|
|
649
|
+
} else {
|
|
650
|
+
// Uninitialized policy, attempt to initialize the internal dompurify policy.
|
|
651
|
+
if (trustedTypesPolicy === undefined) {
|
|
652
|
+
trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
|
|
653
|
+
}
|
|
654
|
+
// If creating the internal policy succeeded sign internal variables.
|
|
655
|
+
if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {
|
|
656
|
+
emptyHTML = trustedTypesPolicy.createHTML('');
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
// Prevent further manipulation of configuration.
|
|
660
|
+
// Not available in IE8, Safari 5, etc.
|
|
661
|
+
if (freeze) {
|
|
662
|
+
freeze(cfg);
|
|
663
|
+
}
|
|
664
|
+
CONFIG = cfg;
|
|
665
|
+
};
|
|
666
|
+
/* Keep track of all possible SVG and MathML tags
|
|
667
|
+
* so that we can perform the namespace checks
|
|
668
|
+
* correctly. */
|
|
669
|
+
const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
|
|
670
|
+
const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
|
|
671
|
+
/**
|
|
672
|
+
* @param element a DOM element whose namespace is being checked
|
|
673
|
+
* @returns Return false if the element has a
|
|
674
|
+
* namespace that a spec-compliant parser would never
|
|
675
|
+
* return. Return true otherwise.
|
|
676
|
+
*/
|
|
677
|
+
const _checkValidNamespace = function _checkValidNamespace(element) {
|
|
678
|
+
let parent = getParentNode(element);
|
|
679
|
+
// In JSDOM, if we're inside shadow DOM, then parentNode
|
|
680
|
+
// can be null. We just simulate parent in this case.
|
|
681
|
+
if (!parent || !parent.tagName) {
|
|
682
|
+
parent = {
|
|
683
|
+
namespaceURI: NAMESPACE,
|
|
684
|
+
tagName: 'template'
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
const tagName = stringToLowerCase(element.tagName);
|
|
688
|
+
const parentTagName = stringToLowerCase(parent.tagName);
|
|
689
|
+
if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
|
|
690
|
+
return false;
|
|
691
|
+
}
|
|
692
|
+
if (element.namespaceURI === SVG_NAMESPACE) {
|
|
693
|
+
// The only way to switch from HTML namespace to SVG
|
|
694
|
+
// is via <svg>. If it happens via any other tag, then
|
|
695
|
+
// it should be killed.
|
|
696
|
+
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
697
|
+
return tagName === 'svg';
|
|
698
|
+
}
|
|
699
|
+
// The only way to switch from MathML to SVG is via`
|
|
700
|
+
// svg if parent is either <annotation-xml> or MathML
|
|
701
|
+
// text integration points.
|
|
702
|
+
if (parent.namespaceURI === MATHML_NAMESPACE) {
|
|
703
|
+
return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
|
|
704
|
+
}
|
|
705
|
+
// We only allow elements that are defined in SVG
|
|
706
|
+
// spec. All others are disallowed in SVG namespace.
|
|
707
|
+
return Boolean(ALL_SVG_TAGS[tagName]);
|
|
708
|
+
}
|
|
709
|
+
if (element.namespaceURI === MATHML_NAMESPACE) {
|
|
710
|
+
// The only way to switch from HTML namespace to MathML
|
|
711
|
+
// is via <math>. If it happens via any other tag, then
|
|
712
|
+
// it should be killed.
|
|
713
|
+
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
714
|
+
return tagName === 'math';
|
|
715
|
+
}
|
|
716
|
+
// The only way to switch from SVG to MathML is via
|
|
717
|
+
// <math> and HTML integration points
|
|
718
|
+
if (parent.namespaceURI === SVG_NAMESPACE) {
|
|
719
|
+
return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
|
|
720
|
+
}
|
|
721
|
+
// We only allow elements that are defined in MathML
|
|
722
|
+
// spec. All others are disallowed in MathML namespace.
|
|
723
|
+
return Boolean(ALL_MATHML_TAGS[tagName]);
|
|
724
|
+
}
|
|
725
|
+
if (element.namespaceURI === HTML_NAMESPACE) {
|
|
726
|
+
// The only way to switch from SVG to HTML is via
|
|
727
|
+
// HTML integration points, and from MathML to HTML
|
|
728
|
+
// is via MathML text integration points
|
|
729
|
+
if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
|
|
730
|
+
return false;
|
|
731
|
+
}
|
|
732
|
+
if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
|
|
733
|
+
return false;
|
|
734
|
+
}
|
|
735
|
+
// We disallow tags that are specific for MathML
|
|
736
|
+
// or SVG and should never appear in HTML namespace
|
|
737
|
+
return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
|
|
738
|
+
}
|
|
739
|
+
// For XHTML and XML documents that support custom namespaces
|
|
740
|
+
if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
|
|
741
|
+
return true;
|
|
742
|
+
}
|
|
743
|
+
// The code should never reach this place (this means
|
|
744
|
+
// that the element somehow got namespace that is not
|
|
745
|
+
// HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).
|
|
746
|
+
// Return false just in case.
|
|
747
|
+
return false;
|
|
748
|
+
};
|
|
749
|
+
/**
|
|
750
|
+
* _forceRemove
|
|
751
|
+
*
|
|
752
|
+
* @param node a DOM node
|
|
753
|
+
*/
|
|
754
|
+
const _forceRemove = function _forceRemove(node) {
|
|
755
|
+
arrayPush(DOMPurify.removed, {
|
|
756
|
+
element: node
|
|
757
|
+
});
|
|
758
|
+
try {
|
|
759
|
+
// eslint-disable-next-line unicorn/prefer-dom-node-remove
|
|
760
|
+
getParentNode(node).removeChild(node);
|
|
761
|
+
} catch (_) {
|
|
762
|
+
remove(node);
|
|
763
|
+
}
|
|
764
|
+
};
|
|
765
|
+
/**
|
|
766
|
+
* _removeAttribute
|
|
767
|
+
*
|
|
768
|
+
* @param name an Attribute name
|
|
769
|
+
* @param element a DOM node
|
|
770
|
+
*/
|
|
771
|
+
const _removeAttribute = function _removeAttribute(name, element) {
|
|
772
|
+
try {
|
|
773
|
+
arrayPush(DOMPurify.removed, {
|
|
774
|
+
attribute: element.getAttributeNode(name),
|
|
775
|
+
from: element
|
|
776
|
+
});
|
|
777
|
+
} catch (_) {
|
|
778
|
+
arrayPush(DOMPurify.removed, {
|
|
779
|
+
attribute: null,
|
|
780
|
+
from: element
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
element.removeAttribute(name);
|
|
784
|
+
// We void attribute values for unremovable "is" attributes
|
|
785
|
+
if (name === 'is') {
|
|
786
|
+
if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
|
|
787
|
+
try {
|
|
788
|
+
_forceRemove(element);
|
|
789
|
+
} catch (_) {}
|
|
790
|
+
} else {
|
|
791
|
+
try {
|
|
792
|
+
element.setAttribute(name, '');
|
|
793
|
+
} catch (_) {}
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
/**
|
|
798
|
+
* _initDocument
|
|
799
|
+
*
|
|
800
|
+
* @param dirty - a string of dirty markup
|
|
801
|
+
* @return a DOM, filled with the dirty markup
|
|
802
|
+
*/
|
|
803
|
+
const _initDocument = function _initDocument(dirty) {
|
|
804
|
+
/* Create a HTML document */
|
|
805
|
+
let doc = null;
|
|
806
|
+
let leadingWhitespace = null;
|
|
807
|
+
if (FORCE_BODY) {
|
|
808
|
+
dirty = '<remove></remove>' + dirty;
|
|
809
|
+
} else {
|
|
810
|
+
/* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */
|
|
811
|
+
const matches = stringMatch(dirty, /^[\r\n\t ]+/);
|
|
812
|
+
leadingWhitespace = matches && matches[0];
|
|
813
|
+
}
|
|
814
|
+
if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {
|
|
815
|
+
// Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
|
|
816
|
+
dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
|
|
817
|
+
}
|
|
818
|
+
const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
|
|
819
|
+
/*
|
|
820
|
+
* Use the DOMParser API by default, fallback later if needs be
|
|
821
|
+
* DOMParser not work for svg when has multiple root element.
|
|
822
|
+
*/
|
|
823
|
+
if (NAMESPACE === HTML_NAMESPACE) {
|
|
824
|
+
try {
|
|
825
|
+
doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
|
|
826
|
+
} catch (_) {}
|
|
827
|
+
}
|
|
828
|
+
/* Use createHTMLDocument in case DOMParser is not available */
|
|
829
|
+
if (!doc || !doc.documentElement) {
|
|
830
|
+
doc = implementation.createDocument(NAMESPACE, 'template', null);
|
|
831
|
+
try {
|
|
832
|
+
doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
|
|
833
|
+
} catch (_) {
|
|
834
|
+
// Syntax error if dirtyPayload is invalid xml
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
const body = doc.body || doc.documentElement;
|
|
838
|
+
if (dirty && leadingWhitespace) {
|
|
839
|
+
body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
|
|
840
|
+
}
|
|
841
|
+
/* Work on whole document or just its body */
|
|
842
|
+
if (NAMESPACE === HTML_NAMESPACE) {
|
|
843
|
+
return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
|
|
844
|
+
}
|
|
845
|
+
return WHOLE_DOCUMENT ? doc.documentElement : body;
|
|
846
|
+
};
|
|
847
|
+
/**
|
|
848
|
+
* Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
|
|
849
|
+
*
|
|
850
|
+
* @param root The root element or node to start traversing on.
|
|
851
|
+
* @return The created NodeIterator
|
|
852
|
+
*/
|
|
853
|
+
const _createNodeIterator = function _createNodeIterator(root) {
|
|
854
|
+
return createNodeIterator.call(root.ownerDocument || root, root,
|
|
855
|
+
// eslint-disable-next-line no-bitwise
|
|
856
|
+
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
|
|
857
|
+
};
|
|
858
|
+
/**
|
|
859
|
+
* _isClobbered
|
|
860
|
+
*
|
|
861
|
+
* @param element element to check for clobbering attacks
|
|
862
|
+
* @return true if clobbered, false if safe
|
|
863
|
+
*/
|
|
864
|
+
const _isClobbered = function _isClobbered(element) {
|
|
865
|
+
return element instanceof HTMLFormElement && (typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' || !(element.attributes instanceof NamedNodeMap) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function');
|
|
866
|
+
};
|
|
867
|
+
/**
|
|
868
|
+
* Checks whether the given object is a DOM node.
|
|
869
|
+
*
|
|
870
|
+
* @param value object to check whether it's a DOM node
|
|
871
|
+
* @return true is object is a DOM node
|
|
872
|
+
*/
|
|
873
|
+
const _isNode = function _isNode(value) {
|
|
874
|
+
return typeof Node === 'function' && value instanceof Node;
|
|
875
|
+
};
|
|
876
|
+
function _executeHooks(hooks, currentNode, data) {
|
|
877
|
+
arrayForEach(hooks, hook => {
|
|
878
|
+
hook.call(DOMPurify, currentNode, data, CONFIG);
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
882
|
+
* _sanitizeElements
|
|
883
|
+
*
|
|
884
|
+
* @protect nodeName
|
|
885
|
+
* @protect textContent
|
|
886
|
+
* @protect removeChild
|
|
887
|
+
* @param currentNode to check for permission to exist
|
|
888
|
+
* @return true if node was killed, false if left alive
|
|
889
|
+
*/
|
|
890
|
+
const _sanitizeElements = function _sanitizeElements(currentNode) {
|
|
891
|
+
let content = null;
|
|
892
|
+
/* Execute a hook if present */
|
|
893
|
+
_executeHooks(hooks.beforeSanitizeElements, currentNode, null);
|
|
894
|
+
/* Check if element is clobbered or can clobber */
|
|
895
|
+
if (_isClobbered(currentNode)) {
|
|
896
|
+
_forceRemove(currentNode);
|
|
897
|
+
return true;
|
|
898
|
+
}
|
|
899
|
+
/* Now let's check the element's type and name */
|
|
900
|
+
const tagName = transformCaseFunc(currentNode.nodeName);
|
|
901
|
+
/* Execute a hook if present */
|
|
902
|
+
_executeHooks(hooks.uponSanitizeElement, currentNode, {
|
|
903
|
+
tagName,
|
|
904
|
+
allowedTags: ALLOWED_TAGS
|
|
905
|
+
});
|
|
906
|
+
/* Detect mXSS attempts abusing namespace confusion */
|
|
907
|
+
if (currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w]/g, currentNode.innerHTML) && regExpTest(/<[/\w]/g, currentNode.textContent)) {
|
|
908
|
+
_forceRemove(currentNode);
|
|
909
|
+
return true;
|
|
910
|
+
}
|
|
911
|
+
/* Remove any occurrence of processing instructions */
|
|
912
|
+
if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
|
|
913
|
+
_forceRemove(currentNode);
|
|
914
|
+
return true;
|
|
915
|
+
}
|
|
916
|
+
/* Remove any kind of possibly harmful comments */
|
|
917
|
+
if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
|
|
918
|
+
_forceRemove(currentNode);
|
|
919
|
+
return true;
|
|
920
|
+
}
|
|
921
|
+
/* Remove element if anything forbids its presence */
|
|
922
|
+
if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
|
|
923
|
+
/* Check if we have a custom element to handle */
|
|
924
|
+
if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
|
|
925
|
+
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
|
|
926
|
+
return false;
|
|
927
|
+
}
|
|
928
|
+
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
|
|
929
|
+
return false;
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
/* Keep content except for bad-listed elements */
|
|
933
|
+
if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
|
|
934
|
+
const parentNode = getParentNode(currentNode) || currentNode.parentNode;
|
|
935
|
+
const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
|
|
936
|
+
if (childNodes && parentNode) {
|
|
937
|
+
const childCount = childNodes.length;
|
|
938
|
+
for (let i = childCount - 1; i >= 0; --i) {
|
|
939
|
+
const childClone = cloneNode(childNodes[i], true);
|
|
940
|
+
childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
|
|
941
|
+
parentNode.insertBefore(childClone, getNextSibling(currentNode));
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
_forceRemove(currentNode);
|
|
946
|
+
return true;
|
|
947
|
+
}
|
|
948
|
+
/* Check whether element has a valid namespace */
|
|
949
|
+
if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
|
|
950
|
+
_forceRemove(currentNode);
|
|
951
|
+
return true;
|
|
952
|
+
}
|
|
953
|
+
/* Make sure that older browsers don't get fallback-tag mXSS */
|
|
954
|
+
if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
|
|
955
|
+
_forceRemove(currentNode);
|
|
956
|
+
return true;
|
|
957
|
+
}
|
|
958
|
+
/* Sanitize element content to be template-safe */
|
|
959
|
+
if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
|
|
960
|
+
/* Get the element's text content */
|
|
961
|
+
content = currentNode.textContent;
|
|
962
|
+
arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
|
|
963
|
+
content = stringReplace(content, expr, ' ');
|
|
964
|
+
});
|
|
965
|
+
if (currentNode.textContent !== content) {
|
|
966
|
+
arrayPush(DOMPurify.removed, {
|
|
967
|
+
element: currentNode.cloneNode()
|
|
826
968
|
});
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
/* Decide if document with <html>... should be returned */ let WHOLE_DOCUMENT = false;
|
|
990
|
-
/* Track whether config is already set on this instance of DOMPurify. */ let SET_CONFIG = false;
|
|
991
|
-
/* Decide if all elements (e.g. style, script) must be children of
|
|
992
|
-
* document.body. By default, browsers might move them to document.head */ let FORCE_BODY = false;
|
|
993
|
-
/* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
|
|
994
|
-
* string (or a TrustedHTML object if Trusted Types are supported).
|
|
995
|
-
* If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
|
|
996
|
-
*/ let RETURN_DOM = false;
|
|
997
|
-
/* Decide if a DOM `DocumentFragment` should be returned, instead of a html
|
|
998
|
-
* string (or a TrustedHTML object if Trusted Types are supported) */ let RETURN_DOM_FRAGMENT = false;
|
|
999
|
-
/* Try to return a Trusted Type object instead of a string, return a string in
|
|
1000
|
-
* case Trusted Types are not supported */ let RETURN_TRUSTED_TYPE = false;
|
|
1001
|
-
/* Output should be free from DOM clobbering attacks?
|
|
1002
|
-
* This sanitizes markups named with colliding, clobberable built-in DOM APIs.
|
|
1003
|
-
*/ let SANITIZE_DOM = true;
|
|
1004
|
-
/* Achieve full DOM Clobbering protection by isolating the namespace of named
|
|
1005
|
-
* properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.
|
|
1006
|
-
*
|
|
1007
|
-
* HTML/DOM spec rules that enable DOM Clobbering:
|
|
1008
|
-
* - Named Access on Window (§7.3.3)
|
|
1009
|
-
* - DOM Tree Accessors (§3.1.5)
|
|
1010
|
-
* - Form Element Parent-Child Relations (§4.10.3)
|
|
1011
|
-
* - Iframe srcdoc / Nested WindowProxies (§4.8.5)
|
|
1012
|
-
* - HTMLCollection (§4.2.10.2)
|
|
1013
|
-
*
|
|
1014
|
-
* Namespace isolation is implemented by prefixing `id` and `name` attributes
|
|
1015
|
-
* with a constant string, i.e., `user-content-`
|
|
1016
|
-
*/ let SANITIZE_NAMED_PROPS = false;
|
|
1017
|
-
const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';
|
|
1018
|
-
/* Keep element content when removing element? */ let KEEP_CONTENT = true;
|
|
1019
|
-
/* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
|
|
1020
|
-
* of importing it into a new Document and returning a sanitized copy */ let IN_PLACE = false;
|
|
1021
|
-
/* Allow usage of profiles like html, svg and mathMl */ let USE_PROFILES = {};
|
|
1022
|
-
/* Tags to ignore content of when KEEP_CONTENT is true */ let FORBID_CONTENTS = null;
|
|
1023
|
-
const DEFAULT_FORBID_CONTENTS = addToSet({}, [
|
|
1024
|
-
'annotation-xml',
|
|
1025
|
-
'audio',
|
|
1026
|
-
'colgroup',
|
|
1027
|
-
'desc',
|
|
1028
|
-
'foreignobject',
|
|
1029
|
-
'head',
|
|
1030
|
-
'iframe',
|
|
1031
|
-
'math',
|
|
1032
|
-
'mi',
|
|
1033
|
-
'mn',
|
|
1034
|
-
'mo',
|
|
1035
|
-
'ms',
|
|
1036
|
-
'mtext',
|
|
1037
|
-
'noembed',
|
|
1038
|
-
'noframes',
|
|
1039
|
-
'noscript',
|
|
1040
|
-
'plaintext',
|
|
1041
|
-
'script',
|
|
1042
|
-
'style',
|
|
1043
|
-
'svg',
|
|
1044
|
-
'template',
|
|
1045
|
-
'thead',
|
|
1046
|
-
'title',
|
|
1047
|
-
'video',
|
|
1048
|
-
'xmp'
|
|
1049
|
-
]);
|
|
1050
|
-
/* Tags that are safe for data: URIs */ let DATA_URI_TAGS = null;
|
|
1051
|
-
const DEFAULT_DATA_URI_TAGS = addToSet({}, [
|
|
1052
|
-
'audio',
|
|
1053
|
-
'video',
|
|
1054
|
-
'img',
|
|
1055
|
-
'source',
|
|
1056
|
-
'image',
|
|
1057
|
-
'track'
|
|
1058
|
-
]);
|
|
1059
|
-
/* Attributes safe for values like "javascript:" */ let URI_SAFE_ATTRIBUTES = null;
|
|
1060
|
-
const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, [
|
|
1061
|
-
'alt',
|
|
1062
|
-
'class',
|
|
1063
|
-
'for',
|
|
1064
|
-
'id',
|
|
1065
|
-
'label',
|
|
1066
|
-
'name',
|
|
1067
|
-
'pattern',
|
|
1068
|
-
'placeholder',
|
|
1069
|
-
'role',
|
|
1070
|
-
'summary',
|
|
1071
|
-
'title',
|
|
1072
|
-
'value',
|
|
1073
|
-
'style',
|
|
1074
|
-
'xmlns'
|
|
1075
|
-
]);
|
|
1076
|
-
const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
|
|
1077
|
-
const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
|
|
1078
|
-
const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
|
|
1079
|
-
/* Document namespace */ let NAMESPACE = HTML_NAMESPACE;
|
|
1080
|
-
let IS_EMPTY_INPUT = false;
|
|
1081
|
-
/* Allowed XHTML+XML namespaces */ let ALLOWED_NAMESPACES = null;
|
|
1082
|
-
const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [
|
|
1083
|
-
MATHML_NAMESPACE,
|
|
1084
|
-
SVG_NAMESPACE,
|
|
1085
|
-
HTML_NAMESPACE
|
|
1086
|
-
], stringToString);
|
|
1087
|
-
/* Parsing of strict XHTML documents */ let PARSER_MEDIA_TYPE = null;
|
|
1088
|
-
const SUPPORTED_PARSER_MEDIA_TYPES = [
|
|
1089
|
-
'application/xhtml+xml',
|
|
1090
|
-
'text/html'
|
|
1091
|
-
];
|
|
1092
|
-
const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
|
|
1093
|
-
let transformCaseFunc = null;
|
|
1094
|
-
/* Keep a reference to config to pass to hooks */ let CONFIG = null;
|
|
1095
|
-
/* Ideally, do not touch anything below this line */ /* ______________________________________________ */ const formElement = document.createElement('form');
|
|
1096
|
-
const isRegexOrFunction = function isRegexOrFunction(testValue) {
|
|
1097
|
-
return testValue instanceof RegExp || testValue instanceof Function;
|
|
1098
|
-
};
|
|
1099
|
-
/**
|
|
1100
|
-
* _parseConfig
|
|
1101
|
-
*
|
|
1102
|
-
* @param {Object} cfg optional config literal
|
|
1103
|
-
*/ // eslint-disable-next-line complexity
|
|
1104
|
-
const _parseConfig = function _parseConfig() {
|
|
1105
|
-
let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1106
|
-
if (CONFIG && CONFIG === cfg) {
|
|
1107
|
-
return;
|
|
1108
|
-
}
|
|
1109
|
-
/* Shield configuration object from tampering */ if (!cfg || typeof cfg !== 'object') {
|
|
1110
|
-
cfg = {};
|
|
1111
|
-
}
|
|
1112
|
-
/* Shield configuration object from prototype pollution */ cfg = clone(cfg);
|
|
1113
|
-
PARSER_MEDIA_TYPE = // eslint-disable-next-line unicorn/prefer-includes
|
|
1114
|
-
SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
|
|
1115
|
-
// HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
|
|
1116
|
-
transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
|
|
1117
|
-
/* Set configuration parameters */ ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
|
|
1118
|
-
ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
|
|
1119
|
-
ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
|
|
1120
|
-
URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), // eslint-disable-line indent
|
|
1121
|
-
cfg.ADD_URI_SAFE_ATTR, // eslint-disable-line indent
|
|
1122
|
-
transformCaseFunc // eslint-disable-line indent
|
|
1123
|
-
) // eslint-disable-line indent
|
|
1124
|
-
: DEFAULT_URI_SAFE_ATTRIBUTES;
|
|
1125
|
-
DATA_URI_TAGS = objectHasOwnProperty(cfg, 'ADD_DATA_URI_TAGS') ? addToSet(clone(DEFAULT_DATA_URI_TAGS), // eslint-disable-line indent
|
|
1126
|
-
cfg.ADD_DATA_URI_TAGS, // eslint-disable-line indent
|
|
1127
|
-
transformCaseFunc // eslint-disable-line indent
|
|
1128
|
-
) // eslint-disable-line indent
|
|
1129
|
-
: DEFAULT_DATA_URI_TAGS;
|
|
1130
|
-
FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
|
|
1131
|
-
FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : {};
|
|
1132
|
-
FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : {};
|
|
1133
|
-
USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES : false;
|
|
1134
|
-
ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
|
|
1135
|
-
ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
|
|
1136
|
-
ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
|
|
1137
|
-
ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true
|
|
1138
|
-
SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
|
|
1139
|
-
SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false; // Default true
|
|
1140
|
-
WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
|
|
1141
|
-
RETURN_DOM = cfg.RETURN_DOM || false; // Default false
|
|
1142
|
-
RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false
|
|
1143
|
-
RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false
|
|
1144
|
-
FORCE_BODY = cfg.FORCE_BODY || false; // Default false
|
|
1145
|
-
SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
|
|
1146
|
-
SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
|
|
1147
|
-
KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
|
|
1148
|
-
IN_PLACE = cfg.IN_PLACE || false; // Default false
|
|
1149
|
-
IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
|
|
1150
|
-
NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
|
|
1151
|
-
CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
|
|
1152
|
-
if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
|
|
1153
|
-
CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
|
|
1154
|
-
}
|
|
1155
|
-
if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
|
|
1156
|
-
CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
|
|
1157
|
-
}
|
|
1158
|
-
if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
|
|
1159
|
-
CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
|
|
1160
|
-
}
|
|
1161
|
-
if (SAFE_FOR_TEMPLATES) {
|
|
1162
|
-
ALLOW_DATA_ATTR = false;
|
|
1163
|
-
}
|
|
1164
|
-
if (RETURN_DOM_FRAGMENT) {
|
|
1165
|
-
RETURN_DOM = true;
|
|
1166
|
-
}
|
|
1167
|
-
/* Parse profile info */ if (USE_PROFILES) {
|
|
1168
|
-
ALLOWED_TAGS = addToSet({}, text);
|
|
1169
|
-
ALLOWED_ATTR = [];
|
|
1170
|
-
if (USE_PROFILES.html === true) {
|
|
1171
|
-
addToSet(ALLOWED_TAGS, html$1);
|
|
1172
|
-
addToSet(ALLOWED_ATTR, html);
|
|
1173
|
-
}
|
|
1174
|
-
if (USE_PROFILES.svg === true) {
|
|
1175
|
-
addToSet(ALLOWED_TAGS, svg$1);
|
|
1176
|
-
addToSet(ALLOWED_ATTR, svg);
|
|
1177
|
-
addToSet(ALLOWED_ATTR, xml);
|
|
1178
|
-
}
|
|
1179
|
-
if (USE_PROFILES.svgFilters === true) {
|
|
1180
|
-
addToSet(ALLOWED_TAGS, svgFilters);
|
|
1181
|
-
addToSet(ALLOWED_ATTR, svg);
|
|
1182
|
-
addToSet(ALLOWED_ATTR, xml);
|
|
1183
|
-
}
|
|
1184
|
-
if (USE_PROFILES.mathMl === true) {
|
|
1185
|
-
addToSet(ALLOWED_TAGS, mathMl$1);
|
|
1186
|
-
addToSet(ALLOWED_ATTR, mathMl);
|
|
1187
|
-
addToSet(ALLOWED_ATTR, xml);
|
|
1188
|
-
}
|
|
1189
|
-
}
|
|
1190
|
-
/* Merge configuration parameters */ if (cfg.ADD_TAGS) {
|
|
1191
|
-
if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
|
|
1192
|
-
ALLOWED_TAGS = clone(ALLOWED_TAGS);
|
|
1193
|
-
}
|
|
1194
|
-
addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
|
|
1195
|
-
}
|
|
1196
|
-
if (cfg.ADD_ATTR) {
|
|
1197
|
-
if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
|
|
1198
|
-
ALLOWED_ATTR = clone(ALLOWED_ATTR);
|
|
1199
|
-
}
|
|
1200
|
-
addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
|
|
1201
|
-
}
|
|
1202
|
-
if (cfg.ADD_URI_SAFE_ATTR) {
|
|
1203
|
-
addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
|
|
1204
|
-
}
|
|
1205
|
-
if (cfg.FORBID_CONTENTS) {
|
|
1206
|
-
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
|
|
1207
|
-
FORBID_CONTENTS = clone(FORBID_CONTENTS);
|
|
1208
|
-
}
|
|
1209
|
-
addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
|
|
1210
|
-
}
|
|
1211
|
-
/* Add #text in case KEEP_CONTENT is set to true */ if (KEEP_CONTENT) {
|
|
1212
|
-
ALLOWED_TAGS['#text'] = true;
|
|
1213
|
-
}
|
|
1214
|
-
/* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */ if (WHOLE_DOCUMENT) {
|
|
1215
|
-
addToSet(ALLOWED_TAGS, [
|
|
1216
|
-
'html',
|
|
1217
|
-
'head',
|
|
1218
|
-
'body'
|
|
1219
|
-
]);
|
|
1220
|
-
}
|
|
1221
|
-
/* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */ if (ALLOWED_TAGS.table) {
|
|
1222
|
-
addToSet(ALLOWED_TAGS, [
|
|
1223
|
-
'tbody'
|
|
1224
|
-
]);
|
|
1225
|
-
delete FORBID_TAGS.tbody;
|
|
1226
|
-
}
|
|
1227
|
-
if (cfg.TRUSTED_TYPES_POLICY) {
|
|
1228
|
-
if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
|
|
1229
|
-
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
|
|
1230
|
-
}
|
|
1231
|
-
if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
|
|
1232
|
-
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
|
|
1233
|
-
}
|
|
1234
|
-
// Overwrite existing TrustedTypes policy.
|
|
1235
|
-
trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
|
|
1236
|
-
// Sign local variables required by `sanitize`.
|
|
1237
|
-
emptyHTML = trustedTypesPolicy.createHTML('');
|
|
1238
|
-
} else {
|
|
1239
|
-
// Uninitialized policy, attempt to initialize the internal dompurify policy.
|
|
1240
|
-
if (trustedTypesPolicy === undefined) {
|
|
1241
|
-
trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
|
|
1242
|
-
}
|
|
1243
|
-
// If creating the internal policy succeeded sign internal variables.
|
|
1244
|
-
if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {
|
|
1245
|
-
emptyHTML = trustedTypesPolicy.createHTML('');
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
// Prevent further manipulation of configuration.
|
|
1249
|
-
// Not available in IE8, Safari 5, etc.
|
|
1250
|
-
if (freeze) {
|
|
1251
|
-
freeze(cfg);
|
|
1252
|
-
}
|
|
1253
|
-
CONFIG = cfg;
|
|
1254
|
-
};
|
|
1255
|
-
const MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, [
|
|
1256
|
-
'mi',
|
|
1257
|
-
'mo',
|
|
1258
|
-
'mn',
|
|
1259
|
-
'ms',
|
|
1260
|
-
'mtext'
|
|
1261
|
-
]);
|
|
1262
|
-
const HTML_INTEGRATION_POINTS = addToSet({}, [
|
|
1263
|
-
'foreignobject',
|
|
1264
|
-
'annotation-xml'
|
|
1265
|
-
]);
|
|
1266
|
-
// Certain elements are allowed in both SVG and HTML
|
|
1267
|
-
// namespace. We need to specify them explicitly
|
|
1268
|
-
// so that they don't get erroneously deleted from
|
|
1269
|
-
// HTML namespace.
|
|
1270
|
-
const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, [
|
|
1271
|
-
'title',
|
|
1272
|
-
'style',
|
|
1273
|
-
'font',
|
|
1274
|
-
'a',
|
|
1275
|
-
'script'
|
|
1276
|
-
]);
|
|
1277
|
-
/* Keep track of all possible SVG and MathML tags
|
|
1278
|
-
* so that we can perform the namespace checks
|
|
1279
|
-
* correctly. */ const ALL_SVG_TAGS = addToSet({}, [
|
|
1280
|
-
...svg$1,
|
|
1281
|
-
...svgFilters,
|
|
1282
|
-
...svgDisallowed
|
|
1283
|
-
]);
|
|
1284
|
-
const ALL_MATHML_TAGS = addToSet({}, [
|
|
1285
|
-
...mathMl$1,
|
|
1286
|
-
...mathMlDisallowed
|
|
1287
|
-
]);
|
|
1288
|
-
/**
|
|
1289
|
-
* @param {Element} element a DOM element whose namespace is being checked
|
|
1290
|
-
* @returns {boolean} Return false if the element has a
|
|
1291
|
-
* namespace that a spec-compliant parser would never
|
|
1292
|
-
* return. Return true otherwise.
|
|
1293
|
-
*/ const _checkValidNamespace = function _checkValidNamespace(element) {
|
|
1294
|
-
let parent = getParentNode(element);
|
|
1295
|
-
// In JSDOM, if we're inside shadow DOM, then parentNode
|
|
1296
|
-
// can be null. We just simulate parent in this case.
|
|
1297
|
-
if (!parent || !parent.tagName) {
|
|
1298
|
-
parent = {
|
|
1299
|
-
namespaceURI: NAMESPACE,
|
|
1300
|
-
tagName: 'template'
|
|
1301
|
-
};
|
|
1302
|
-
}
|
|
1303
|
-
const tagName = stringToLowerCase(element.tagName);
|
|
1304
|
-
const parentTagName = stringToLowerCase(parent.tagName);
|
|
1305
|
-
if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
|
|
1306
|
-
return false;
|
|
1307
|
-
}
|
|
1308
|
-
if (element.namespaceURI === SVG_NAMESPACE) {
|
|
1309
|
-
// The only way to switch from HTML namespace to SVG
|
|
1310
|
-
// is via <svg>. If it happens via any other tag, then
|
|
1311
|
-
// it should be killed.
|
|
1312
|
-
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
1313
|
-
return tagName === 'svg';
|
|
1314
|
-
}
|
|
1315
|
-
// The only way to switch from MathML to SVG is via`
|
|
1316
|
-
// svg if parent is either <annotation-xml> or MathML
|
|
1317
|
-
// text integration points.
|
|
1318
|
-
if (parent.namespaceURI === MATHML_NAMESPACE) {
|
|
1319
|
-
return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
|
|
1320
|
-
}
|
|
1321
|
-
// We only allow elements that are defined in SVG
|
|
1322
|
-
// spec. All others are disallowed in SVG namespace.
|
|
1323
|
-
return Boolean(ALL_SVG_TAGS[tagName]);
|
|
1324
|
-
}
|
|
1325
|
-
if (element.namespaceURI === MATHML_NAMESPACE) {
|
|
1326
|
-
// The only way to switch from HTML namespace to MathML
|
|
1327
|
-
// is via <math>. If it happens via any other tag, then
|
|
1328
|
-
// it should be killed.
|
|
1329
|
-
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
1330
|
-
return tagName === 'math';
|
|
1331
|
-
}
|
|
1332
|
-
// The only way to switch from SVG to MathML is via
|
|
1333
|
-
// <math> and HTML integration points
|
|
1334
|
-
if (parent.namespaceURI === SVG_NAMESPACE) {
|
|
1335
|
-
return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
|
|
1336
|
-
}
|
|
1337
|
-
// We only allow elements that are defined in MathML
|
|
1338
|
-
// spec. All others are disallowed in MathML namespace.
|
|
1339
|
-
return Boolean(ALL_MATHML_TAGS[tagName]);
|
|
1340
|
-
}
|
|
1341
|
-
if (element.namespaceURI === HTML_NAMESPACE) {
|
|
1342
|
-
// The only way to switch from SVG to HTML is via
|
|
1343
|
-
// HTML integration points, and from MathML to HTML
|
|
1344
|
-
// is via MathML text integration points
|
|
1345
|
-
if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
|
|
1346
|
-
return false;
|
|
1347
|
-
}
|
|
1348
|
-
if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
|
|
1349
|
-
return false;
|
|
1350
|
-
}
|
|
1351
|
-
// We disallow tags that are specific for MathML
|
|
1352
|
-
// or SVG and should never appear in HTML namespace
|
|
1353
|
-
return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
|
|
1354
|
-
}
|
|
1355
|
-
// For XHTML and XML documents that support custom namespaces
|
|
1356
|
-
if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
|
|
1357
|
-
return true;
|
|
1358
|
-
}
|
|
1359
|
-
// The code should never reach this place (this means
|
|
1360
|
-
// that the element somehow got namespace that is not
|
|
1361
|
-
// HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).
|
|
1362
|
-
// Return false just in case.
|
|
1363
|
-
return false;
|
|
1364
|
-
};
|
|
1365
|
-
/**
|
|
1366
|
-
* _forceRemove
|
|
1367
|
-
*
|
|
1368
|
-
* @param {Node} node a DOM node
|
|
1369
|
-
*/ const _forceRemove = function _forceRemove(node) {
|
|
1370
|
-
arrayPush(DOMPurify.removed, {
|
|
1371
|
-
element: node
|
|
1372
|
-
});
|
|
1373
|
-
try {
|
|
1374
|
-
// eslint-disable-next-line unicorn/prefer-dom-node-remove
|
|
1375
|
-
getParentNode(node).removeChild(node);
|
|
1376
|
-
} catch (_) {
|
|
1377
|
-
remove(node);
|
|
1378
|
-
}
|
|
1379
|
-
};
|
|
1380
|
-
/**
|
|
1381
|
-
* _removeAttribute
|
|
1382
|
-
*
|
|
1383
|
-
* @param {String} name an Attribute name
|
|
1384
|
-
* @param {Node} node a DOM node
|
|
1385
|
-
*/ const _removeAttribute = function _removeAttribute(name, node) {
|
|
1386
|
-
try {
|
|
1387
|
-
arrayPush(DOMPurify.removed, {
|
|
1388
|
-
attribute: node.getAttributeNode(name),
|
|
1389
|
-
from: node
|
|
1390
|
-
});
|
|
1391
|
-
} catch (_) {
|
|
1392
|
-
arrayPush(DOMPurify.removed, {
|
|
1393
|
-
attribute: null,
|
|
1394
|
-
from: node
|
|
1395
|
-
});
|
|
1396
|
-
}
|
|
1397
|
-
node.removeAttribute(name);
|
|
1398
|
-
// We void attribute values for unremovable "is"" attributes
|
|
1399
|
-
if (name === 'is' && !ALLOWED_ATTR[name]) {
|
|
1400
|
-
if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
|
|
1401
|
-
try {
|
|
1402
|
-
_forceRemove(node);
|
|
1403
|
-
} catch (_) {}
|
|
1404
|
-
} else {
|
|
1405
|
-
try {
|
|
1406
|
-
node.setAttribute(name, '');
|
|
1407
|
-
} catch (_) {}
|
|
1408
|
-
}
|
|
1409
|
-
}
|
|
1410
|
-
};
|
|
1411
|
-
/**
|
|
1412
|
-
* _initDocument
|
|
1413
|
-
*
|
|
1414
|
-
* @param {String} dirty a string of dirty markup
|
|
1415
|
-
* @return {Document} a DOM, filled with the dirty markup
|
|
1416
|
-
*/ const _initDocument = function _initDocument(dirty) {
|
|
1417
|
-
/* Create a HTML document */ let doc = null;
|
|
1418
|
-
let leadingWhitespace = null;
|
|
1419
|
-
if (FORCE_BODY) {
|
|
1420
|
-
dirty = '<remove></remove>' + dirty;
|
|
1421
|
-
} else {
|
|
1422
|
-
/* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */ const matches = stringMatch(dirty, /^[\r\n\t ]+/);
|
|
1423
|
-
leadingWhitespace = matches && matches[0];
|
|
1424
|
-
}
|
|
1425
|
-
if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {
|
|
1426
|
-
// Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
|
|
1427
|
-
dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
|
|
1428
|
-
}
|
|
1429
|
-
const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
|
|
1430
|
-
/*
|
|
1431
|
-
* Use the DOMParser API by default, fallback later if needs be
|
|
1432
|
-
* DOMParser not work for svg when has multiple root element.
|
|
1433
|
-
*/ if (NAMESPACE === HTML_NAMESPACE) {
|
|
1434
|
-
try {
|
|
1435
|
-
doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
|
|
1436
|
-
} catch (_) {}
|
|
1437
|
-
}
|
|
1438
|
-
/* Use createHTMLDocument in case DOMParser is not available */ if (!doc || !doc.documentElement) {
|
|
1439
|
-
doc = implementation.createDocument(NAMESPACE, 'template', null);
|
|
1440
|
-
try {
|
|
1441
|
-
doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
|
|
1442
|
-
} catch (_) {
|
|
1443
|
-
// Syntax error if dirtyPayload is invalid xml
|
|
1444
|
-
}
|
|
1445
|
-
}
|
|
1446
|
-
const body = doc.body || doc.documentElement;
|
|
1447
|
-
if (dirty && leadingWhitespace) {
|
|
1448
|
-
body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
|
|
1449
|
-
}
|
|
1450
|
-
/* Work on whole document or just its body */ if (NAMESPACE === HTML_NAMESPACE) {
|
|
1451
|
-
return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
|
|
1452
|
-
}
|
|
1453
|
-
return WHOLE_DOCUMENT ? doc.documentElement : body;
|
|
1454
|
-
};
|
|
1455
|
-
/**
|
|
1456
|
-
* Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
|
|
1457
|
-
*
|
|
1458
|
-
* @param {Node} root The root element or node to start traversing on.
|
|
1459
|
-
* @return {NodeIterator} The created NodeIterator
|
|
1460
|
-
*/ const _createNodeIterator = function _createNodeIterator(root) {
|
|
1461
|
-
return createNodeIterator.call(root.ownerDocument || root, root, // eslint-disable-next-line no-bitwise
|
|
1462
|
-
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
|
|
1463
|
-
};
|
|
1464
|
-
/**
|
|
1465
|
-
* _isClobbered
|
|
1466
|
-
*
|
|
1467
|
-
* @param {Node} elm element to check for clobbering attacks
|
|
1468
|
-
* @return {Boolean} true if clobbered, false if safe
|
|
1469
|
-
*/ const _isClobbered = function _isClobbered(elm) {
|
|
1470
|
-
return elm instanceof HTMLFormElement && (typeof elm.nodeName !== 'string' || typeof elm.textContent !== 'string' || typeof elm.removeChild !== 'function' || !(elm.attributes instanceof NamedNodeMap) || typeof elm.removeAttribute !== 'function' || typeof elm.setAttribute !== 'function' || typeof elm.namespaceURI !== 'string' || typeof elm.insertBefore !== 'function' || typeof elm.hasChildNodes !== 'function');
|
|
1471
|
-
};
|
|
1472
|
-
/**
|
|
1473
|
-
* Checks whether the given object is a DOM node.
|
|
1474
|
-
*
|
|
1475
|
-
* @param {Node} object object to check whether it's a DOM node
|
|
1476
|
-
* @return {Boolean} true is object is a DOM node
|
|
1477
|
-
*/ const _isNode = function _isNode(object) {
|
|
1478
|
-
return typeof Node === 'function' && object instanceof Node;
|
|
1479
|
-
};
|
|
1480
|
-
/**
|
|
1481
|
-
* _executeHook
|
|
1482
|
-
* Execute user configurable hooks
|
|
1483
|
-
*
|
|
1484
|
-
* @param {String} entryPoint Name of the hook's entry point
|
|
1485
|
-
* @param {Node} currentNode node to work on with the hook
|
|
1486
|
-
* @param {Object} data additional hook parameters
|
|
1487
|
-
*/ const _executeHook = function _executeHook(entryPoint, currentNode, data) {
|
|
1488
|
-
if (!hooks[entryPoint]) {
|
|
1489
|
-
return;
|
|
1490
|
-
}
|
|
1491
|
-
arrayForEach(hooks[entryPoint], (hook)=>{
|
|
1492
|
-
hook.call(DOMPurify, currentNode, data, CONFIG);
|
|
1493
|
-
});
|
|
1494
|
-
};
|
|
1495
|
-
/**
|
|
1496
|
-
* _sanitizeElements
|
|
1497
|
-
*
|
|
1498
|
-
* @protect nodeName
|
|
1499
|
-
* @protect textContent
|
|
1500
|
-
* @protect removeChild
|
|
1501
|
-
*
|
|
1502
|
-
* @param {Node} currentNode to check for permission to exist
|
|
1503
|
-
* @return {Boolean} true if node was killed, false if left alive
|
|
1504
|
-
*/ const _sanitizeElements = function _sanitizeElements(currentNode) {
|
|
1505
|
-
let content = null;
|
|
1506
|
-
/* Execute a hook if present */ _executeHook('beforeSanitizeElements', currentNode, null);
|
|
1507
|
-
/* Check if element is clobbered or can clobber */ if (_isClobbered(currentNode)) {
|
|
1508
|
-
_forceRemove(currentNode);
|
|
1509
|
-
return true;
|
|
1510
|
-
}
|
|
1511
|
-
/* Now let's check the element's type and name */ const tagName = transformCaseFunc(currentNode.nodeName);
|
|
1512
|
-
/* Execute a hook if present */ _executeHook('uponSanitizeElement', currentNode, {
|
|
1513
|
-
tagName,
|
|
1514
|
-
allowedTags: ALLOWED_TAGS
|
|
1515
|
-
});
|
|
1516
|
-
/* Detect mXSS attempts abusing namespace confusion */ if (currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w]/g, currentNode.innerHTML) && regExpTest(/<[/\w]/g, currentNode.textContent)) {
|
|
1517
|
-
_forceRemove(currentNode);
|
|
1518
|
-
return true;
|
|
1519
|
-
}
|
|
1520
|
-
/* Remove any occurrence of processing instructions */ if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
|
|
1521
|
-
_forceRemove(currentNode);
|
|
1522
|
-
return true;
|
|
1523
|
-
}
|
|
1524
|
-
/* Remove any kind of possibly harmful comments */ if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
|
|
1525
|
-
_forceRemove(currentNode);
|
|
1526
|
-
return true;
|
|
1527
|
-
}
|
|
1528
|
-
/* Remove element if anything forbids its presence */ if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
|
|
1529
|
-
/* Check if we have a custom element to handle */ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
|
|
1530
|
-
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
|
|
1531
|
-
return false;
|
|
1532
|
-
}
|
|
1533
|
-
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
|
|
1534
|
-
return false;
|
|
1535
|
-
}
|
|
1536
|
-
}
|
|
1537
|
-
/* Keep content except for bad-listed elements */ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
|
|
1538
|
-
const parentNode = getParentNode(currentNode) || currentNode.parentNode;
|
|
1539
|
-
const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
|
|
1540
|
-
if (childNodes && parentNode) {
|
|
1541
|
-
const childCount = childNodes.length;
|
|
1542
|
-
for(let i = childCount - 1; i >= 0; --i){
|
|
1543
|
-
const childClone = cloneNode(childNodes[i], true);
|
|
1544
|
-
childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
|
|
1545
|
-
parentNode.insertBefore(childClone, getNextSibling(currentNode));
|
|
1546
|
-
}
|
|
1547
|
-
}
|
|
1548
|
-
}
|
|
1549
|
-
_forceRemove(currentNode);
|
|
1550
|
-
return true;
|
|
1551
|
-
}
|
|
1552
|
-
/* Check whether element has a valid namespace */ if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
|
|
1553
|
-
_forceRemove(currentNode);
|
|
1554
|
-
return true;
|
|
1555
|
-
}
|
|
1556
|
-
/* Make sure that older browsers don't get fallback-tag mXSS */ if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
|
|
1557
|
-
_forceRemove(currentNode);
|
|
1558
|
-
return true;
|
|
1559
|
-
}
|
|
1560
|
-
/* Sanitize element content to be template-safe */ if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
|
|
1561
|
-
/* Get the element's text content */ content = currentNode.textContent;
|
|
1562
|
-
arrayForEach([
|
|
1563
|
-
MUSTACHE_EXPR,
|
|
1564
|
-
ERB_EXPR,
|
|
1565
|
-
TMPLIT_EXPR
|
|
1566
|
-
], (expr)=>{
|
|
1567
|
-
content = stringReplace(content, expr, ' ');
|
|
1568
|
-
});
|
|
1569
|
-
if (currentNode.textContent !== content) {
|
|
1570
|
-
arrayPush(DOMPurify.removed, {
|
|
1571
|
-
element: currentNode.cloneNode()
|
|
1572
|
-
});
|
|
1573
|
-
currentNode.textContent = content;
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
/* Execute a hook if present */ _executeHook('afterSanitizeElements', currentNode, null);
|
|
1577
|
-
return false;
|
|
1578
|
-
};
|
|
1579
|
-
/**
|
|
1580
|
-
* _isValidAttribute
|
|
1581
|
-
*
|
|
1582
|
-
* @param {string} lcTag Lowercase tag name of containing element.
|
|
1583
|
-
* @param {string} lcName Lowercase attribute name.
|
|
1584
|
-
* @param {string} value Attribute value.
|
|
1585
|
-
* @return {Boolean} Returns true if `value` is valid, otherwise false.
|
|
1586
|
-
*/ // eslint-disable-next-line complexity
|
|
1587
|
-
const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
|
|
1588
|
-
/* Make sure attribute cannot clobber */ if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
|
|
1589
|
-
return false;
|
|
1590
|
-
}
|
|
1591
|
-
/* Allow valid data-* attributes: At least one character after "-"
|
|
1592
|
-
(https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
|
|
1593
|
-
XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
|
|
1594
|
-
We don't need to check the value; it's always URI safe. */ if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ;
|
|
1595
|
-
else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ;
|
|
1596
|
-
else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
|
|
1597
|
-
if (// First condition does a very basic check if a) it's basically a valid custom element tagname AND
|
|
1598
|
-
// b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
|
1599
|
-
// and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
|
|
1600
|
-
_isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName)) || // Alternative, second condition checks if it's an `is`-attribute, AND
|
|
1601
|
-
// the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
|
1602
|
-
lcName === 'is' && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))) ;
|
|
1603
|
-
else {
|
|
1604
|
-
return false;
|
|
1605
|
-
}
|
|
1606
|
-
/* Check value is safe. First, is attr inert? If so, is safe */ } else if (URI_SAFE_ATTRIBUTES[lcName]) ;
|
|
1607
|
-
else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE, ''))) ;
|
|
1608
|
-
else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ;
|
|
1609
|
-
else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA, stringReplace(value, ATTR_WHITESPACE, ''))) ;
|
|
1610
|
-
else if (value) {
|
|
1611
|
-
return false;
|
|
1612
|
-
} else ;
|
|
1613
|
-
return true;
|
|
1614
|
-
};
|
|
1615
|
-
/**
|
|
1616
|
-
* _isBasicCustomElement
|
|
1617
|
-
* checks if at least one dash is included in tagName, and it's not the first char
|
|
1618
|
-
* for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
|
|
1619
|
-
*
|
|
1620
|
-
* @param {string} tagName name of the tag of the node to sanitize
|
|
1621
|
-
* @returns {boolean} Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
|
|
1622
|
-
*/ const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
|
|
1623
|
-
return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);
|
|
1624
|
-
};
|
|
1625
|
-
/**
|
|
1626
|
-
* _sanitizeAttributes
|
|
1627
|
-
*
|
|
1628
|
-
* @protect attributes
|
|
1629
|
-
* @protect nodeName
|
|
1630
|
-
* @protect removeAttribute
|
|
1631
|
-
* @protect setAttribute
|
|
1632
|
-
*
|
|
1633
|
-
* @param {Node} currentNode to sanitize
|
|
1634
|
-
*/ const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
|
|
1635
|
-
/* Execute a hook if present */ _executeHook('beforeSanitizeAttributes', currentNode, null);
|
|
1636
|
-
const { attributes } = currentNode;
|
|
1637
|
-
/* Check if we have attributes; if not we might have a text node */ if (!attributes) {
|
|
1638
|
-
return;
|
|
1639
|
-
}
|
|
1640
|
-
const hookEvent = {
|
|
1641
|
-
attrName: '',
|
|
1642
|
-
attrValue: '',
|
|
1643
|
-
keepAttr: true,
|
|
1644
|
-
allowedAttributes: ALLOWED_ATTR
|
|
1645
|
-
};
|
|
1646
|
-
let l = attributes.length;
|
|
1647
|
-
/* Go backwards over all attributes; safely remove bad ones */ while(l--){
|
|
1648
|
-
const attr = attributes[l];
|
|
1649
|
-
const { name, namespaceURI, value: attrValue } = attr;
|
|
1650
|
-
const lcName = transformCaseFunc(name);
|
|
1651
|
-
let value = name === 'value' ? attrValue : stringTrim(attrValue);
|
|
1652
|
-
/* Execute a hook if present */ hookEvent.attrName = lcName;
|
|
1653
|
-
hookEvent.attrValue = value;
|
|
1654
|
-
hookEvent.keepAttr = true;
|
|
1655
|
-
hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
|
|
1656
|
-
_executeHook('uponSanitizeAttribute', currentNode, hookEvent);
|
|
1657
|
-
value = hookEvent.attrValue;
|
|
1658
|
-
/* Work around a security issue with comments inside attributes */ if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title)/i, value)) {
|
|
1659
|
-
_removeAttribute(name, currentNode);
|
|
1660
|
-
continue;
|
|
1661
|
-
}
|
|
1662
|
-
/* Did the hooks approve of the attribute? */ if (hookEvent.forceKeepAttr) {
|
|
1663
|
-
continue;
|
|
1664
|
-
}
|
|
1665
|
-
/* Remove attribute */ _removeAttribute(name, currentNode);
|
|
1666
|
-
/* Did the hooks approve of the attribute? */ if (!hookEvent.keepAttr) {
|
|
1667
|
-
continue;
|
|
1668
|
-
}
|
|
1669
|
-
/* Work around a security issue in jQuery 3.0 */ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
|
|
1670
|
-
_removeAttribute(name, currentNode);
|
|
1671
|
-
continue;
|
|
1672
|
-
}
|
|
1673
|
-
/* Sanitize attribute content to be template-safe */ if (SAFE_FOR_TEMPLATES) {
|
|
1674
|
-
arrayForEach([
|
|
1675
|
-
MUSTACHE_EXPR,
|
|
1676
|
-
ERB_EXPR,
|
|
1677
|
-
TMPLIT_EXPR
|
|
1678
|
-
], (expr)=>{
|
|
1679
|
-
value = stringReplace(value, expr, ' ');
|
|
1680
|
-
});
|
|
1681
|
-
}
|
|
1682
|
-
/* Is `value` valid for this attribute? */ const lcTag = transformCaseFunc(currentNode.nodeName);
|
|
1683
|
-
if (!_isValidAttribute(lcTag, lcName, value)) {
|
|
1684
|
-
continue;
|
|
1685
|
-
}
|
|
1686
|
-
/* Full DOM Clobbering protection via namespace isolation,
|
|
1687
|
-
* Prefix id and name attributes with `user-content-`
|
|
1688
|
-
*/ if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
|
|
1689
|
-
// Remove the attribute with this value
|
|
1690
|
-
_removeAttribute(name, currentNode);
|
|
1691
|
-
// Prefix the value and later re-create the attribute with the sanitized value
|
|
1692
|
-
value = SANITIZE_NAMED_PROPS_PREFIX + value;
|
|
1693
|
-
}
|
|
1694
|
-
/* Handle attributes that require Trusted Types */ if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
|
|
1695
|
-
if (namespaceURI) ;
|
|
1696
|
-
else {
|
|
1697
|
-
switch(trustedTypes.getAttributeType(lcTag, lcName)){
|
|
1698
|
-
case 'TrustedHTML':
|
|
1699
|
-
{
|
|
1700
|
-
value = trustedTypesPolicy.createHTML(value);
|
|
1701
|
-
break;
|
|
1702
|
-
}
|
|
1703
|
-
case 'TrustedScriptURL':
|
|
1704
|
-
{
|
|
1705
|
-
value = trustedTypesPolicy.createScriptURL(value);
|
|
1706
|
-
break;
|
|
1707
|
-
}
|
|
1708
|
-
}
|
|
1709
|
-
}
|
|
1710
|
-
}
|
|
1711
|
-
/* Handle invalid data-* attribute set by try-catching it */ try {
|
|
1712
|
-
if (namespaceURI) {
|
|
1713
|
-
currentNode.setAttributeNS(namespaceURI, name, value);
|
|
1714
|
-
} else {
|
|
1715
|
-
/* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */ currentNode.setAttribute(name, value);
|
|
1716
|
-
}
|
|
1717
|
-
if (_isClobbered(currentNode)) {
|
|
1718
|
-
_forceRemove(currentNode);
|
|
1719
|
-
} else {
|
|
1720
|
-
arrayPop(DOMPurify.removed);
|
|
1721
|
-
}
|
|
1722
|
-
} catch (_) {}
|
|
1723
|
-
}
|
|
1724
|
-
/* Execute a hook if present */ _executeHook('afterSanitizeAttributes', currentNode, null);
|
|
1725
|
-
};
|
|
1726
|
-
/**
|
|
1727
|
-
* _sanitizeShadowDOM
|
|
1728
|
-
*
|
|
1729
|
-
* @param {DocumentFragment} fragment to iterate over recursively
|
|
1730
|
-
*/ const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
|
|
1731
|
-
let shadowNode = null;
|
|
1732
|
-
const shadowIterator = _createNodeIterator(fragment);
|
|
1733
|
-
/* Execute a hook if present */ _executeHook('beforeSanitizeShadowDOM', fragment, null);
|
|
1734
|
-
while(shadowNode = shadowIterator.nextNode()){
|
|
1735
|
-
/* Execute a hook if present */ _executeHook('uponSanitizeShadowNode', shadowNode, null);
|
|
1736
|
-
/* Sanitize tags and elements */ if (_sanitizeElements(shadowNode)) {
|
|
1737
|
-
continue;
|
|
1738
|
-
}
|
|
1739
|
-
/* Deep shadow DOM detected */ if (shadowNode.content instanceof DocumentFragment) {
|
|
1740
|
-
_sanitizeShadowDOM(shadowNode.content);
|
|
1741
|
-
}
|
|
1742
|
-
/* Check attributes, sanitize if necessary */ _sanitizeAttributes(shadowNode);
|
|
1743
|
-
}
|
|
1744
|
-
/* Execute a hook if present */ _executeHook('afterSanitizeShadowDOM', fragment, null);
|
|
1745
|
-
};
|
|
1746
|
-
/**
|
|
1747
|
-
* Sanitize
|
|
1748
|
-
* Public method providing core sanitation functionality
|
|
1749
|
-
*
|
|
1750
|
-
* @param {String|Node} dirty string or DOM node
|
|
1751
|
-
* @param {Object} cfg object
|
|
1752
|
-
*/ // eslint-disable-next-line complexity
|
|
1753
|
-
DOMPurify.sanitize = function(dirty) {
|
|
1754
|
-
let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1755
|
-
let body = null;
|
|
1756
|
-
let importedNode = null;
|
|
1757
|
-
let currentNode = null;
|
|
1758
|
-
let returnNode = null;
|
|
1759
|
-
/* Make sure we have a string to sanitize.
|
|
1760
|
-
DO NOT return early, as this will return the wrong type if
|
|
1761
|
-
the user has requested a DOM object rather than a string */ IS_EMPTY_INPUT = !dirty;
|
|
1762
|
-
if (IS_EMPTY_INPUT) {
|
|
1763
|
-
dirty = '<!-->';
|
|
1764
|
-
}
|
|
1765
|
-
/* Stringify, in case dirty is an object */ if (typeof dirty !== 'string' && !_isNode(dirty)) {
|
|
1766
|
-
if (typeof dirty.toString === 'function') {
|
|
1767
|
-
dirty = dirty.toString();
|
|
1768
|
-
if (typeof dirty !== 'string') {
|
|
1769
|
-
throw typeErrorCreate('dirty is not a string, aborting');
|
|
1770
|
-
}
|
|
1771
|
-
} else {
|
|
1772
|
-
throw typeErrorCreate('toString is not a function');
|
|
1773
|
-
}
|
|
1774
|
-
}
|
|
1775
|
-
/* Return dirty HTML if DOMPurify cannot run */ if (!DOMPurify.isSupported) {
|
|
1776
|
-
return dirty;
|
|
1777
|
-
}
|
|
1778
|
-
/* Assign config vars */ if (!SET_CONFIG) {
|
|
1779
|
-
_parseConfig(cfg);
|
|
1780
|
-
}
|
|
1781
|
-
/* Clean up removed elements */ DOMPurify.removed = [];
|
|
1782
|
-
/* Check if dirty is correctly typed for IN_PLACE */ if (typeof dirty === 'string') {
|
|
1783
|
-
IN_PLACE = false;
|
|
1784
|
-
}
|
|
1785
|
-
if (IN_PLACE) {
|
|
1786
|
-
/* Do some early pre-sanitization to avoid unsafe root nodes */ if (dirty.nodeName) {
|
|
1787
|
-
const tagName = transformCaseFunc(dirty.nodeName);
|
|
1788
|
-
if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
|
|
1789
|
-
throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
|
|
1790
|
-
}
|
|
1791
|
-
}
|
|
1792
|
-
} else if (dirty instanceof Node) {
|
|
1793
|
-
/* If dirty is a DOM element, append to an empty document to avoid
|
|
1794
|
-
elements being stripped by the parser */ body = _initDocument('<!---->');
|
|
1795
|
-
importedNode = body.ownerDocument.importNode(dirty, true);
|
|
1796
|
-
if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === 'BODY') {
|
|
1797
|
-
/* Node is already a body, use as is */ body = importedNode;
|
|
1798
|
-
} else if (importedNode.nodeName === 'HTML') {
|
|
1799
|
-
body = importedNode;
|
|
1800
|
-
} else {
|
|
1801
|
-
// eslint-disable-next-line unicorn/prefer-dom-node-append
|
|
1802
|
-
body.appendChild(importedNode);
|
|
1803
|
-
}
|
|
1804
|
-
} else {
|
|
1805
|
-
/* Exit directly if we have nothing to do */ if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && // eslint-disable-next-line unicorn/prefer-includes
|
|
1806
|
-
dirty.indexOf('<') === -1) {
|
|
1807
|
-
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
|
|
1808
|
-
}
|
|
1809
|
-
/* Initialize the document to work on */ body = _initDocument(dirty);
|
|
1810
|
-
/* Check we have a DOM node from the data */ if (!body) {
|
|
1811
|
-
return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
|
|
1812
|
-
}
|
|
1813
|
-
}
|
|
1814
|
-
/* Remove first element node (ours) if FORCE_BODY is set */ if (body && FORCE_BODY) {
|
|
1815
|
-
_forceRemove(body.firstChild);
|
|
1816
|
-
}
|
|
1817
|
-
/* Get node iterator */ const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
|
|
1818
|
-
/* Now start iterating over the created document */ while(currentNode = nodeIterator.nextNode()){
|
|
1819
|
-
/* Sanitize tags and elements */ if (_sanitizeElements(currentNode)) {
|
|
1820
|
-
continue;
|
|
1821
|
-
}
|
|
1822
|
-
/* Shadow DOM detected, sanitize it */ if (currentNode.content instanceof DocumentFragment) {
|
|
1823
|
-
_sanitizeShadowDOM(currentNode.content);
|
|
1824
|
-
}
|
|
1825
|
-
/* Check attributes, sanitize if necessary */ _sanitizeAttributes(currentNode);
|
|
1826
|
-
}
|
|
1827
|
-
/* If we sanitized `dirty` in-place, return it. */ if (IN_PLACE) {
|
|
1828
|
-
return dirty;
|
|
1829
|
-
}
|
|
1830
|
-
/* Return sanitized string or DOM */ if (RETURN_DOM) {
|
|
1831
|
-
if (RETURN_DOM_FRAGMENT) {
|
|
1832
|
-
returnNode = createDocumentFragment.call(body.ownerDocument);
|
|
1833
|
-
while(body.firstChild){
|
|
1834
|
-
// eslint-disable-next-line unicorn/prefer-dom-node-append
|
|
1835
|
-
returnNode.appendChild(body.firstChild);
|
|
1836
|
-
}
|
|
1837
|
-
} else {
|
|
1838
|
-
returnNode = body;
|
|
1839
|
-
}
|
|
1840
|
-
if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
|
|
1841
|
-
/*
|
|
1842
|
-
AdoptNode() is not used because internal state is not reset
|
|
1843
|
-
(e.g. the past names map of a HTMLFormElement), this is safe
|
|
1844
|
-
in theory but we would rather not risk another attack vector.
|
|
1845
|
-
The state that is cloned by importNode() is explicitly defined
|
|
1846
|
-
by the specs.
|
|
1847
|
-
*/ returnNode = importNode.call(originalDocument, returnNode, true);
|
|
1848
|
-
}
|
|
1849
|
-
return returnNode;
|
|
1850
|
-
}
|
|
1851
|
-
let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
|
|
1852
|
-
/* Serialize doctype if allowed */ if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
|
|
1853
|
-
serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
|
|
1854
|
-
}
|
|
1855
|
-
/* Sanitize final string template-safe */ if (SAFE_FOR_TEMPLATES) {
|
|
1856
|
-
arrayForEach([
|
|
1857
|
-
MUSTACHE_EXPR,
|
|
1858
|
-
ERB_EXPR,
|
|
1859
|
-
TMPLIT_EXPR
|
|
1860
|
-
], (expr)=>{
|
|
1861
|
-
serializedHTML = stringReplace(serializedHTML, expr, ' ');
|
|
1862
|
-
});
|
|
1863
|
-
}
|
|
1864
|
-
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
|
|
1865
|
-
};
|
|
1866
|
-
/**
|
|
1867
|
-
* Public method to set the configuration once
|
|
1868
|
-
* setConfig
|
|
1869
|
-
*
|
|
1870
|
-
* @param {Object} cfg configuration object
|
|
1871
|
-
*/ DOMPurify.setConfig = function() {
|
|
1872
|
-
let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1873
|
-
_parseConfig(cfg);
|
|
1874
|
-
SET_CONFIG = true;
|
|
1875
|
-
};
|
|
1876
|
-
/**
|
|
1877
|
-
* Public method to remove the configuration
|
|
1878
|
-
* clearConfig
|
|
1879
|
-
*
|
|
1880
|
-
*/ DOMPurify.clearConfig = function() {
|
|
1881
|
-
CONFIG = null;
|
|
1882
|
-
SET_CONFIG = false;
|
|
1883
|
-
};
|
|
1884
|
-
/**
|
|
1885
|
-
* Public method to check if an attribute value is valid.
|
|
1886
|
-
* Uses last set config, if any. Otherwise, uses config defaults.
|
|
1887
|
-
* isValidAttribute
|
|
1888
|
-
*
|
|
1889
|
-
* @param {String} tag Tag name of containing element.
|
|
1890
|
-
* @param {String} attr Attribute name.
|
|
1891
|
-
* @param {String} value Attribute value.
|
|
1892
|
-
* @return {Boolean} Returns true if `value` is valid. Otherwise, returns false.
|
|
1893
|
-
*/ DOMPurify.isValidAttribute = function(tag, attr, value) {
|
|
1894
|
-
/* Initialize shared config vars if necessary. */ if (!CONFIG) {
|
|
1895
|
-
_parseConfig({});
|
|
1896
|
-
}
|
|
1897
|
-
const lcTag = transformCaseFunc(tag);
|
|
1898
|
-
const lcName = transformCaseFunc(attr);
|
|
1899
|
-
return _isValidAttribute(lcTag, lcName, value);
|
|
1900
|
-
};
|
|
1901
|
-
/**
|
|
1902
|
-
* AddHook
|
|
1903
|
-
* Public method to add DOMPurify hooks
|
|
1904
|
-
*
|
|
1905
|
-
* @param {String} entryPoint entry point for the hook to add
|
|
1906
|
-
* @param {Function} hookFunction function to execute
|
|
1907
|
-
*/ DOMPurify.addHook = function(entryPoint, hookFunction) {
|
|
1908
|
-
if (typeof hookFunction !== 'function') {
|
|
1909
|
-
return;
|
|
1910
|
-
}
|
|
1911
|
-
hooks[entryPoint] = hooks[entryPoint] || [];
|
|
1912
|
-
arrayPush(hooks[entryPoint], hookFunction);
|
|
1913
|
-
};
|
|
1914
|
-
/**
|
|
1915
|
-
* RemoveHook
|
|
1916
|
-
* Public method to remove a DOMPurify hook at a given entryPoint
|
|
1917
|
-
* (pops it from the stack of hooks if more are present)
|
|
1918
|
-
*
|
|
1919
|
-
* @param {String} entryPoint entry point for the hook to remove
|
|
1920
|
-
* @return {Function} removed(popped) hook
|
|
1921
|
-
*/ DOMPurify.removeHook = function(entryPoint) {
|
|
1922
|
-
if (hooks[entryPoint]) {
|
|
1923
|
-
return arrayPop(hooks[entryPoint]);
|
|
1924
|
-
}
|
|
1925
|
-
};
|
|
1926
|
-
/**
|
|
1927
|
-
* RemoveHooks
|
|
1928
|
-
* Public method to remove all DOMPurify hooks at a given entryPoint
|
|
1929
|
-
*
|
|
1930
|
-
* @param {String} entryPoint entry point for the hooks to remove
|
|
1931
|
-
*/ DOMPurify.removeHooks = function(entryPoint) {
|
|
1932
|
-
if (hooks[entryPoint]) {
|
|
1933
|
-
hooks[entryPoint] = [];
|
|
1934
|
-
}
|
|
1935
|
-
};
|
|
1936
|
-
/**
|
|
1937
|
-
* RemoveAllHooks
|
|
1938
|
-
* Public method to remove all DOMPurify hooks
|
|
1939
|
-
*/ DOMPurify.removeAllHooks = function() {
|
|
1940
|
-
hooks = {};
|
|
1941
|
-
};
|
|
1942
|
-
return DOMPurify;
|
|
969
|
+
currentNode.textContent = content;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
/* Execute a hook if present */
|
|
973
|
+
_executeHooks(hooks.afterSanitizeElements, currentNode, null);
|
|
974
|
+
return false;
|
|
975
|
+
};
|
|
976
|
+
/**
|
|
977
|
+
* _isValidAttribute
|
|
978
|
+
*
|
|
979
|
+
* @param lcTag Lowercase tag name of containing element.
|
|
980
|
+
* @param lcName Lowercase attribute name.
|
|
981
|
+
* @param value Attribute value.
|
|
982
|
+
* @return Returns true if `value` is valid, otherwise false.
|
|
983
|
+
*/
|
|
984
|
+
// eslint-disable-next-line complexity
|
|
985
|
+
const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
|
|
986
|
+
/* Make sure attribute cannot clobber */
|
|
987
|
+
if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
|
|
988
|
+
return false;
|
|
989
|
+
}
|
|
990
|
+
/* Allow valid data-* attributes: At least one character after "-"
|
|
991
|
+
(https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
|
|
992
|
+
XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
|
|
993
|
+
We don't need to check the value; it's always URI safe. */
|
|
994
|
+
if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
|
|
995
|
+
if (
|
|
996
|
+
// First condition does a very basic check if a) it's basically a valid custom element tagname AND
|
|
997
|
+
// b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
|
998
|
+
// and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
|
|
999
|
+
_isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName)) ||
|
|
1000
|
+
// Alternative, second condition checks if it's an `is`-attribute, AND
|
|
1001
|
+
// the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
|
1002
|
+
lcName === 'is' && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))) ; else {
|
|
1003
|
+
return false;
|
|
1004
|
+
}
|
|
1005
|
+
/* Check value is safe. First, is attr inert? If so, is safe */
|
|
1006
|
+
} else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if (value) {
|
|
1007
|
+
return false;
|
|
1008
|
+
} else ;
|
|
1009
|
+
return true;
|
|
1010
|
+
};
|
|
1011
|
+
/**
|
|
1012
|
+
* _isBasicCustomElement
|
|
1013
|
+
* checks if at least one dash is included in tagName, and it's not the first char
|
|
1014
|
+
* for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
|
|
1015
|
+
*
|
|
1016
|
+
* @param tagName name of the tag of the node to sanitize
|
|
1017
|
+
* @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
|
|
1018
|
+
*/
|
|
1019
|
+
const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
|
|
1020
|
+
return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);
|
|
1021
|
+
};
|
|
1022
|
+
/**
|
|
1023
|
+
* _sanitizeAttributes
|
|
1024
|
+
*
|
|
1025
|
+
* @protect attributes
|
|
1026
|
+
* @protect nodeName
|
|
1027
|
+
* @protect removeAttribute
|
|
1028
|
+
* @protect setAttribute
|
|
1029
|
+
*
|
|
1030
|
+
* @param currentNode to sanitize
|
|
1031
|
+
*/
|
|
1032
|
+
const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
|
|
1033
|
+
/* Execute a hook if present */
|
|
1034
|
+
_executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
|
|
1035
|
+
const {
|
|
1036
|
+
attributes
|
|
1037
|
+
} = currentNode;
|
|
1038
|
+
/* Check if we have attributes; if not we might have a text node */
|
|
1039
|
+
if (!attributes || _isClobbered(currentNode)) {
|
|
1040
|
+
return;
|
|
1041
|
+
}
|
|
1042
|
+
const hookEvent = {
|
|
1043
|
+
attrName: '',
|
|
1044
|
+
attrValue: '',
|
|
1045
|
+
keepAttr: true,
|
|
1046
|
+
allowedAttributes: ALLOWED_ATTR,
|
|
1047
|
+
forceKeepAttr: undefined
|
|
1048
|
+
};
|
|
1049
|
+
let l = attributes.length;
|
|
1050
|
+
/* Go backwards over all attributes; safely remove bad ones */
|
|
1051
|
+
while (l--) {
|
|
1052
|
+
const attr = attributes[l];
|
|
1053
|
+
const {
|
|
1054
|
+
name,
|
|
1055
|
+
namespaceURI,
|
|
1056
|
+
value: attrValue
|
|
1057
|
+
} = attr;
|
|
1058
|
+
const lcName = transformCaseFunc(name);
|
|
1059
|
+
let value = name === 'value' ? attrValue : stringTrim(attrValue);
|
|
1060
|
+
/* Execute a hook if present */
|
|
1061
|
+
hookEvent.attrName = lcName;
|
|
1062
|
+
hookEvent.attrValue = value;
|
|
1063
|
+
hookEvent.keepAttr = true;
|
|
1064
|
+
hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
|
|
1065
|
+
_executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);
|
|
1066
|
+
value = hookEvent.attrValue;
|
|
1067
|
+
/* Full DOM Clobbering protection via namespace isolation,
|
|
1068
|
+
* Prefix id and name attributes with `user-content-`
|
|
1069
|
+
*/
|
|
1070
|
+
if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
|
|
1071
|
+
// Remove the attribute with this value
|
|
1072
|
+
_removeAttribute(name, currentNode);
|
|
1073
|
+
// Prefix the value and later re-create the attribute with the sanitized value
|
|
1074
|
+
value = SANITIZE_NAMED_PROPS_PREFIX + value;
|
|
1075
|
+
}
|
|
1076
|
+
/* Work around a security issue with comments inside attributes */
|
|
1077
|
+
if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title)/i, value)) {
|
|
1078
|
+
_removeAttribute(name, currentNode);
|
|
1079
|
+
continue;
|
|
1080
|
+
}
|
|
1081
|
+
/* Did the hooks approve of the attribute? */
|
|
1082
|
+
if (hookEvent.forceKeepAttr) {
|
|
1083
|
+
continue;
|
|
1084
|
+
}
|
|
1085
|
+
/* Remove attribute */
|
|
1086
|
+
_removeAttribute(name, currentNode);
|
|
1087
|
+
/* Did the hooks approve of the attribute? */
|
|
1088
|
+
if (!hookEvent.keepAttr) {
|
|
1089
|
+
continue;
|
|
1090
|
+
}
|
|
1091
|
+
/* Work around a security issue in jQuery 3.0 */
|
|
1092
|
+
if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
|
|
1093
|
+
_removeAttribute(name, currentNode);
|
|
1094
|
+
continue;
|
|
1095
|
+
}
|
|
1096
|
+
/* Sanitize attribute content to be template-safe */
|
|
1097
|
+
if (SAFE_FOR_TEMPLATES) {
|
|
1098
|
+
arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
|
|
1099
|
+
value = stringReplace(value, expr, ' ');
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
/* Is `value` valid for this attribute? */
|
|
1103
|
+
const lcTag = transformCaseFunc(currentNode.nodeName);
|
|
1104
|
+
if (!_isValidAttribute(lcTag, lcName, value)) {
|
|
1105
|
+
continue;
|
|
1106
|
+
}
|
|
1107
|
+
/* Handle attributes that require Trusted Types */
|
|
1108
|
+
if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
|
|
1109
|
+
if (namespaceURI) ; else {
|
|
1110
|
+
switch (trustedTypes.getAttributeType(lcTag, lcName)) {
|
|
1111
|
+
case 'TrustedHTML':
|
|
1112
|
+
{
|
|
1113
|
+
value = trustedTypesPolicy.createHTML(value);
|
|
1114
|
+
break;
|
|
1115
|
+
}
|
|
1116
|
+
case 'TrustedScriptURL':
|
|
1117
|
+
{
|
|
1118
|
+
value = trustedTypesPolicy.createScriptURL(value);
|
|
1119
|
+
break;
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
/* Handle invalid data-* attribute set by try-catching it */
|
|
1125
|
+
try {
|
|
1126
|
+
if (namespaceURI) {
|
|
1127
|
+
currentNode.setAttributeNS(namespaceURI, name, value);
|
|
1128
|
+
} else {
|
|
1129
|
+
/* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
|
|
1130
|
+
currentNode.setAttribute(name, value);
|
|
1943
1131
|
}
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
}
|
|
1949
|
-
|
|
1132
|
+
if (_isClobbered(currentNode)) {
|
|
1133
|
+
_forceRemove(currentNode);
|
|
1134
|
+
} else {
|
|
1135
|
+
arrayPop(DOMPurify.removed);
|
|
1136
|
+
}
|
|
1137
|
+
} catch (_) {}
|
|
1138
|
+
}
|
|
1139
|
+
/* Execute a hook if present */
|
|
1140
|
+
_executeHooks(hooks.afterSanitizeAttributes, currentNode, null);
|
|
1141
|
+
};
|
|
1142
|
+
/**
|
|
1143
|
+
* _sanitizeShadowDOM
|
|
1144
|
+
*
|
|
1145
|
+
* @param fragment to iterate over recursively
|
|
1146
|
+
*/
|
|
1147
|
+
const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
|
|
1148
|
+
let shadowNode = null;
|
|
1149
|
+
const shadowIterator = _createNodeIterator(fragment);
|
|
1150
|
+
/* Execute a hook if present */
|
|
1151
|
+
_executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
|
|
1152
|
+
while (shadowNode = shadowIterator.nextNode()) {
|
|
1153
|
+
/* Execute a hook if present */
|
|
1154
|
+
_executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
|
|
1155
|
+
/* Sanitize tags and elements */
|
|
1156
|
+
_sanitizeElements(shadowNode);
|
|
1157
|
+
/* Check attributes next */
|
|
1158
|
+
_sanitizeAttributes(shadowNode);
|
|
1159
|
+
/* Deep shadow DOM detected */
|
|
1160
|
+
if (shadowNode.content instanceof DocumentFragment) {
|
|
1161
|
+
_sanitizeShadowDOM(shadowNode.content);
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
/* Execute a hook if present */
|
|
1165
|
+
_executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
|
|
1166
|
+
};
|
|
1167
|
+
// eslint-disable-next-line complexity
|
|
1168
|
+
DOMPurify.sanitize = function (dirty) {
|
|
1169
|
+
let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1170
|
+
let body = null;
|
|
1171
|
+
let importedNode = null;
|
|
1172
|
+
let currentNode = null;
|
|
1173
|
+
let returnNode = null;
|
|
1174
|
+
/* Make sure we have a string to sanitize.
|
|
1175
|
+
DO NOT return early, as this will return the wrong type if
|
|
1176
|
+
the user has requested a DOM object rather than a string */
|
|
1177
|
+
IS_EMPTY_INPUT = !dirty;
|
|
1178
|
+
if (IS_EMPTY_INPUT) {
|
|
1179
|
+
dirty = '<!-->';
|
|
1180
|
+
}
|
|
1181
|
+
/* Stringify, in case dirty is an object */
|
|
1182
|
+
if (typeof dirty !== 'string' && !_isNode(dirty)) {
|
|
1183
|
+
if (typeof dirty.toString === 'function') {
|
|
1184
|
+
dirty = dirty.toString();
|
|
1185
|
+
if (typeof dirty !== 'string') {
|
|
1186
|
+
throw typeErrorCreate('dirty is not a string, aborting');
|
|
1187
|
+
}
|
|
1188
|
+
} else {
|
|
1189
|
+
throw typeErrorCreate('toString is not a function');
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
/* Return dirty HTML if DOMPurify cannot run */
|
|
1193
|
+
if (!DOMPurify.isSupported) {
|
|
1194
|
+
return dirty;
|
|
1195
|
+
}
|
|
1196
|
+
/* Assign config vars */
|
|
1197
|
+
if (!SET_CONFIG) {
|
|
1198
|
+
_parseConfig(cfg);
|
|
1199
|
+
}
|
|
1200
|
+
/* Clean up removed elements */
|
|
1201
|
+
DOMPurify.removed = [];
|
|
1202
|
+
/* Check if dirty is correctly typed for IN_PLACE */
|
|
1203
|
+
if (typeof dirty === 'string') {
|
|
1204
|
+
IN_PLACE = false;
|
|
1205
|
+
}
|
|
1206
|
+
if (IN_PLACE) {
|
|
1207
|
+
/* Do some early pre-sanitization to avoid unsafe root nodes */
|
|
1208
|
+
if (dirty.nodeName) {
|
|
1209
|
+
const tagName = transformCaseFunc(dirty.nodeName);
|
|
1210
|
+
if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
|
|
1211
|
+
throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
} else if (dirty instanceof Node) {
|
|
1215
|
+
/* If dirty is a DOM element, append to an empty document to avoid
|
|
1216
|
+
elements being stripped by the parser */
|
|
1217
|
+
body = _initDocument('<!---->');
|
|
1218
|
+
importedNode = body.ownerDocument.importNode(dirty, true);
|
|
1219
|
+
if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === 'BODY') {
|
|
1220
|
+
/* Node is already a body, use as is */
|
|
1221
|
+
body = importedNode;
|
|
1222
|
+
} else if (importedNode.nodeName === 'HTML') {
|
|
1223
|
+
body = importedNode;
|
|
1224
|
+
} else {
|
|
1225
|
+
// eslint-disable-next-line unicorn/prefer-dom-node-append
|
|
1226
|
+
body.appendChild(importedNode);
|
|
1227
|
+
}
|
|
1228
|
+
} else {
|
|
1229
|
+
/* Exit directly if we have nothing to do */
|
|
1230
|
+
if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
|
|
1231
|
+
// eslint-disable-next-line unicorn/prefer-includes
|
|
1232
|
+
dirty.indexOf('<') === -1) {
|
|
1233
|
+
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
|
|
1234
|
+
}
|
|
1235
|
+
/* Initialize the document to work on */
|
|
1236
|
+
body = _initDocument(dirty);
|
|
1237
|
+
/* Check we have a DOM node from the data */
|
|
1238
|
+
if (!body) {
|
|
1239
|
+
return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
/* Remove first element node (ours) if FORCE_BODY is set */
|
|
1243
|
+
if (body && FORCE_BODY) {
|
|
1244
|
+
_forceRemove(body.firstChild);
|
|
1245
|
+
}
|
|
1246
|
+
/* Get node iterator */
|
|
1247
|
+
const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
|
|
1248
|
+
/* Now start iterating over the created document */
|
|
1249
|
+
while (currentNode = nodeIterator.nextNode()) {
|
|
1250
|
+
/* Sanitize tags and elements */
|
|
1251
|
+
_sanitizeElements(currentNode);
|
|
1252
|
+
/* Check attributes next */
|
|
1253
|
+
_sanitizeAttributes(currentNode);
|
|
1254
|
+
/* Shadow DOM detected, sanitize it */
|
|
1255
|
+
if (currentNode.content instanceof DocumentFragment) {
|
|
1256
|
+
_sanitizeShadowDOM(currentNode.content);
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
/* If we sanitized `dirty` in-place, return it. */
|
|
1260
|
+
if (IN_PLACE) {
|
|
1261
|
+
return dirty;
|
|
1262
|
+
}
|
|
1263
|
+
/* Return sanitized string or DOM */
|
|
1264
|
+
if (RETURN_DOM) {
|
|
1265
|
+
if (RETURN_DOM_FRAGMENT) {
|
|
1266
|
+
returnNode = createDocumentFragment.call(body.ownerDocument);
|
|
1267
|
+
while (body.firstChild) {
|
|
1268
|
+
// eslint-disable-next-line unicorn/prefer-dom-node-append
|
|
1269
|
+
returnNode.appendChild(body.firstChild);
|
|
1270
|
+
}
|
|
1271
|
+
} else {
|
|
1272
|
+
returnNode = body;
|
|
1273
|
+
}
|
|
1274
|
+
if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
|
|
1275
|
+
/*
|
|
1276
|
+
AdoptNode() is not used because internal state is not reset
|
|
1277
|
+
(e.g. the past names map of a HTMLFormElement), this is safe
|
|
1278
|
+
in theory but we would rather not risk another attack vector.
|
|
1279
|
+
The state that is cloned by importNode() is explicitly defined
|
|
1280
|
+
by the specs.
|
|
1281
|
+
*/
|
|
1282
|
+
returnNode = importNode.call(originalDocument, returnNode, true);
|
|
1283
|
+
}
|
|
1284
|
+
return returnNode;
|
|
1285
|
+
}
|
|
1286
|
+
let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
|
|
1287
|
+
/* Serialize doctype if allowed */
|
|
1288
|
+
if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
|
|
1289
|
+
serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
|
|
1290
|
+
}
|
|
1291
|
+
/* Sanitize final string template-safe */
|
|
1292
|
+
if (SAFE_FOR_TEMPLATES) {
|
|
1293
|
+
arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
|
|
1294
|
+
serializedHTML = stringReplace(serializedHTML, expr, ' ');
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1297
|
+
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
|
|
1298
|
+
};
|
|
1299
|
+
DOMPurify.setConfig = function () {
|
|
1300
|
+
let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1301
|
+
_parseConfig(cfg);
|
|
1302
|
+
SET_CONFIG = true;
|
|
1303
|
+
};
|
|
1304
|
+
DOMPurify.clearConfig = function () {
|
|
1305
|
+
CONFIG = null;
|
|
1306
|
+
SET_CONFIG = false;
|
|
1307
|
+
};
|
|
1308
|
+
DOMPurify.isValidAttribute = function (tag, attr, value) {
|
|
1309
|
+
/* Initialize shared config vars if necessary. */
|
|
1310
|
+
if (!CONFIG) {
|
|
1311
|
+
_parseConfig({});
|
|
1312
|
+
}
|
|
1313
|
+
const lcTag = transformCaseFunc(tag);
|
|
1314
|
+
const lcName = transformCaseFunc(attr);
|
|
1315
|
+
return _isValidAttribute(lcTag, lcName, value);
|
|
1316
|
+
};
|
|
1317
|
+
DOMPurify.addHook = function (entryPoint, hookFunction) {
|
|
1318
|
+
if (typeof hookFunction !== 'function') {
|
|
1319
|
+
return;
|
|
1320
|
+
}
|
|
1321
|
+
arrayPush(hooks[entryPoint], hookFunction);
|
|
1322
|
+
};
|
|
1323
|
+
DOMPurify.removeHook = function (entryPoint) {
|
|
1324
|
+
return arrayPop(hooks[entryPoint]);
|
|
1325
|
+
};
|
|
1326
|
+
DOMPurify.removeHooks = function (entryPoint) {
|
|
1327
|
+
hooks[entryPoint] = [];
|
|
1328
|
+
};
|
|
1329
|
+
DOMPurify.removeAllHooks = function () {
|
|
1330
|
+
hooks = _createHooksMap();
|
|
1331
|
+
};
|
|
1332
|
+
return DOMPurify;
|
|
1333
|
+
}
|
|
1334
|
+
var purify = createDOMPurify();
|
|
1950
1335
|
|
|
1951
1336
|
/**
|
|
1952
1337
|
* This class represents all the constants needed in a MathType integration among different classes.
|
|
@@ -2266,6 +1651,19 @@ var purifyExports = purify.exports;
|
|
|
2266
1651
|
return mathml.replace(semanticsStartingTagRegex, "").replace(semanticsEndingTagRegex, "");
|
|
2267
1652
|
}
|
|
2268
1653
|
/**
|
|
1654
|
+
* Removes semantics tag to element that contains mathml.
|
|
1655
|
+
* When using Hand to create formulas, it adds the mrow tag due to the semantics one, this one is also removed.
|
|
1656
|
+
* @param {string} element - Inner HTML text string.
|
|
1657
|
+
* @returns {string} - 'mathml' without semantics tag.
|
|
1658
|
+
*/ static removeSafeXMLSemantics(element) {
|
|
1659
|
+
// If `mrow` is found right before the `semantics` starting tag, it's removed as well
|
|
1660
|
+
const semanticsSafeStartingTagRegex = /«semantics»\s*?(«mrow»)?/gm;
|
|
1661
|
+
// If `mrow` is found right after the `annotation` ending tag, it's removed as well
|
|
1662
|
+
// alongside `semantics` closing tag and the whole `annotation` tag and its contents.
|
|
1663
|
+
const semanticsSafeEndingTagRegex = /(«\/mrow»)?\s*«annotation[\W\w]*?«\/semantics»/gm;
|
|
1664
|
+
return element.replace(semanticsSafeStartingTagRegex, "").replace(semanticsSafeEndingTagRegex, "");
|
|
1665
|
+
}
|
|
1666
|
+
/**
|
|
2269
1667
|
* Transforms all xml mathml occurrences that contain semantics to the same
|
|
2270
1668
|
* xml mathml occurrences without semantics.
|
|
2271
1669
|
* @param {string} text - string that can contain xml mathml occurrences.
|
|
@@ -3588,6 +2986,9 @@ var ko = {
|
|
|
3588
2986
|
var nl = {
|
|
3589
2987
|
latex: "LaTeX",
|
|
3590
2988
|
cancel: "Annuleren",
|
|
2989
|
+
accept: "Invoegen",
|
|
2990
|
+
manual: "Handmatig",
|
|
2991
|
+
insert_math: "Een wiskundige vergelijking invoegen - MathType",
|
|
3591
2992
|
insert_chem: "Een scheikundige formule invoegen - ChemType",
|
|
3592
2993
|
minimize: "Minimaliseer",
|
|
3593
2994
|
maximize: "Maximaliseer",
|
|
@@ -4345,7 +3746,7 @@ var translations = {
|
|
|
4345
3746
|
// Get all the annotation content including the tags.
|
|
4346
3747
|
let annotation = html.match(annotationRegex);
|
|
4347
3748
|
// Sanitize html code without removing our supported MathML tags and attributes.
|
|
4348
|
-
html =
|
|
3749
|
+
html = purify.sanitize(html, {
|
|
4349
3750
|
ADD_TAGS: [
|
|
4350
3751
|
"semantics",
|
|
4351
3752
|
"annotation",
|
|
@@ -5517,12 +4918,14 @@ var translations = {
|
|
|
5517
4918
|
* @param {string} code - HTML code to be parsed
|
|
5518
4919
|
* @returns {string} HTML code parsed.
|
|
5519
4920
|
*/ static endParseSaveMode(code) {
|
|
5520
|
-
|
|
5521
|
-
|
|
4921
|
+
const savemode = Configuration.get("saveMode");
|
|
4922
|
+
const base64savemode = Configuration.get("base64savemode");
|
|
4923
|
+
if (savemode) {
|
|
4924
|
+
if (savemode === "safeXml") {
|
|
5522
4925
|
code = Parser.codeImgTransform(code, "img2mathml");
|
|
5523
|
-
} else if (
|
|
4926
|
+
} else if (savemode === "xml") {
|
|
5524
4927
|
code = Parser.codeImgTransform(code, "img2mathml");
|
|
5525
|
-
} else if (
|
|
4928
|
+
} else if (savemode === "base64" && base64savemode === "image") {
|
|
5526
4929
|
code = Parser.codeImgTransform(code, "img264");
|
|
5527
4930
|
}
|
|
5528
4931
|
}
|
|
@@ -7679,7 +7082,7 @@ var maxHoverIcon = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>
|
|
|
7679
7082
|
const isIOS = ContentManager.isIOS();
|
|
7680
7083
|
this.iosSoftkeyboardOpened = false;
|
|
7681
7084
|
this.iosMeasureUnit = ua.indexOf("crios") === -1 ? "%" : "vh";
|
|
7682
|
-
this.iosDivHeight = `
|
|
7085
|
+
this.iosDivHeight = `auto`;
|
|
7683
7086
|
const deviceWidth = window.outerWidth;
|
|
7684
7087
|
const deviceHeight = window.outerHeight;
|
|
7685
7088
|
const landscape = deviceWidth > deviceHeight;
|
|
@@ -8094,7 +7497,6 @@ var maxHoverIcon = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>
|
|
|
8094
7497
|
// iOS keyboard is a float div which can overlay the modal object.
|
|
8095
7498
|
if (this.deviceProperties.isIOS) {
|
|
8096
7499
|
this.iosSoftkeyboardOpened = false;
|
|
8097
|
-
this.setContainerHeight(`${100 + this.iosMeasureUnit}`);
|
|
8098
7500
|
}
|
|
8099
7501
|
}
|
|
8100
7502
|
if (!ContentManager.isEditorLoaded()) {
|
|
@@ -8471,8 +7873,6 @@ var maxHoverIcon = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>
|
|
|
8471
7873
|
/**
|
|
8472
7874
|
* Sets the modal dialog initial size.
|
|
8473
7875
|
*/ recalculateSize() {
|
|
8474
|
-
this.wrapper.style.width = `${this.container.clientWidth - 12}px`;
|
|
8475
|
-
this.wrapper.style.height = `${this.container.clientHeight - 38}px`;
|
|
8476
7876
|
this.contentContainer.style.height = `${parseInt(this.wrapper.offsetHeight - 50, 10)}px`;
|
|
8477
7877
|
}
|
|
8478
7878
|
/**
|
|
@@ -8877,38 +8277,39 @@ var maxHoverIcon = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>
|
|
|
8877
8277
|
/**
|
|
8878
8278
|
* Event handler that change container size when IOS soft keyboard is opened.
|
|
8879
8279
|
*/ handleOpenedIosSoftkeyboard() {
|
|
8880
|
-
if (!this.iosSoftkeyboardOpened && this.iosDivHeight != null && this.iosDivHeight === `
|
|
8280
|
+
if (!this.iosSoftkeyboardOpened && this.iosDivHeight != null && this.iosDivHeight === `auto`) {
|
|
8881
8281
|
if (this.portraitMode()) {
|
|
8882
|
-
this.setContainerHeight(`
|
|
8282
|
+
this.setContainerHeight(`60${this.iosMeasureUnit}`);
|
|
8883
8283
|
} else {
|
|
8884
|
-
this.setContainerHeight(`
|
|
8284
|
+
this.setContainerHeight(`35${this.iosMeasureUnit}`);
|
|
8885
8285
|
}
|
|
8886
8286
|
}
|
|
8887
8287
|
this.iosSoftkeyboardOpened = true;
|
|
8288
|
+
this.wrapper.style.flexGrow = "1";
|
|
8888
8289
|
}
|
|
8889
8290
|
/**
|
|
8890
8291
|
* Event handler that change container size when IOS soft keyboard is closed.
|
|
8891
8292
|
*/ handleClosedIosSoftkeyboard() {
|
|
8892
8293
|
this.iosSoftkeyboardOpened = false;
|
|
8893
|
-
this.
|
|
8294
|
+
this.wrapper.style.flexGrow = "1";
|
|
8894
8295
|
}
|
|
8895
8296
|
/**
|
|
8896
8297
|
* Change container sizes when orientation is changed on iOS.
|
|
8897
8298
|
*/ orientationChangeIosSoftkeyboard() {
|
|
8898
8299
|
if (this.iosSoftkeyboardOpened) {
|
|
8899
8300
|
if (this.portraitMode()) {
|
|
8900
|
-
this.setContainerHeight(`
|
|
8301
|
+
this.setContainerHeight(`65${this.iosMeasureUnit}`);
|
|
8901
8302
|
} else {
|
|
8902
|
-
this.setContainerHeight(`
|
|
8303
|
+
this.setContainerHeight(`45${this.iosMeasureUnit}`);
|
|
8903
8304
|
}
|
|
8904
8305
|
} else {
|
|
8905
|
-
this.
|
|
8306
|
+
this.wrapper.style.flexGrow = "1";
|
|
8906
8307
|
}
|
|
8907
8308
|
}
|
|
8908
8309
|
/**
|
|
8909
8310
|
* Change container sizes when orientation is changed on Android.
|
|
8910
8311
|
*/ orientationChangeAndroidSoftkeyboard() {
|
|
8911
|
-
this.
|
|
8312
|
+
this.wrapper.style.flexGrow = "1";
|
|
8912
8313
|
}
|
|
8913
8314
|
/**
|
|
8914
8315
|
* Set iframe container height.
|
|
@@ -10769,7 +10170,7 @@ var mathIcon = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!-- Generator: Adob
|
|
|
10769
10170
|
var chemIcon = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!-- Generator: Adobe Illustrator 22.0.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->\n<svg version=\"1.1\" id=\"Layer_1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\"\n\t viewBox=\"0 0 40.3 49.5\" style=\"enable-background:new 0 0 40.3 49.5;\" xml:space=\"preserve\">\n<style type=\"text/css\">\n\t.st0{fill:#A4CF61;}\n</style>\n<path class=\"st0\" d=\"M39.2,12.1c0-1.9-1.1-3.6-2.7-4.4L24.5,0.9l0,0c-0.7-0.4-1.5-0.6-2.4-0.6c-0.9,0-1.7,0.2-2.4,0.6l0,0L2.3,10.8\n\tl0,0C0.9,11.7,0,13.2,0,14.9h0v19.6h0c0,1.7,0.9,3.3,2.3,4.1l0,0l17.4,9.9l0,0c0.7,0.4,1.5,0.6,2.4,0.6c0.9,0,1.7-0.2,2.4-0.6l0,0\n\tl12.2-6.9h0c1.5-0.8,2.6-2.5,2.6-4.3c0-2.7-2.2-4.9-4.9-4.9c-0.9,0-1.8,0.3-2.5,0.7l0,0l-9.7,5.6l-12.3-7V17.8l12.3-7l9.9,5.7l0,0\n\tc0.7,0.4,1.5,0.6,2.4,0.6C37,17,39.2,14.8,39.2,12.1\"/>\n</svg>\n";
|
|
10770
10171
|
|
|
10771
10172
|
var name = "@wiris/mathtype-ckeditor5";
|
|
10772
|
-
var version = "8.
|
|
10173
|
+
var version = "8.12.0";
|
|
10773
10174
|
var description = "MathType Web for CKEditor5 editor";
|
|
10774
10175
|
var keywords = [
|
|
10775
10176
|
"chem",
|
|
@@ -10786,7 +10187,7 @@ var keywords = [
|
|
|
10786
10187
|
"mathtype",
|
|
10787
10188
|
"wiris"
|
|
10788
10189
|
];
|
|
10789
|
-
var repository = "https://github.com/wiris/html-integrations/tree/
|
|
10190
|
+
var repository = "https://github.com/wiris/html-integrations/tree/master/packages/ckeditor5";
|
|
10790
10191
|
var homepage = "https://www.wiris.com/";
|
|
10791
10192
|
var bugs = {
|
|
10792
10193
|
email: "support@wiris.com"
|
|
@@ -10816,7 +10217,7 @@ var scripts = {
|
|
|
10816
10217
|
prepare: "npm run build:dist"
|
|
10817
10218
|
};
|
|
10818
10219
|
var dependencies = {
|
|
10819
|
-
"@wiris/mathtype-html-integration-devkit": "1.17.
|
|
10220
|
+
"@wiris/mathtype-html-integration-devkit": "1.17.6"
|
|
10820
10221
|
};
|
|
10821
10222
|
var devDependencies = {
|
|
10822
10223
|
"@ckeditor/ckeditor5-dev-build-tools": "^42.1.0",
|
|
@@ -10899,7 +10300,7 @@ class MathType extends Plugin {
|
|
|
10899
10300
|
integrationProperties.managesLanguage = true;
|
|
10900
10301
|
// etc
|
|
10901
10302
|
// There are platforms like Drupal that initialize CKEditor but they hide or remove the container element.
|
|
10902
|
-
// To avoid a wrong
|
|
10303
|
+
// To avoid a wrong behavior, this integration only starts if the workspace container exists.
|
|
10903
10304
|
let integration;
|
|
10904
10305
|
if (integrationProperties.target) {
|
|
10905
10306
|
// Instance of the integration associated to this editor instance
|
|
@@ -10985,7 +10386,8 @@ class MathType extends Plugin {
|
|
|
10985
10386
|
schema.register("mathml", {
|
|
10986
10387
|
inheritAllFrom: "$inlineObject",
|
|
10987
10388
|
allowAttributes: [
|
|
10988
|
-
"formula"
|
|
10389
|
+
"formula",
|
|
10390
|
+
"htmlContent"
|
|
10989
10391
|
]
|
|
10990
10392
|
});
|
|
10991
10393
|
}
|
|
@@ -11069,6 +10471,50 @@ class MathType extends Plugin {
|
|
|
11069
10471
|
data.modelCursor = data.modelRange.end;
|
|
11070
10472
|
}
|
|
11071
10473
|
});
|
|
10474
|
+
// Data view -> Model
|
|
10475
|
+
editor.data.upcastDispatcher.on("element:img", (evt, data, conversionApi)=>{
|
|
10476
|
+
const { consumable, writer } = conversionApi;
|
|
10477
|
+
const { viewItem } = data;
|
|
10478
|
+
// Only upcast when is wiris formula
|
|
10479
|
+
if (viewItem.getClassNames().next().value !== "Wirisformula") {
|
|
10480
|
+
return;
|
|
10481
|
+
}
|
|
10482
|
+
const mathAttributes = [
|
|
10483
|
+
...viewItem.getAttributes()
|
|
10484
|
+
].map(([key, value])=>` ${key}="${value}"`).join("");
|
|
10485
|
+
let htmlContent = Util.htmlSanitize(`<img${mathAttributes}>`);
|
|
10486
|
+
const modelNode = writer.createElement("mathml", {
|
|
10487
|
+
htmlContent
|
|
10488
|
+
});
|
|
10489
|
+
// Find allowed parent for element that we are going to insert.
|
|
10490
|
+
// If current parent does not allow to insert element but one of the ancestors does
|
|
10491
|
+
// then split nodes to allowed parent.
|
|
10492
|
+
const splitResult = conversionApi.splitToAllowedParent(modelNode, data.modelCursor);
|
|
10493
|
+
// When there is no split result it means that we can't insert element to model tree, so let's skip it.
|
|
10494
|
+
if (!splitResult) {
|
|
10495
|
+
return;
|
|
10496
|
+
}
|
|
10497
|
+
// Insert element on allowed position.
|
|
10498
|
+
conversionApi.writer.insert(modelNode, splitResult.position);
|
|
10499
|
+
// Consume appropriate value from consumable values list.
|
|
10500
|
+
consumable.consume(viewItem, {
|
|
10501
|
+
name: true
|
|
10502
|
+
});
|
|
10503
|
+
const parts = conversionApi.getSplitParts(modelNode);
|
|
10504
|
+
// Set conversion result range.
|
|
10505
|
+
data.modelRange = writer.createRange(conversionApi.writer.createPositionBefore(modelNode), conversionApi.writer.createPositionAfter(parts[parts.length - 1]));
|
|
10506
|
+
// Now we need to check where the `modelCursor` should be.
|
|
10507
|
+
if (splitResult.cursorParent) {
|
|
10508
|
+
// If we split parent to insert our element then we want to continue conversion in the new part of the split parent.
|
|
10509
|
+
//
|
|
10510
|
+
// before: <allowed><notAllowed>foo[]</notAllowed></allowed>
|
|
10511
|
+
// after: <allowed><notAllowed>foo</notAllowed><converted></converted><notAllowed>[]</notAllowed></allowed>
|
|
10512
|
+
data.modelCursor = conversionApi.writer.createPositionAt(splitResult.cursorParent, 0);
|
|
10513
|
+
} else {
|
|
10514
|
+
// Otherwise just continue after inserted element.
|
|
10515
|
+
data.modelCursor = data.modelRange.end;
|
|
10516
|
+
}
|
|
10517
|
+
});
|
|
11072
10518
|
/**
|
|
11073
10519
|
* Whether the given view <math> element has a LaTeX annotation element.
|
|
11074
10520
|
* @param {*} math
|
|
@@ -11097,12 +10543,25 @@ class MathType extends Plugin {
|
|
|
11097
10543
|
}
|
|
11098
10544
|
function createViewImage(modelItem, { writer: viewWriter }) {
|
|
11099
10545
|
const htmlDataProcessor = new HtmlDataProcessor(viewWriter.document);
|
|
11100
|
-
const
|
|
11101
|
-
const
|
|
11102
|
-
|
|
10546
|
+
const formula = modelItem.getAttribute("formula");
|
|
10547
|
+
const htmlContent = modelItem.getAttribute("htmlContent");
|
|
10548
|
+
if (!formula && !htmlContent) {
|
|
10549
|
+
return null;
|
|
10550
|
+
}
|
|
10551
|
+
let imgElement = null;
|
|
10552
|
+
if (htmlContent) {
|
|
10553
|
+
imgElement = htmlDataProcessor.toView(htmlContent).getChild(0);
|
|
10554
|
+
} else if (formula) {
|
|
10555
|
+
const mathString = formula.replaceAll('ref="<"', 'ref="<"');
|
|
10556
|
+
const imgHtml = Parser.initParse(mathString, integration.getLanguage());
|
|
10557
|
+
imgElement = htmlDataProcessor.toView(imgHtml).getChild(0);
|
|
10558
|
+
// Add HTML element (<img>) to model
|
|
10559
|
+
viewWriter.setAttribute("htmlContent", imgHtml, modelItem);
|
|
10560
|
+
}
|
|
11103
10561
|
/* Although we use the HtmlDataProcessor to obtain the attributes,
|
|
11104
|
-
|
|
11105
|
-
|
|
10562
|
+
* we must create a new EmptyElement which is independent of the
|
|
10563
|
+
* DataProcessor being used by this editor instance
|
|
10564
|
+
*/ if (imgElement) {
|
|
11106
10565
|
return viewWriter.createEmptyElement("img", imgElement.getAttributes(), {
|
|
11107
10566
|
renderUnsafeAttributes: [
|
|
11108
10567
|
"src"
|
|
@@ -11143,7 +10602,8 @@ class MathType extends Plugin {
|
|
|
11143
10602
|
}
|
|
11144
10603
|
function createDataString(modelItem, { writer: viewWriter }) {
|
|
11145
10604
|
const htmlDataProcessor = new HtmlDataProcessor(viewWriter.document);
|
|
11146
|
-
|
|
10605
|
+
// Load img element
|
|
10606
|
+
let mathString = modelItem.getAttribute("htmlContent") || Parser.endParseSaveMode(modelItem.getAttribute("formula"));
|
|
11147
10607
|
const sourceMathElement = htmlDataProcessor.toView(mathString).getChild(0);
|
|
11148
10608
|
return clone(viewWriter, sourceMathElement);
|
|
11149
10609
|
}
|
|
@@ -11155,36 +10615,40 @@ class MathType extends Plugin {
|
|
|
11155
10615
|
* Hack to transform $$latex$$ into <math> in editor.getData()'s output.
|
|
11156
10616
|
*/ editor.data.on("get", (e)=>{
|
|
11157
10617
|
let output = e.return;
|
|
11158
|
-
|
|
11159
|
-
//
|
|
11160
|
-
|
|
10618
|
+
const parsedResult = Parser.endParse(output);
|
|
10619
|
+
// Cleans all the semantics tag for safexml
|
|
10620
|
+
// including the handwritten data points
|
|
10621
|
+
e.return = MathML.removeSafeXMLSemantics(parsedResult);
|
|
11161
10622
|
}, {
|
|
11162
10623
|
priority: "low"
|
|
11163
10624
|
});
|
|
11164
10625
|
/**
|
|
11165
|
-
* Hack to transform <math> with LaTeX into $$LaTeX$$ in editor.setData().
|
|
10626
|
+
* Hack to transform <math> with LaTeX into $$LaTeX$$ and formula images in editor.setData().
|
|
11166
10627
|
*/ editor.data.on("set", (e, args)=>{
|
|
11167
10628
|
// Retrieve the data to be set on the CKEditor.
|
|
11168
10629
|
let modifiedData = args[0];
|
|
11169
10630
|
// Regex to find all mathml formulas.
|
|
11170
|
-
const regexp =
|
|
11171
|
-
|
|
11172
|
-
|
|
11173
|
-
//
|
|
11174
|
-
|
|
11175
|
-
|
|
11176
|
-
|
|
11177
|
-
|
|
11178
|
-
] : [
|
|
11179
|
-
...modifiedData.matchAll(regexp)
|
|
11180
|
-
];
|
|
11181
|
-
// Loop to find LaTeX formulas and replace the MathML for the LaTeX notation.
|
|
10631
|
+
const regexp = /(<img\b[^>]*>)|(<math(.*?)<\/math>)/gm;
|
|
10632
|
+
const formulas = [];
|
|
10633
|
+
let formula;
|
|
10634
|
+
// Both data.set from the source plugin and console command are taken into account as the data received is MathML or an image containing the MathML.
|
|
10635
|
+
while((formula = regexp.exec(modifiedData)) !== null){
|
|
10636
|
+
formulas.push(formula[0]);
|
|
10637
|
+
}
|
|
10638
|
+
// Loop to find LaTeX and formula images and replace the MathML for the both.
|
|
11182
10639
|
formulas.forEach((formula)=>{
|
|
11183
|
-
|
|
11184
|
-
if (mathml.includes('encoding="LaTeX"')) {
|
|
10640
|
+
if (formula.includes('encoding="LaTeX"')) {
|
|
11185
10641
|
// LaTeX found.
|
|
11186
|
-
let latex = "$$$" + Latex.getLatexFromMathML(
|
|
11187
|
-
modifiedData = modifiedData.replace(
|
|
10642
|
+
let latex = "$$$" + Latex.getLatexFromMathML(formula) + "$$$"; // We add $$$ instead of $$ because the replace function ignores one $.
|
|
10643
|
+
modifiedData = modifiedData.replace(formula, latex);
|
|
10644
|
+
} else if (formula.includes("<img")) {
|
|
10645
|
+
// If we found a formula image, we should find MathML data, and then substitute the entire image.
|
|
10646
|
+
const regexp = /«math\b[^»]*»(.*?)«\/math»/g;
|
|
10647
|
+
const safexml = formula.match(regexp);
|
|
10648
|
+
if (safexml !== null) {
|
|
10649
|
+
let decodeXML = MathML.safeXmlDecode(safexml[0]);
|
|
10650
|
+
modifiedData = modifiedData.replace(formula, decodeXML);
|
|
10651
|
+
}
|
|
11188
10652
|
}
|
|
11189
10653
|
});
|
|
11190
10654
|
args[0] = modifiedData;
|