Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: tools/dom/src/Validators.dart

Issue 1077813002: Check for DOM clobbering attacks in sanitizing/node validation (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/html/node_validator_test.dart ('k') | tools/dom/templates/html/impl/impl_Element.darttemplate » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/dom/src/Validators.dart
diff --git a/tools/dom/src/Validators.dart b/tools/dom/src/Validators.dart
index 95024c6f37824aa3a5d1656387e57c1396894d24..9ba95df7adee8078ffe41d97922720313f166b8a 100644
--- a/tools/dom/src/Validators.dart
+++ b/tools/dom/src/Validators.dart
@@ -145,29 +145,50 @@ class _ValidatingTreeSanitizer implements NodeTreeSanitizer {
_ValidatingTreeSanitizer(this.validator) {}
void sanitizeTree(Node node) {
- void walk(Node node) {
- sanitizeNode(node);
+ void walk(Node node, Node parent) {
+ sanitizeNode(node, parent);
var child = node.lastChild;
while (child != null) {
// Child may be removed during the walk.
var nextChild = child.previousNode;
- walk(child);
+ walk(child, node);
child = nextChild;
}
}
- walk(node);
+ walk(node, null);
}
- void sanitizeNode(Node node) {
+ /// Aggressively try to remove node.
+ void _removeNode(Node node, Node parent) {
+ // If we have the parent, it's presumably already passed more sanitization or
+ // is the fragment, so ask it to remove the child. And if that fails try to
+ // set the outer html.
+ if (parent == null) {
+ node.remove();
+ } else {
+ try {
+ parent._removeChild(node);
+ } catch (e) {
+ node.outerHtml = '';
+ }
+ }
+ }
+
+ void sanitizeNode(Node node, Node parent) {
switch (node.nodeType) {
case Node.ELEMENT_NODE:
Element element = node;
+ if (element._hasCorruptedAttributes) {
+ window.console.warn('Removing element due to corrupted attributes on <${element}>');
+ _removeNode(node, parent);
+ break;
+ }
var attrs = element.attributes;
if (!validator.allowsElement(element)) {
window.console.warn(
'Removing disallowed element <${element.tagName}>');
- element.remove();
+ _removeNode(node, parent);
break;
}
@@ -176,7 +197,7 @@ class _ValidatingTreeSanitizer implements NodeTreeSanitizer {
if (!validator.allowsAttribute(element, 'is', isAttr)) {
window.console.warn('Removing disallowed type extension '
'<${element.tagName} is="$isAttr">');
- element.remove();
+ _removeNode(node, parent);
break;
}
}
@@ -205,7 +226,7 @@ class _ValidatingTreeSanitizer implements NodeTreeSanitizer {
case Node.CDATA_SECTION_NODE:
break;
default:
- node.remove();
+ _removeNode(node, parent);
}
}
}
« no previous file with comments | « tests/html/node_validator_test.dart ('k') | tools/dom/templates/html/impl/impl_Element.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698