Skip to content

Commit d5957fe

Browse files
authored
Merge pull request #273 from leeN/node-normalize-taint
Fixes Node.normalize() losing taints
2 parents 3032937 + 92bf535 commit d5957fe

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

dom/base/nsINode.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,13 +975,14 @@ void nsINode::Normalize() {
975975
"mutation events messed us up");
976976
if (!hasRemoveListeners || (target && target->NodeType() == TEXT_NODE)) {
977977
nsTextNode* t = static_cast<nsTextNode*>(target);
978+
SafeStringTaint taint = text->Taint();
978979
if (text->Is2b()) {
979-
t->AppendTextForNormalize(text->Get2b(), text->GetLength(), true,
980+
t->AppendTextForNormalize(text->Get2b(), text->GetLength(), taint, true,
980981
node);
981982
} else {
982983
tmpStr.Truncate();
983984
text->AppendTo(tmpStr);
984-
t->AppendTextForNormalize(tmpStr.get(), tmpStr.Length(), true, node);
985+
t->AppendTextForNormalize(tmpStr.get(), tmpStr.Length(), taint, true, node);
985986
}
986987
}
987988
}

dom/base/nsTextNode.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,11 @@ already_AddRefed<CharacterData> nsTextNode::CloneDataNode(
106106
}
107107

108108
nsresult nsTextNode::AppendTextForNormalize(const char16_t* aBuffer,
109-
uint32_t aLength, bool aNotify,
109+
uint32_t aLength, const StringTaint& aTaint, bool aNotify,
110110
nsIContent* aNextSibling) {
111111
CharacterDataChangeInfo::Details details = {
112112
CharacterDataChangeInfo::Details::eMerge, aNextSibling};
113-
// TaintFox: no taint information available here. TODO(samuel) can add aTaint?
114-
return SetTextInternal(mText.GetLength(), 0, aBuffer, aLength, aNotify, EmptyTaint,
113+
return SetTextInternal(mText.GetLength(), 0, aBuffer, aLength, aNotify, aTaint,
115114
&details);
116115
}
117116

dom/base/nsTextNode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class nsTextNode : public mozilla::dom::Text {
4747
nsresult BindToTree(BindContext&, nsINode& aParent) override;
4848
void UnbindFromTree(UnbindContext&) override;
4949

50-
nsresult AppendTextForNormalize(const char16_t* aBuffer, uint32_t aLength,
50+
nsresult AppendTextForNormalize(const char16_t* aBuffer, uint32_t aLength, const StringTaint& taint,
5151
bool aNotify, nsIContent* aNextSibling);
5252

5353
#ifdef MOZ_DOM_LIST

taint/test/mochitest/test_dom.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,24 @@
212212

213213
});
214214

215+
add_task(async function test_node_normalize() {
216+
const wrapper = document.createElement("div");
217+
218+
wrapper.appendChild(document.createTextNode("Values: "));
219+
wrapper.appendChild(document.createTextNode(String.tainted("taint1")));
220+
wrapper.appendChild(document.createTextNode(" - "));
221+
wrapper.appendChild(document.createTextNode(String.tainted("taint2")));
222+
check_untainted(wrapper.childNodes[0].textContent);
223+
check_tainted(wrapper.childNodes[1].textContent);
224+
check_untainted(wrapper.childNodes[2].textContent);
225+
check_tainted(wrapper.childNodes[3].textContent);
226+
wrapper.normalize();
227+
let text = wrapper.firstChild.textContent;
228+
check_tainted(text);
229+
is(text.taint.length,2, "Two flows");
230+
231+
});
232+
215233
</script>
216234
</head>
217235
<body>

0 commit comments

Comments
 (0)