/* Now start iterating over the created document */ while ((currentNode = nodeIterator.nextNode())) { /* Fix IE's strange behavior with manipulated textNodes #89 */ if (currentNode.nodeType === 3 && currentNode === oldNode) { continue; }
/* Sanitize tags and elements */ if (_sanitizeElements(currentNode)) { continue; }
/* Shadow DOM detected, sanitize it */ if (currentNode.content instanceof DocumentFragment) { _sanitizeShadowDOM(currentNode.content); }
/* Check attributes, sanitize if necessary */ _sanitizeAttributes(currentNode);
/* Check whether element has a valid namespace */ if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) { _forceRemove(currentNode); returntrue; }
if (ALLOW_DATA_ATTR && regExpTest(DATA_ATTR, lcName)) { // This attribute is safe } elseif (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) { // This attribute is safe /* Otherwise, check the name is permitted */ } elseif (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) { returnfalse;
/* Check value is safe. First, is attr inert? If so, is safe */ } elseif (URI_SAFE_ATTRIBUTES[lcName]) { // This attribute is safe /* Check no script, data or unknown possibly unsafe URI unless we know URI values are safe for that attribute */ } elseif ( regExpTest(IS_ALLOWED_URI, stringReplace(value, ATTR_WHITESPACE, '')) ) { // This attribute is safe /* Keep image data URIs alive if src/xlink:href is allowed */ /* Further prevent gadget XSS for dynamically built script tags */ } elseif ( (lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag] ) { // This attribute is safe /* Allow unknown protocols: This provides support for links that are handled by protocol handlers which may be unknown ahead of time, e.g. fb:, spotify: */ } elseif ( ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA, stringReplace(value, ATTR_WHITESPACE, '')) ) { // This attribute is safe /* Check for binary attributes */ // eslint-disable-next-line no-negated-condition } elseif (!value) { // Binary attributes are safe at this point /* Anything else, presume unsafe, do not add it back */ } else { returnfalse; }