Skip to content

Commit

Permalink
Version 2.12.3
Browse files Browse the repository at this point in the history
* Cherry-pick ce5a1c2 to stable
* Cherry-pick adc36a6 to stable
  • Loading branch information
athomas committed Apr 14, 2021
2 parents 65376c0 + ad01a07 commit 7c8c6b3
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2.12.3 - 2021-04-12

This is a patch release that fixes a vulnerability in `dart:html` related to
DOM clobbering. Thanks again to **Vincenzo di Cicco** for finding and reporting
this vulnerability.

## 2.12.2 - 2021-03-17

This is a patch release that fixes crashes reported by Flutter 2 users (issue
Expand Down
16 changes: 8 additions & 8 deletions sdk/lib/html/dart2js/html_dart2js.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40994,8 +40994,8 @@ class _ThrowsNodeValidator implements NodeValidator {
class _ValidatingTreeSanitizer implements NodeTreeSanitizer {
NodeValidator validator;

/// Did we modify the tree by removing anything.
bool modifiedTree = false;
/// Number of tree modifications this instance has made.
int numTreeModifications = 0;
_ValidatingTreeSanitizer(this.validator) {}

void sanitizeTree(Node node) {
Expand Down Expand Up @@ -41026,20 +41026,20 @@ class _ValidatingTreeSanitizer implements NodeTreeSanitizer {
}
}

modifiedTree = false;
walk(node, null);
while (modifiedTree) {
modifiedTree = false;
// Walk the tree until no new modifications are added to the tree.
var previousTreeModifications;
do {
previousTreeModifications = numTreeModifications;
walk(node, null);
}
} while (previousTreeModifications != numTreeModifications);
}

/// 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.
modifiedTree = true;
numTreeModifications++;
if (parent == null || parent != node.parentNode) {
node.remove();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,20 @@ main() {
"<input id='bad' onmouseover='alert(1)'>",
"");

// Walking templates triggers a recursive sanitization call, which shouldn't
// invalidate the information collected from the previous visit of the later
// nodes in the walk.
testHtml(
'DOM clobbering with recursive sanitize call using templates',
validator,
"<form><div>"
"<input id=childNodes />"
"<template></template>"
"<input id=childNodes name=lastChild />"
"<img id=exploitImg src=0 onerror='alert(1)' />"
"</div></form>",
"");

test('tagName makes containing form invalid', () {
var fragment = document.body!.createFragment(
"<form onmouseover='alert(2)'><input name='tagName'>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,20 @@ main() {
"<input id='bad' onmouseover='alert(1)'>",
"");

// Walking templates triggers a recursive sanitization call, which shouldn't
// invalidate the information collected from the previous visit of the later
// nodes in the walk.
testHtml(
'DOM clobbering with recursive sanitize call using templates',
validator,
"<form><div>"
"<input id=childNodes />"
"<template></template>"
"<input id=childNodes name=lastChild />"
"<img id=exploitImg src=0 onerror='alert(1)' />"
"</div></form>",
"");

test('tagName makes containing form invalid', () {
var fragment = document.body.createFragment(
"<form onmouseover='alert(2)'><input name='tagName'>",
Expand Down
2 changes: 1 addition & 1 deletion tools/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
CHANNEL stable
MAJOR 2
MINOR 12
PATCH 2
PATCH 3
PRERELEASE 0
PRERELEASE_PATCH 0
16 changes: 8 additions & 8 deletions tools/dom/src/Validators.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ class _ThrowsNodeValidator implements NodeValidator {
class _ValidatingTreeSanitizer implements NodeTreeSanitizer {
NodeValidator validator;

/// Did we modify the tree by removing anything.
bool modifiedTree = false;
/// Number of tree modifications this instance has made.
int numTreeModifications = 0;
_ValidatingTreeSanitizer(this.validator) {}

void sanitizeTree(Node node) {
Expand Down Expand Up @@ -190,20 +190,20 @@ class _ValidatingTreeSanitizer implements NodeTreeSanitizer {
}
}

modifiedTree = false;
walk(node, null);
while (modifiedTree) {
modifiedTree = false;
// Walk the tree until no new modifications are added to the tree.
var previousTreeModifications;
do {
previousTreeModifications = numTreeModifications;
walk(node, null);
}
} while (previousTreeModifications != numTreeModifications);
}

/// 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.
modifiedTree = true;
numTreeModifications++;
if (parent == null || parent != node.parentNode) {
node.remove();
} else {
Expand Down

0 comments on commit 7c8c6b3

Please sign in to comment.