fix(editor): sanitize user-imported SVGs before DOM insertion
SvgEditorRoute.loadSVG inserted dropped SVG files with no stripping; pathology-editor stripped descendants but missed the root element's on* attributes and javascript: hrefs. Both now remove script/ foreignObject nodes, on* handlers (root included) and javascript: hrefs before appendChild. Impact bounded (no auth/backend), MEDIUM.
This commit is contained in:
1 parent
18865def06
commit
3f91a45660
2 files changed
+21
-3
No files matched your search
@@ -1125,9 +1125,12 @@
|
||||
clearChildren(canvasInner);
|
||||
var imported = document.importNode(svg, true);
|
||||
imported.querySelectorAll('script, foreignObject').forEach(function (e) { e.remove(); });
|
||||
imported.querySelectorAll('*').forEach(function (e) {
|
||||
[imported].concat(Array.prototype.slice.call(imported.querySelectorAll('*'))).forEach(function (e) {
|
||||
for (var i = e.attributes.length - 1; i >= 0; i--) {
|
||||
if (e.attributes[i].name.match(/^on/i)) e.removeAttribute(e.attributes[i].name);
|
||||
var a = e.attributes[i];
|
||||
var isHandler = a.name.match(/^on/i);
|
||||
var isJsHref = a.name.match(/href$/i) && a.value.match(/^\s*javascript:/i);
|
||||
if (isHandler || isJsHref) e.removeAttribute(a.name);
|
||||
}
|
||||
});
|
||||
canvasInner.appendChild(imported);
|
||||
|
||||
Reference in new issue
Block a user