Skip to content

Commit 7c8c6b3

Browse files
committed
Version 2.12.3
* Cherry-pick ce5a1c2 to stable * Cherry-pick adc36a6 to stable
2 parents 65376c0 + ad01a07 commit 7c8c6b3

File tree

6 files changed

+51
-17
lines changed

6 files changed

+51
-17
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 2.12.3 - 2021-04-12
2+
3+
This is a patch release that fixes a vulnerability in `dart:html` related to
4+
DOM clobbering. Thanks again to **Vincenzo di Cicco** for finding and reporting
5+
this vulnerability.
6+
17
## 2.12.2 - 2021-03-17
28

39
This is a patch release that fixes crashes reported by Flutter 2 users (issue

sdk/lib/html/dart2js/html_dart2js.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40994,8 +40994,8 @@ class _ThrowsNodeValidator implements NodeValidator {
4099440994
class _ValidatingTreeSanitizer implements NodeTreeSanitizer {
4099540995
NodeValidator validator;
4099640996

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

4100141001
void sanitizeTree(Node node) {
@@ -41026,20 +41026,20 @@ class _ValidatingTreeSanitizer implements NodeTreeSanitizer {
4102641026
}
4102741027
}
4102841028

41029-
modifiedTree = false;
41030-
walk(node, null);
41031-
while (modifiedTree) {
41032-
modifiedTree = false;
41029+
// Walk the tree until no new modifications are added to the tree.
41030+
var previousTreeModifications;
41031+
do {
41032+
previousTreeModifications = numTreeModifications;
4103341033
walk(node, null);
41034-
}
41034+
} while (previousTreeModifications != numTreeModifications);
4103541035
}
4103641036

4103741037
/// Aggressively try to remove node.
4103841038
void _removeNode(Node node, Node? parent) {
4103941039
// If we have the parent, it's presumably already passed more sanitization
4104041040
// or is the fragment, so ask it to remove the child. And if that fails
4104141041
// try to set the outer html.
41042-
modifiedTree = true;
41042+
numTreeModifications++;
4104341043
if (parent == null || parent != node.parentNode) {
4104441044
node.remove();
4104541045
} else {

tests/lib/html/node_validator_important_if_you_suppress_make_the_bug_critical_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,20 @@ main() {
453453
"<input id='bad' onmouseover='alert(1)'>",
454454
"");
455455

456+
// Walking templates triggers a recursive sanitization call, which shouldn't
457+
// invalidate the information collected from the previous visit of the later
458+
// nodes in the walk.
459+
testHtml(
460+
'DOM clobbering with recursive sanitize call using templates',
461+
validator,
462+
"<form><div>"
463+
"<input id=childNodes />"
464+
"<template></template>"
465+
"<input id=childNodes name=lastChild />"
466+
"<img id=exploitImg src=0 onerror='alert(1)' />"
467+
"</div></form>",
468+
"");
469+
456470
test('tagName makes containing form invalid', () {
457471
var fragment = document.body!.createFragment(
458472
"<form onmouseover='alert(2)'><input name='tagName'>",

tests/lib_2/html/node_validator_important_if_you_suppress_make_the_bug_critical_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,20 @@ main() {
478478
"<input id='bad' onmouseover='alert(1)'>",
479479
"");
480480

481+
// Walking templates triggers a recursive sanitization call, which shouldn't
482+
// invalidate the information collected from the previous visit of the later
483+
// nodes in the walk.
484+
testHtml(
485+
'DOM clobbering with recursive sanitize call using templates',
486+
validator,
487+
"<form><div>"
488+
"<input id=childNodes />"
489+
"<template></template>"
490+
"<input id=childNodes name=lastChild />"
491+
"<img id=exploitImg src=0 onerror='alert(1)' />"
492+
"</div></form>",
493+
"");
494+
481495
test('tagName makes containing form invalid', () {
482496
var fragment = document.body.createFragment(
483497
"<form onmouseover='alert(2)'><input name='tagName'>",

tools/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
CHANNEL stable
2727
MAJOR 2
2828
MINOR 12
29-
PATCH 2
29+
PATCH 3
3030
PRERELEASE 0
3131
PRERELEASE_PATCH 0

tools/dom/src/Validators.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ class _ThrowsNodeValidator implements NodeValidator {
158158
class _ValidatingTreeSanitizer implements NodeTreeSanitizer {
159159
NodeValidator validator;
160160

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

165165
void sanitizeTree(Node node) {
@@ -190,20 +190,20 @@ class _ValidatingTreeSanitizer implements NodeTreeSanitizer {
190190
}
191191
}
192192

193-
modifiedTree = false;
194-
walk(node, null);
195-
while (modifiedTree) {
196-
modifiedTree = false;
193+
// Walk the tree until no new modifications are added to the tree.
194+
var previousTreeModifications;
195+
do {
196+
previousTreeModifications = numTreeModifications;
197197
walk(node, null);
198-
}
198+
} while (previousTreeModifications != numTreeModifications);
199199
}
200200

201201
/// Aggressively try to remove node.
202202
void _removeNode(Node node, Node? parent) {
203203
// If we have the parent, it's presumably already passed more sanitization
204204
// or is the fragment, so ask it to remove the child. And if that fails
205205
// try to set the outer html.
206-
modifiedTree = true;
206+
numTreeModifications++;
207207
if (parent == null || parent != node.parentNode) {
208208
node.remove();
209209
} else {

0 commit comments

Comments
 (0)