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

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

Issue 1365093003: Fix node_validator xss tests for IE and Firefox (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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 | « tools/dom/src/NodeValidatorBuilder.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 11cb3d0d5ac642f9872959a9851baae3030c84da..d7fd920b79400ada5d947f459469a35dd2f70c49 100644
--- a/tools/dom/src/Validators.dart
+++ b/tools/dom/src/Validators.dart
@@ -141,14 +141,14 @@ class _ThrowsNodeValidator implements NodeValidator {
bool allowsElement(Element element) {
if (!validator.allowsElement(element)) {
- throw new ArgumentError(element._safeTagName);
+ throw new ArgumentError(Element._safeTagName(element));
}
return true;
}
bool allowsAttribute(Element element, String attributeName, String value) {
if (!validator.allowsAttribute(element, attributeName, value)) {
- throw new ArgumentError('${element._safeTagName}[$attributeName="$value"]');
+ throw new ArgumentError('${Element._safeTagName(element)}[$attributeName="$value"]');
}
}
}
@@ -190,7 +190,7 @@ class _ValidatingTreeSanitizer implements NodeTreeSanitizer {
}
/// Sanitize the element, assuming we can't trust anything about it.
- void _sanitizeUntrustedElement(Element element, Node parent) {
+ void _sanitizeUntrustedElement(/* Element */ element, Node parent) {
// If the _hasCorruptedAttributes does not successfully return false,
// then we consider it corrupted and remove.
// TODO(alanknight): This is a workaround because on Firefox
@@ -199,7 +199,9 @@ class _ValidatingTreeSanitizer implements NodeTreeSanitizer {
// can't call methods. This does mean that you can't explicitly allow an
// embed tag. The only thing that will let it through is a null
// sanitizer that doesn't traverse the tree at all. But sanitizing while
- // allowing embeds seems quite unlikely.
+ // allowing embeds seems quite unlikely. This is also the reason that we
+ // can't declare the type of element, as an embed won't pass any type
+ // check in dart2js.
var corrupted = true;
var attrs;
var isAttr;
@@ -207,15 +209,27 @@ class _ValidatingTreeSanitizer implements NodeTreeSanitizer {
// If getting/indexing attributes throws, count that as corrupt.
attrs = element.attributes;
isAttr = attrs['is'];
- corrupted = Element._hasCorruptedAttributes(element);
+ // On IE, erratically, the hasCorruptedAttributes test can return false,
+ // even though it clearly is corrupted. A separate copy of the test
+ // inlining just the basic check seems to help.
+ var corruptedTest1 = Element._hasCorruptedAttributes(element);
+ var corruptedTest2 = JS('bool', r'!(#.attributes instanceof NamedNodeMap)', element);
+ corrupted = corruptedTest1 || corruptedTest2;
} catch(e) {}
- var elementText = 'element unprintable';
+ var elementText = 'element unprintable';
try {
elementText = element.toString();
} catch(e) {}
- var elementTagName = element._safeTagName;
- _sanitizeElement(element, parent, corrupted, elementText, elementTagName,
- attrs, isAttr);
+ try {
+ var elementTagName = Element._safeTagName(element);
+ _sanitizeElement(element, parent, corrupted, elementText, elementTagName,
+ attrs, isAttr);
+ } on ArgumentError { // Thrown by _ThrowsNodeValidator
+ rethrow;
+ } catch(e) { // Unexpected exception sanitizing -> remove
+ _removeNode(element, parent);
+ window.console.warn('Removing corrupted element $elementText');
+ }
}
/// Having done basic sanity checking on the element, and computed the
@@ -224,23 +238,23 @@ class _ValidatingTreeSanitizer implements NodeTreeSanitizer {
void _sanitizeElement(Element element, Node parent, bool corrupted,
String text, String tag, Map attrs, String isAttr) {
if (false != corrupted) {
+ _removeNode(element, parent);
window.console.warn(
'Removing element due to corrupted attributes on <$text>');
- _removeNode(element, parent);
return;
}
if (!validator.allowsElement(element)) {
- window.console.warn(
- 'Removing disallowed element <$tag>');
_removeNode(element, parent);
+ window.console.warn(
+ 'Removing disallowed element <$tag> from $parent');
return;
}
if (isAttr != null) {
if (!validator.allowsAttribute(element, 'is', isAttr)) {
+ _removeNode(element, parent);
window.console.warn('Removing disallowed type extension '
'<$tag is="$isAttr">');
- _removeNode(element, parent);
return;
}
}
« no previous file with comments | « tools/dom/src/NodeValidatorBuilder.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