Bug 1250985 - Part 2: Prevent copy constructing a Request object with navigate mode if a RequestInit member is present; r=bzbarsky

This commit is contained in:
Ehsan Akhgari 2016-02-24 13:46:38 -05:00
parent cc9a74fb65
commit 2b0a5105b9
3 changed files with 36 additions and 1 deletions

View File

@ -284,7 +284,8 @@ Request::Constructor(const GlobalObject& aGlobal,
aInit.mCredentials.WasPassed() ? aInit.mCredentials.Value()
: fallbackCredentials;
if (mode == RequestMode::Navigate) {
if (mode == RequestMode::Navigate ||
(aInit.IsAnyMemberPresent() && request->Mode() == RequestMode::Navigate)) {
aRv.ThrowTypeError<MSG_INVALID_REQUEST_MODE>(NS_LITERAL_STRING("navigate"));
return nullptr;
}

View File

@ -117,6 +117,15 @@
my_ok(this.test_result, "iframe load should be intercepted");
});
test_onload(function() {
var elem = document.createElement('iframe');
elem.id = 'intercepted-iframe-2';
elem.src = "navigate.html";
return elem;
}, function() {
my_ok(this.test_result, "iframe should successfully load");
});
gExpected++;
var xmlDoc = document.implementation.createDocument(null, null, null);
xmlDoc.load('load_cross_origin_xml_document_synthetic.xml');

View File

@ -147,6 +147,31 @@ onfetch = function(ev) {
));
}
else if (ev.request.url.includes("navigate.html")) {
var navigateModeCorrectlyChecked = false;
var requests = [ // should not throw
new Request(ev.request),
new Request(ev.request, undefined),
new Request(ev.request, null),
new Request(ev.request, {}),
new Request(ev.request, {someUnrelatedProperty: 42}),
];
try {
var request3 = new Request(ev.request, {method: "GET"}); // should throw
} catch(e) {
navigateModeCorrectlyChecked = requests[0].mode == "navigate";
}
if (navigateModeCorrectlyChecked) {
ev.respondWith(Promise.resolve(
new Response("<script>window.frameElement.test_result = true;</script>", {
headers : {
"Content-Type": "text/html"
}
})
));
}
}
else if (ev.request.url.includes("nonexistent_worker_script.js")) {
ev.respondWith(Promise.resolve(
new Response("postMessage('worker-intercept-success')", {})