diff --git a/public/Assets/CSS/Dark.css b/public/Assets/CSS/Dark.css index fb3de9a..e240177 100644 --- a/public/Assets/CSS/Dark.css +++ b/public/Assets/CSS/Dark.css @@ -104,6 +104,7 @@ Body { background-attachment: local, local, scroll, scroll; */ Background-Color: RGBA(36, 36, 36, 0.85); + Font-Size: Larger; } .Footer > .FooterRight { Margin-Right: 12px; } diff --git a/public/Assets/Lib/Trasformapi.js b/public/Assets/Lib/Trasformapi.js index f67edfa..49866b4 100644 --- a/public/Assets/Lib/Trasformapi.js +++ b/public/Assets/Lib/Trasformapi.js @@ -140,7 +140,7 @@ function _TransformForOutput (transformerTree, initOptions, entityName, upstream // TODO: 'document' won't work on nodejs, must change it function GetElementsByXPath (xpath, parent) { let results = []; - let query = document.evaluate(xpath, parent || document, ((ns) => ns), XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); + let query = (parent?.getRootNode() || document).evaluate(xpath, (parent || document), ((ns) => ns), XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); for (let i=0, length=query.snapshotLength; i elements + * @param {Node} html The HTML + */ + function removeScripts (html) { + let scripts = html.querySelectorAll('script'); + for (let script of scripts) { + script.remove(); + } + } + + /** + * Check if the attribute is potentially dangerous + * @param {String} name The attribute name + * @param {String} value The attribute value + * @return {Boolean} If true, the attribute is potentially dangerous + */ + function isPossiblyDangerous (name, value) { + let val = value.replace(/\s+/g, '').toLowerCase(); + if (['src', 'href', 'xlink:href'].includes(name)) { + if (val.includes('javascript:') || val.includes('data:')) return true; + } + if (name.startsWith('on')) return true; + } + + /** + * Remove potentially dangerous attributes from an element + * @param {Node} elem The element + */ + function removeAttributes (elem) { + + // Loop through each attribute + // If it's dangerous, remove it + let atts = elem.attributes; + for (let {name, value} of atts) { + if (!isPossiblyDangerous(name, value)) continue; + elem.removeAttribute(name); + } + + } + + /** + * Remove dangerous stuff from the HTML document's nodes + * @param {Node} html The HTML document + */ + function clean (html) { + let nodes = html.children; + for (let node of nodes) { + removeAttributes(node); + clean(node); + } + } + + // Convert the string to HTML + let html = stringToHTML(); + + // Sanitize it + removeScripts(html); + clean(html); + + // If the user wants HTML nodes back, return them + // Otherwise, pass a sanitized string back + return nodes ? html.childNodes : html.innerHTML; + +} diff --git a/public/MBViewer/index.html b/public/MBViewer/index.html index 08339a7..d10d4e5 100644 --- a/public/MBViewer/index.html +++ b/public/MBViewer/index.html @@ -207,6 +207,7 @@ +