Skip to content

Commit 2758d1e

Browse files
committed
Bug 1744352 - Part 2: Add test for sandboxing javascript uris in pop-ups, r=smaug a=RyanVM
Differential Revision: https://phabricator.services.mozilla.com/D138211
1 parent 549c632 commit 2758d1e

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

docshell/test/mochitest/mochitest.ini

+1
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,4 @@ support-files =
137137
clicker.html
138138
double_submit.sjs
139139
[test_iframe_srcdoc_to_remote.html]
140+
[test_javascript_sandboxed_popup.html]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<head>
3+
<meta charset="utf-8">
4+
<script src="/tests/SimpleTest/SimpleTest.js"></script>
5+
<link rel="stylesheet" href="/tests/SimpleTest/test.css" />
6+
</head>
7+
8+
<body>
9+
<iframe srcdoc="<a href='javascript:opener.parent.ok(false, `The JS ran!`)' target=_blank rel=opener>click</a>"
10+
sandbox="allow-popups allow-same-origin"></iframe>
11+
12+
<script>
13+
add_task(async function() {
14+
let promise = new Promise(resolve =>{
15+
SpecialPowers.addObserver(function obs(subject) {
16+
is(subject.opener, window[0],
17+
"blocked javascript URI should have been targeting the pop-up document");
18+
subject.close();
19+
SpecialPowers.removeObserver(obs, "javascript-uri-blocked-by-sandbox");
20+
resolve();
21+
}, "javascript-uri-blocked-by-sandbox");
22+
});
23+
document.querySelector("iframe").contentDocument.querySelector("a").click();
24+
await promise;
25+
});
26+
</script>
27+
</body>

dom/jsurl/nsJSProtocolHandler.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ nsresult nsJSThunk::EvaluateScript(
236236
// Sandboxed document check: javascript: URI execution is disabled
237237
// in a sandboxed document unless 'allow-scripts' was specified.
238238
if (targetDoc->HasScriptsBlockedBySandbox()) {
239+
if (nsCOMPtr<nsIObserverService> obs =
240+
mozilla::services::GetObserverService()) {
241+
obs->NotifyWhenScriptSafe(ToSupports(innerWin),
242+
"javascript-uri-blocked-by-sandbox");
243+
}
239244
return NS_ERROR_DOM_RETVAL_UNDEFINED;
240245
}
241246

0 commit comments

Comments
 (0)