Skip to content
This repository was archived by the owner on Aug 1, 2024. It is now read-only.

Commit c79ab48

Browse files
sirdarckcatnreid260
authored andcommitted
Automated g4 rollback of changelist 214621663.
*** Reason for rollback *** This introduced an XSS in GWS. b/125799080 *** Original change description *** Fix(safedomtreeprocessor): closing empty element using XML style /> not valid on IE cause by IE's XMLSerializer - use innerHTML instead of XMLSerializer to get string version of sanitized HTML tree - added test for this issue - updated affected test http://sponge/54fb1dcf-8d59-4b42-9faf-9702b24466c1 demo: http://pmelendez.pit.corp.google.com:8888/search?q=nintendo+switch&e=4197585 RELNOTES: Fix safedomtreeprocessor.processToString closing empty element using /> on IE. *** ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=235204275
1 parent a2daa5f commit c79ab48

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

closure/goog/html/sanitizer/htmlsanitizer_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,11 +1648,11 @@ function testUrlWithCredentials() {
16481648

16491649

16501650
function testClobberedForm() {
1651-
var input = '<form><input name="nodeType"></form>';
1651+
var input = '<form><input name="nodeType" /></form>';
16521652
// Passing a string in assertSanitizedHtml uses assertHtmlMatches, which is
16531653
// also vulnerable to clobbering. We use a regexp to fall back to simple
16541654
// string matching.
1655-
var expected = new RegExp('<form><input name="nodeType"></form>');
1655+
var expected = new RegExp('<form><input name="nodeType" /></form>');
16561656
assertSanitizedHtml(
16571657
input, expected,
16581658
new goog.html.sanitizer.HtmlSanitizer.Builder()

closure/goog/html/sanitizer/safedomtreeprocessor.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,12 @@ SafeDomTreeProcessor.prototype.processToString = function(html) {
108108
newRoot.appendChild(newTree);
109109
newTree = newRoot;
110110
}
111-
112-
// Serialized string of the sanitized DOM without root span tag
113-
return newTree.innerHTML;
111+
// The XMLSerializer will add a spurious xmlns attribute to the root node.
112+
var serializedNewTree = new XMLSerializer().serializeToString(newTree);
113+
// Remove the outer span before returning the string representation of the
114+
// processed copy.
115+
return serializedNewTree.slice(
116+
serializedNewTree.indexOf('>') + 1, serializedNewTree.lastIndexOf('</'));
114117
};
115118

116119
/**

closure/goog/html/sanitizer/safedomtreeprocessor_test.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,6 @@ testSuite({
7373
input, new NoopProcessor().processToString(input));
7474
},
7575

76-
testEmptyTag() {
77-
var input = '<div></div>';
78-
var actual = new NoopProcessor().processToString(input);
79-
80-
if (SafeDomTreeProcessor.SAFE_PARSING_SUPPORTED) {
81-
assertEquals(input, actual);
82-
} else {
83-
assertEquals('', actual);
84-
}
85-
},
86-
8776
testTagChanged() {
8877
var processor = new NoopProcessor();
8978
processor.createElementWithoutAttributes = anchorToFoo;

0 commit comments

Comments
 (0)