@claspo/common 7.5.18-dcp1 → 7.5.19-mss1
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/dom/sanitizeHTML.js +1 -1
- package/package.json +1 -1
package/dom/sanitizeHTML.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function sanitizeHTML(t){if(null==t)return"";if("string"!=typeof t)return String(t);if(""===t)return"";if(!/<\/?([a-zA-Z][a-zA-Z0-9]*)\b[^>]*>/.test(t))return t;const e=(new DOMParser).parseFromString(t,"text/html");e.querySelectorAll('script, style, link[rel="stylesheet"], meta[http-equiv]').forEach(t=>t.remove());return e.querySelectorAll("*").forEach(t=>{
|
|
1
|
+
function normalizeUrlForSchemeCheck(t){return t.replace(/[\u0000- ]/g,"").toLowerCase()}export default function sanitizeHTML(t){if(null==t)return"";if("string"!=typeof t)return String(t);if(""===t)return"";if(!/<\/?([a-zA-Z][a-zA-Z0-9]*)\b[^>]*>/.test(t))return t;const e=(new DOMParser).parseFromString(t,"text/html");e.querySelectorAll('script, style, link[rel="stylesheet"], meta[http-equiv], object, embed').forEach(t=>t.remove());return e.querySelectorAll("*").forEach(t=>{["onclick","onload","onerror","onmouseover","onfocus","onblur","onkeyup","onkeydown","onchange","onsubmit","onmouseenter","onmouseleave","onmouseout","oncontextmenu","ondrag","ondrop","srcdoc"].forEach(e=>t.removeAttribute(e)),Array.from(t.attributes).forEach(e=>{e.name.startsWith("on")&&t.removeAttribute(e.name)});const e=t.tagName.toUpperCase();if("A"!==e&&"AREA"!==e||["href","xlink:href"].forEach(e=>{const r=normalizeUrlForSchemeCheck(t.getAttribute(e)||"");(r.startsWith("javascript:")||r.startsWith("data:"))&&t.removeAttribute(e)}),"IMG"===e||"IFRAME"===e){const e=normalizeUrlForSchemeCheck(t.getAttribute("src")||"");(e.startsWith("javascript:")||e.startsWith("data:text/html"))&&t.removeAttribute("src")}["action","formaction"].forEach(e=>{normalizeUrlForSchemeCheck(t.getAttribute(e)||"").startsWith("javascript:")&&t.removeAttribute(e)})}),e.body.innerHTML}
|