# HG changeset patch # User Henri Sivonen # Date 1603457329 0 # Fri Oct 23 12:48:49 2020 +0000 # Node ID 3476387362fb15c82f133f390afef719ad36de0a # Parent fd45fcfd6261e9ed6cf83e54ad8286717f1b4762 Bug 1666300 part 1 - Remove attributes from descendants when setting sanitized style. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D93215 diff -r fd45fcfd6261 -r 3476387362fb dom/base/nsTreeSanitizer.cpp --- a/dom/base/nsTreeSanitizer.cpp Fri Oct 23 13:04:19 2020 +0000 +++ b/dom/base/nsTreeSanitizer.cpp Fri Oct 23 12:48:49 2020 +0000 @@ -1341,6 +1341,7 @@ nsAutoString sanitizedStyle; SanitizeStyleSheet(styleText, sanitizedStyle, aRoot->OwnerDoc(), node->GetBaseURI()); + RemoveAllAttributesFromDescendants(elt); nsContentUtils::SetNodeTextContent(node, sanitizedStyle, true); if (!mOnlyConditionalCSS) { @@ -1427,6 +1428,18 @@ } } +void nsTreeSanitizer::RemoveAllAttributesFromDescendants( + mozilla::dom::Element* aElement) { + nsIContent* node = aElement->GetFirstChild(); + while (node) { + if (node->IsElement()) { + mozilla::dom::Element* elt = node->AsElement(); + RemoveAllAttributes(elt); + } + node = node->GetNextNode(aElement); + } +} + void nsTreeSanitizer::LogMessage(const char* aMessage, Document* aDoc, Element* aElement, nsAtom* aAttr) { if (mLogRemovals) { diff -r fd45fcfd6261 -r 3476387362fb dom/base/nsTreeSanitizer.h --- a/dom/base/nsTreeSanitizer.h Fri Oct 23 13:04:19 2020 +0000 +++ b/dom/base/nsTreeSanitizer.h Fri Oct 23 12:48:49 2020 +0000 @@ -200,6 +200,12 @@ void RemoveAllAttributes(mozilla::dom::Element* aElement); /** + * Removes all attributes from the descendants of an element but not from + * the element itself. + */ + void RemoveAllAttributesFromDescendants(mozilla::dom::Element* aElement); + + /** * Log a Console Service message to indicate we removed something. * If you pass an element and/or attribute, their information will * be appended to the message.