dompurify 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -3
- package/dist/purify.cjs.js +148 -138
- package/dist/purify.cjs.js.map +1 -1
- package/dist/purify.es.js +148 -138
- package/dist/purify.es.js.map +1 -1
- package/dist/purify.js +148 -138
- package/dist/purify.js.map +1 -1
- package/dist/purify.min.js +1 -1
- package/dist/purify.min.js.map +1 -1
- package/package-lock.json +6620 -0
- package/package.json +9 -9
package/dist/purify.es.js
CHANGED
|
@@ -9,7 +9,7 @@ var mathMl = ['math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi',
|
|
|
9
9
|
|
|
10
10
|
var text = ['#text'];
|
|
11
11
|
|
|
12
|
-
var html$1 = ['accept', 'action', 'align', 'alt', 'autocomplete', 'background', 'bgcolor', 'border', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'coords', 'datetime', 'default', 'dir', 'disabled', 'download', 'enctype', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'ismap', 'label', 'lang', 'list', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'multiple', 'name', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'pattern', 'placeholder', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'span', 'srclang', 'start', 'src', 'step', 'style', 'summary', 'tabindex', 'title', 'type', 'usemap', 'valign', 'value', 'width', 'xmlns'];
|
|
12
|
+
var html$1 = ['accept', 'action', 'align', 'alt', 'autocomplete', 'background', 'bgcolor', 'border', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'coords', 'crossorigin', 'datetime', 'default', 'dir', 'disabled', 'download', 'enctype', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'integrity', 'ismap', 'label', 'lang', 'list', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'multiple', 'name', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'pattern', 'placeholder', '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', 'type', 'usemap', 'valign', 'value', 'width', 'xmlns'];
|
|
13
13
|
|
|
14
14
|
var svg$1 = ['accent-height', 'accumulate', 'additivive', 'alignment-baseline', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', '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', 'fill', 'fill-opacity', 'fill-rule', 'filter', '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', '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', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'specularconstant', 'specularexponent', 'spreadmethod', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'tabindex', 'targetx', 'targety', 'transform', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', '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'];
|
|
15
15
|
|
|
@@ -41,6 +41,14 @@ function clone(object) {
|
|
|
41
41
|
return newObject;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
var MUSTACHE_EXPR = /\{\{[\s\S]*|[\s\S]*\}\}/gm; // Specify template detection regex for SAFE_FOR_TEMPLATES mode
|
|
45
|
+
var ERB_EXPR = /<%[\s\S]*|[\s\S]*%>/gm;
|
|
46
|
+
var DATA_ATTR = /^data-[\-\w.\u00B7-\uFFFF]/; // eslint-disable-line no-useless-escape
|
|
47
|
+
var ARIA_ATTR = /^aria-[\-\w]+$/; // eslint-disable-line no-useless-escape
|
|
48
|
+
var IS_ALLOWED_URI = /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i; // eslint-disable-line no-useless-escape
|
|
49
|
+
var IS_SCRIPT_OR_DATA = /^(?:\w+script|data):/i;
|
|
50
|
+
var ATTR_WHITESPACE = /[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205f\u3000]/g; // This needs to be extensive thanks to Webkit/Blink's behavior
|
|
51
|
+
|
|
44
52
|
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
|
45
53
|
|
|
46
54
|
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
|
@@ -57,15 +65,15 @@ function createDOMPurify() {
|
|
|
57
65
|
};
|
|
58
66
|
|
|
59
67
|
/**
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
DOMPurify.version = '1.0.
|
|
68
|
+
* Version label, exposed for easier checks
|
|
69
|
+
* if DOMPurify is up to date or not
|
|
70
|
+
*/
|
|
71
|
+
DOMPurify.version = '1.0.3';
|
|
64
72
|
|
|
65
73
|
/**
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
74
|
+
* Array of elements that DOMPurify removed during sanitation.
|
|
75
|
+
* Empty if nothing was removed.
|
|
76
|
+
*/
|
|
69
77
|
DOMPurify.removed = [];
|
|
70
78
|
|
|
71
79
|
if (!window || !window.document || window.document.nodeType !== 9) {
|
|
@@ -120,14 +128,23 @@ function createDOMPurify() {
|
|
|
120
128
|
var hooks = {};
|
|
121
129
|
|
|
122
130
|
/**
|
|
123
|
-
|
|
124
|
-
|
|
131
|
+
* Expose whether this browser supports running the full DOMPurify.
|
|
132
|
+
*/
|
|
125
133
|
DOMPurify.isSupported = implementation && typeof implementation.createHTMLDocument !== 'undefined' && document.documentMode !== 9;
|
|
126
134
|
|
|
135
|
+
var MUSTACHE_EXPR$$1 = MUSTACHE_EXPR,
|
|
136
|
+
ERB_EXPR$$1 = ERB_EXPR,
|
|
137
|
+
DATA_ATTR$$1 = DATA_ATTR,
|
|
138
|
+
ARIA_ATTR$$1 = ARIA_ATTR,
|
|
139
|
+
IS_SCRIPT_OR_DATA$$1 = IS_SCRIPT_OR_DATA,
|
|
140
|
+
ATTR_WHITESPACE$$1 = ATTR_WHITESPACE;
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
var IS_ALLOWED_URI$$1 = IS_ALLOWED_URI;
|
|
127
144
|
/**
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
145
|
+
* We consider the elements and attributes below to be safe. Ideally
|
|
146
|
+
* don't add any new ones but feel free to remove unwanted ones.
|
|
147
|
+
*/
|
|
131
148
|
|
|
132
149
|
/* allowed element names */
|
|
133
150
|
var ALLOWED_TAGS = null;
|
|
@@ -160,10 +177,6 @@ function createDOMPurify() {
|
|
|
160
177
|
*/
|
|
161
178
|
var SAFE_FOR_TEMPLATES = false;
|
|
162
179
|
|
|
163
|
-
/* Specify template detection regex for SAFE_FOR_TEMPLATES mode */
|
|
164
|
-
var MUSTACHE_EXPR = /\{\{[\s\S]*|[\s\S]*\}\}/gm;
|
|
165
|
-
var ERB_EXPR = /<%[\s\S]*|[\s\S]*%>/gm;
|
|
166
|
-
|
|
167
180
|
/* Decide if document with <html>... should be returned */
|
|
168
181
|
var WHOLE_DOCUMENT = false;
|
|
169
182
|
|
|
@@ -215,17 +228,16 @@ function createDOMPurify() {
|
|
|
215
228
|
var formElement = document.createElement('form');
|
|
216
229
|
|
|
217
230
|
/**
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
231
|
+
* _parseConfig
|
|
232
|
+
*
|
|
233
|
+
* @param optional config literal
|
|
234
|
+
*/
|
|
222
235
|
// eslint-disable-next-line complexity
|
|
223
236
|
var _parseConfig = function _parseConfig(cfg) {
|
|
224
237
|
/* Shield configuration object from tampering */
|
|
225
238
|
if ((typeof cfg === 'undefined' ? 'undefined' : _typeof(cfg)) !== 'object') {
|
|
226
239
|
cfg = {};
|
|
227
240
|
}
|
|
228
|
-
|
|
229
241
|
/* Set configuration parameters */
|
|
230
242
|
ALLOWED_TAGS = 'ALLOWED_TAGS' in cfg ? addToSet({}, cfg.ALLOWED_TAGS) : DEFAULT_ALLOWED_TAGS;
|
|
231
243
|
ALLOWED_ATTR = 'ALLOWED_ATTR' in cfg ? addToSet({}, cfg.ALLOWED_ATTR) : DEFAULT_ALLOWED_ATTR;
|
|
@@ -245,6 +257,8 @@ function createDOMPurify() {
|
|
|
245
257
|
SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
|
|
246
258
|
KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
|
|
247
259
|
|
|
260
|
+
IS_ALLOWED_URI$$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI$$1;
|
|
261
|
+
|
|
248
262
|
if (SAFE_FOR_TEMPLATES) {
|
|
249
263
|
ALLOW_DATA_ATTR = false;
|
|
250
264
|
}
|
|
@@ -310,10 +324,10 @@ function createDOMPurify() {
|
|
|
310
324
|
};
|
|
311
325
|
|
|
312
326
|
/**
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
327
|
+
* _forceRemove
|
|
328
|
+
*
|
|
329
|
+
* @param a DOM node
|
|
330
|
+
*/
|
|
317
331
|
var _forceRemove = function _forceRemove(node) {
|
|
318
332
|
DOMPurify.removed.push({ element: node });
|
|
319
333
|
try {
|
|
@@ -324,11 +338,11 @@ function createDOMPurify() {
|
|
|
324
338
|
};
|
|
325
339
|
|
|
326
340
|
/**
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
341
|
+
* _removeAttribute
|
|
342
|
+
*
|
|
343
|
+
* @param an Attribute name
|
|
344
|
+
* @param a DOM node
|
|
345
|
+
*/
|
|
332
346
|
var _removeAttribute = function _removeAttribute(name, node) {
|
|
333
347
|
DOMPurify.removed.push({
|
|
334
348
|
attribute: node.getAttributeNode(name),
|
|
@@ -338,11 +352,11 @@ function createDOMPurify() {
|
|
|
338
352
|
};
|
|
339
353
|
|
|
340
354
|
/**
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
355
|
+
* _initDocument
|
|
356
|
+
*
|
|
357
|
+
* @param a string of dirty markup
|
|
358
|
+
* @return a DOM, filled with the dirty markup
|
|
359
|
+
*/
|
|
346
360
|
var _initDocument = function _initDocument(dirty) {
|
|
347
361
|
/* Create a HTML document */
|
|
348
362
|
var doc = void 0;
|
|
@@ -418,11 +432,11 @@ function createDOMPurify() {
|
|
|
418
432
|
}
|
|
419
433
|
|
|
420
434
|
/**
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
435
|
+
* _createIterator
|
|
436
|
+
*
|
|
437
|
+
* @param document/fragment to create iterator for
|
|
438
|
+
* @return iterator instance
|
|
439
|
+
*/
|
|
426
440
|
var _createIterator = function _createIterator(root) {
|
|
427
441
|
return createNodeIterator.call(root.ownerDocument || root, root, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT, function () {
|
|
428
442
|
return NodeFilter.FILTER_ACCEPT;
|
|
@@ -430,11 +444,11 @@ function createDOMPurify() {
|
|
|
430
444
|
};
|
|
431
445
|
|
|
432
446
|
/**
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
447
|
+
* _isClobbered
|
|
448
|
+
*
|
|
449
|
+
* @param element to check for clobbering attacks
|
|
450
|
+
* @return true if clobbered, false if safe
|
|
451
|
+
*/
|
|
438
452
|
var _isClobbered = function _isClobbered(elm) {
|
|
439
453
|
if (elm instanceof Text || elm instanceof Comment) {
|
|
440
454
|
return false;
|
|
@@ -446,22 +460,22 @@ function createDOMPurify() {
|
|
|
446
460
|
};
|
|
447
461
|
|
|
448
462
|
/**
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
463
|
+
* _isNode
|
|
464
|
+
*
|
|
465
|
+
* @param object to check whether it's a DOM node
|
|
466
|
+
* @return true is object is a DOM node
|
|
467
|
+
*/
|
|
454
468
|
var _isNode = function _isNode(obj) {
|
|
455
469
|
return (typeof Node === 'undefined' ? 'undefined' : _typeof(Node)) === 'object' ? obj instanceof Node : obj && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && typeof obj.nodeType === 'number' && typeof obj.nodeName === 'string';
|
|
456
470
|
};
|
|
457
471
|
|
|
458
472
|
/**
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
473
|
+
* _executeHook
|
|
474
|
+
* Execute user configurable hooks
|
|
475
|
+
*
|
|
476
|
+
* @param {String} entryPoint Name of the hook's entry point
|
|
477
|
+
* @param {Node} currentNode
|
|
478
|
+
*/
|
|
465
479
|
var _executeHook = function _executeHook(entryPoint, currentNode, data) {
|
|
466
480
|
if (!hooks[entryPoint]) {
|
|
467
481
|
return;
|
|
@@ -473,15 +487,15 @@ function createDOMPurify() {
|
|
|
473
487
|
};
|
|
474
488
|
|
|
475
489
|
/**
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
490
|
+
* _sanitizeElements
|
|
491
|
+
*
|
|
492
|
+
* @protect nodeName
|
|
493
|
+
* @protect textContent
|
|
494
|
+
* @protect removeChild
|
|
495
|
+
*
|
|
496
|
+
* @param node to check for permission to exist
|
|
497
|
+
* @return true if node was killed, false if left alive
|
|
498
|
+
*/
|
|
485
499
|
var _sanitizeElements = function _sanitizeElements(currentNode) {
|
|
486
500
|
var content = void 0;
|
|
487
501
|
|
|
@@ -525,8 +539,8 @@ function createDOMPurify() {
|
|
|
525
539
|
if (SAFE_FOR_TEMPLATES && currentNode.nodeType === 3) {
|
|
526
540
|
/* Get the element's text content */
|
|
527
541
|
content = currentNode.textContent;
|
|
528
|
-
content = content.replace(MUSTACHE_EXPR, ' ');
|
|
529
|
-
content = content.replace(ERB_EXPR, ' ');
|
|
542
|
+
content = content.replace(MUSTACHE_EXPR$$1, ' ');
|
|
543
|
+
content = content.replace(ERB_EXPR$$1, ' ');
|
|
530
544
|
if (currentNode.textContent !== content) {
|
|
531
545
|
DOMPurify.removed.push({ element: currentNode.cloneNode() });
|
|
532
546
|
currentNode.textContent = content;
|
|
@@ -539,24 +553,17 @@ function createDOMPurify() {
|
|
|
539
553
|
return false;
|
|
540
554
|
};
|
|
541
555
|
|
|
542
|
-
var DATA_ATTR = /^data-[\-\w.\u00B7-\uFFFF]/; // eslint-disable-line no-useless-escape
|
|
543
|
-
var ARIA_ATTR = /^aria-[\-\w]+$/; // eslint-disable-line no-useless-escape
|
|
544
|
-
var IS_ALLOWED_URI = /^(?:(?:(?:f|ht)tps?|mailto|tel):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i; // eslint-disable-line no-useless-escape
|
|
545
|
-
var IS_SCRIPT_OR_DATA = /^(?:\w+script|data):/i;
|
|
546
|
-
/* This needs to be extensive thanks to Webkit/Blink's behavior */
|
|
547
|
-
var ATTR_WHITESPACE = /[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205f\u3000]/g;
|
|
548
|
-
|
|
549
556
|
/**
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
557
|
+
* _sanitizeAttributes
|
|
558
|
+
*
|
|
559
|
+
* @protect attributes
|
|
560
|
+
* @protect nodeName
|
|
561
|
+
* @protect removeAttribute
|
|
562
|
+
* @protect setAttribute
|
|
563
|
+
*
|
|
564
|
+
* @param node to sanitize
|
|
565
|
+
* @return void
|
|
566
|
+
*/
|
|
560
567
|
// eslint-disable-next-line complexity
|
|
561
568
|
var _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
|
|
562
569
|
var attr = void 0;
|
|
@@ -631,23 +638,23 @@ function createDOMPurify() {
|
|
|
631
638
|
}
|
|
632
639
|
|
|
633
640
|
/* Make sure attribute cannot clobber */
|
|
634
|
-
if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in
|
|
641
|
+
if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
|
|
635
642
|
continue;
|
|
636
643
|
}
|
|
637
644
|
|
|
638
645
|
/* Sanitize attribute content to be template-safe */
|
|
639
646
|
if (SAFE_FOR_TEMPLATES) {
|
|
640
|
-
value = value.replace(MUSTACHE_EXPR, ' ');
|
|
641
|
-
value = value.replace(ERB_EXPR, ' ');
|
|
647
|
+
value = value.replace(MUSTACHE_EXPR$$1, ' ');
|
|
648
|
+
value = value.replace(ERB_EXPR$$1, ' ');
|
|
642
649
|
}
|
|
643
650
|
|
|
644
651
|
/* Allow valid data-* attributes: At least one character after "-"
|
|
645
652
|
(https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
|
|
646
653
|
XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
|
|
647
654
|
We don't need to check the value; it's always URI safe. */
|
|
648
|
-
if (ALLOW_DATA_ATTR && DATA_ATTR.test(lcName)) {
|
|
655
|
+
if (ALLOW_DATA_ATTR && DATA_ATTR$$1.test(lcName)) {
|
|
649
656
|
// This attribute is safe
|
|
650
|
-
} else if (ALLOW_ARIA_ATTR && ARIA_ATTR.test(lcName)) {
|
|
657
|
+
} else if (ALLOW_ARIA_ATTR && ARIA_ATTR$$1.test(lcName)) {
|
|
651
658
|
// This attribute is safe
|
|
652
659
|
/* Otherwise, check the name is permitted */
|
|
653
660
|
} else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
|
|
@@ -658,7 +665,7 @@ function createDOMPurify() {
|
|
|
658
665
|
// This attribute is safe
|
|
659
666
|
/* Check no script, data or unknown possibly unsafe URI
|
|
660
667
|
unless we know URI values are safe for that attribute */
|
|
661
|
-
} else if (IS_ALLOWED_URI.test(value.replace(ATTR_WHITESPACE, ''))) {
|
|
668
|
+
} else if (IS_ALLOWED_URI$$1.test(value.replace(ATTR_WHITESPACE$$1, ''))) {
|
|
662
669
|
// This attribute is safe
|
|
663
670
|
/* Keep image data URIs alive if src/xlink:href is allowed */
|
|
664
671
|
} else if ((lcName === 'src' || lcName === 'xlink:href') && value.indexOf('data:') === 0 && DATA_URI_TAGS[currentNode.nodeName.toLowerCase()]) {
|
|
@@ -666,7 +673,7 @@ function createDOMPurify() {
|
|
|
666
673
|
/* Allow unknown protocols: This provides support for links that
|
|
667
674
|
are handled by protocol handlers which may be unknown ahead of
|
|
668
675
|
time, e.g. fb:, spotify: */
|
|
669
|
-
} else if (ALLOW_UNKNOWN_PROTOCOLS && !IS_SCRIPT_OR_DATA.test(value.replace(ATTR_WHITESPACE, ''))) {
|
|
676
|
+
} else if (ALLOW_UNKNOWN_PROTOCOLS && !IS_SCRIPT_OR_DATA$$1.test(value.replace(ATTR_WHITESPACE$$1, ''))) {
|
|
670
677
|
// This attribute is safe
|
|
671
678
|
/* Check for binary attributes */
|
|
672
679
|
// eslint-disable-next-line no-negated-condition
|
|
@@ -689,11 +696,11 @@ function createDOMPurify() {
|
|
|
689
696
|
};
|
|
690
697
|
|
|
691
698
|
/**
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
699
|
+
* _sanitizeShadowDOM
|
|
700
|
+
*
|
|
701
|
+
* @param fragment to iterate over recursively
|
|
702
|
+
* @return void
|
|
703
|
+
*/
|
|
697
704
|
var _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
|
|
698
705
|
var shadowNode = void 0;
|
|
699
706
|
var shadowIterator = _createIterator(fragment);
|
|
@@ -724,12 +731,12 @@ function createDOMPurify() {
|
|
|
724
731
|
};
|
|
725
732
|
|
|
726
733
|
/**
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
734
|
+
* Sanitize
|
|
735
|
+
* Public method providing core sanitation functionality
|
|
736
|
+
*
|
|
737
|
+
* @param {String|Node} dirty string or DOM node
|
|
738
|
+
* @param {Object} configuration object
|
|
739
|
+
*/
|
|
733
740
|
// eslint-disable-next-line complexity
|
|
734
741
|
DOMPurify.sanitize = function (dirty, cfg) {
|
|
735
742
|
var body = void 0;
|
|
@@ -751,6 +758,9 @@ function createDOMPurify() {
|
|
|
751
758
|
throw new TypeError('toString is not a function');
|
|
752
759
|
} else {
|
|
753
760
|
dirty = dirty.toString();
|
|
761
|
+
if (typeof dirty !== 'string') {
|
|
762
|
+
throw new TypeError('dirty is not a string, aborting');
|
|
763
|
+
}
|
|
754
764
|
}
|
|
755
765
|
}
|
|
756
766
|
|
|
@@ -859,35 +869,35 @@ function createDOMPurify() {
|
|
|
859
869
|
};
|
|
860
870
|
|
|
861
871
|
/**
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
872
|
+
* Public method to set the configuration once
|
|
873
|
+
* setConfig
|
|
874
|
+
*
|
|
875
|
+
* @param {Object} configuration object
|
|
876
|
+
* @return void
|
|
877
|
+
*/
|
|
868
878
|
DOMPurify.setConfig = function (cfg) {
|
|
869
879
|
_parseConfig(cfg);
|
|
870
880
|
SET_CONFIG = true;
|
|
871
881
|
};
|
|
872
882
|
|
|
873
883
|
/**
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
884
|
+
* Public method to remove the configuration
|
|
885
|
+
* clearConfig
|
|
886
|
+
*
|
|
887
|
+
* @return void
|
|
888
|
+
*/
|
|
879
889
|
DOMPurify.clearConfig = function () {
|
|
880
890
|
CONFIG = null;
|
|
881
891
|
SET_CONFIG = false;
|
|
882
892
|
};
|
|
883
893
|
|
|
884
894
|
/**
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
895
|
+
* AddHook
|
|
896
|
+
* Public method to add DOMPurify hooks
|
|
897
|
+
*
|
|
898
|
+
* @param {String} entryPoint
|
|
899
|
+
* @param {Function} hookFunction
|
|
900
|
+
*/
|
|
891
901
|
DOMPurify.addHook = function (entryPoint, hookFunction) {
|
|
892
902
|
if (typeof hookFunction !== 'function') {
|
|
893
903
|
return;
|
|
@@ -897,13 +907,13 @@ function createDOMPurify() {
|
|
|
897
907
|
};
|
|
898
908
|
|
|
899
909
|
/**
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
910
|
+
* RemoveHook
|
|
911
|
+
* Public method to remove a DOMPurify hook at a given entryPoint
|
|
912
|
+
* (pops it from the stack of hooks if more are present)
|
|
913
|
+
*
|
|
914
|
+
* @param {String} entryPoint
|
|
915
|
+
* @return void
|
|
916
|
+
*/
|
|
907
917
|
DOMPurify.removeHook = function (entryPoint) {
|
|
908
918
|
if (hooks[entryPoint]) {
|
|
909
919
|
hooks[entryPoint].pop();
|
|
@@ -911,12 +921,12 @@ function createDOMPurify() {
|
|
|
911
921
|
};
|
|
912
922
|
|
|
913
923
|
/**
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
924
|
+
* RemoveHooks
|
|
925
|
+
* Public method to remove all DOMPurify hooks at a given entryPoint
|
|
926
|
+
*
|
|
927
|
+
* @param {String} entryPoint
|
|
928
|
+
* @return void
|
|
929
|
+
*/
|
|
920
930
|
DOMPurify.removeHooks = function (entryPoint) {
|
|
921
931
|
if (hooks[entryPoint]) {
|
|
922
932
|
hooks[entryPoint] = [];
|
|
@@ -924,11 +934,11 @@ function createDOMPurify() {
|
|
|
924
934
|
};
|
|
925
935
|
|
|
926
936
|
/**
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
937
|
+
* RemoveAllHooks
|
|
938
|
+
* Public method to remove all DOMPurify hooks
|
|
939
|
+
*
|
|
940
|
+
* @return void
|
|
941
|
+
*/
|
|
932
942
|
DOMPurify.removeAllHooks = function () {
|
|
933
943
|
hooks = {};
|
|
934
944
|
};
|