Skip to content

Commit b6e7487

Browse files
authored
Merge pull request #282 from leeN/script-textContent-sink
script.textContent sink
2 parents 5453ff4 + fa828ab commit b6e7487

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

dom/html/HTMLScriptElement.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ nsresult HTMLScriptElement::Clone(dom::NodeInfo* aNodeInfo,
126126
return NS_OK;
127127
}
128128

129+
void HTMLScriptElement::SetTextContentInternal(const nsAString& aTextContent,
130+
nsIPrincipal* aSubjectPrincipal,
131+
ErrorResult& aError) {
132+
if(aTextContent.isTainted()) {
133+
ReportTaintSink(aTextContent, "script.textContent", this);
134+
}
135+
FragmentOrElement::SetTextContentInternal(aTextContent, aSubjectPrincipal, aError);
136+
}
137+
129138
nsresult HTMLScriptElement::CheckTaintSinkSetAttr(int32_t aNamespaceID, nsAtom* aName,
130139
const nsAString& aValue) {
131140
if (aNamespaceID == kNameSpaceID_None && aName == nsGkAtoms::src) {

dom/html/HTMLScriptElement.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ class HTMLScriptElement final : public nsGenericHTMLElement,
152152
[[nodiscard]] static bool Supports(const GlobalObject& aGlobal,
153153
const nsAString& aType);
154154

155+
virtual void SetTextContentInternal(const nsAString& aTextContent,
156+
nsIPrincipal* aSubjectPrincipal,
157+
ErrorResult& aError) override;
155158
protected:
156159
virtual ~HTMLScriptElement();
157160

taint/test/mochitest/test_script_sinks.html

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,38 @@
1919

2020
SimpleTest.waitForExplicitFinish();
2121
addEventListener("__taintreport", (report) => {
22-
SimpleTest.is(report.detail.str, "tainted=hello", "Check sink string content");
23-
22+
if(i == 0) {
23+
SimpleTest.is(report.detail.str, "url", "Check sink string content");
24+
} else {
25+
SimpleTest.is(report.detail.str, "console.log();", "Check sink string content");
26+
}
2427
let flow = report.detail.str.taint[0].flow;
25-
SimpleTest.is(flow[2].operation, sink_names[i]);
28+
SimpleTest.is(flow[2].operation, sink_names[i], `${sink_names[i]} sink test`);
2629

2730
i += 1;
2831
if (i >= sink_names.length) {
2932
SimpleTest.finish();
3033
}
3134
}, false);
3235

36+
function setScriptProperty(text, f) {
37+
let script = document.createElement("script");
38+
script.id = "tempscript";
39+
f(script, text);
40+
document.body.appendChild(script);
41+
document.body.removeChild(script);
42+
}
43+
3344
function startTest() {
34-
let tainted = String.tainted("tainted=hello");
35-
let script = document.getElementById("emptyScript");
36-
script.src = tainted;
37-
script.text = tainted;
38-
script.innerHTML = tainted;
39-
script.textContent = tainted;
45+
let tainted = String.tainted("console.log();");
46+
setScriptProperty(String.tainted("url"), (s,t) => s.src = t);
47+
setScriptProperty(tainted, (s,t) => s.text = t);
48+
setScriptProperty(tainted, (s,t) => s.innerHTML = t);
49+
setScriptProperty(tainted, (s,t) => s.textContent = t);
4050
}
4151

4252
</script>
43-
<script id="emptyScript">
44-
</script>
53+
4554
</head>
4655

4756
<body onload="startTest();">

0 commit comments

Comments
 (0)