Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions dom/html/HTMLScriptElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ nsresult HTMLScriptElement::Clone(dom::NodeInfo* aNodeInfo,
return NS_OK;
}

void HTMLScriptElement::SetTextContentInternal(const nsAString& aTextContent,
nsIPrincipal* aSubjectPrincipal,
ErrorResult& aError) {
if(aTextContent.isTainted()) {
ReportTaintSink(aTextContent, "script.textContent", this);
}
FragmentOrElement::SetTextContentInternal(aTextContent, aSubjectPrincipal, aError);
}

nsresult HTMLScriptElement::CheckTaintSinkSetAttr(int32_t aNamespaceID, nsAtom* aName,
const nsAString& aValue) {
if (aNamespaceID == kNameSpaceID_None && aName == nsGkAtoms::src) {
Expand Down
3 changes: 3 additions & 0 deletions dom/html/HTMLScriptElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ class HTMLScriptElement final : public nsGenericHTMLElement,
[[nodiscard]] static bool Supports(const GlobalObject& aGlobal,
const nsAString& aType);

virtual void SetTextContentInternal(const nsAString& aTextContent,
nsIPrincipal* aSubjectPrincipal,
ErrorResult& aError) override;
protected:
virtual ~HTMLScriptElement();

Expand Down
31 changes: 20 additions & 11 deletions taint/test/mochitest/test_script_sinks.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,38 @@

SimpleTest.waitForExplicitFinish();
addEventListener("__taintreport", (report) => {
SimpleTest.is(report.detail.str, "tainted=hello", "Check sink string content");

if(i == 0) {
SimpleTest.is(report.detail.str, "url", "Check sink string content");
} else {
SimpleTest.is(report.detail.str, "console.log();", "Check sink string content");
}
let flow = report.detail.str.taint[0].flow;
SimpleTest.is(flow[2].operation, sink_names[i]);
SimpleTest.is(flow[2].operation, sink_names[i], `${sink_names[i]} sink test`);

i += 1;
if (i >= sink_names.length) {
SimpleTest.finish();
}
}, false);

function setScriptProperty(text, f) {
let script = document.createElement("script");
script.id = "tempscript";
f(script, text);
document.body.appendChild(script);
document.body.removeChild(script);
}

function startTest() {
let tainted = String.tainted("tainted=hello");
let script = document.getElementById("emptyScript");
script.src = tainted;
script.text = tainted;
script.innerHTML = tainted;
script.textContent = tainted;
let tainted = String.tainted("console.log();");
setScriptProperty(String.tainted("url"), (s,t) => s.src = t);
setScriptProperty(tainted, (s,t) => s.text = t);
setScriptProperty(tainted, (s,t) => s.innerHTML = t);
setScriptProperty(tainted, (s,t) => s.textContent = t);
}

</script>
<script id="emptyScript">
</script>

</head>

<body onload="startTest();">
Expand Down
Loading