Bug 1163898 part 2. Allow creation of an anonymous XHR in non-window scopes if the right mozAnon bits are passed in. r=smaug

This commit is contained in:
Boris Zbarsky 2015-05-12 15:56:41 -04:00
parent 068f758b05
commit ca4d389a7a
3 changed files with 30 additions and 9 deletions

View File

@ -391,29 +391,33 @@ nsXMLHttpRequest::InitParameters(bool aAnon, bool aSystem)
}
// Check for permissions.
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(GetOwner());
if (!window || !window->GetDocShell()) {
return;
}
// Chrome is always allowed access, so do the permission check only
// for non-chrome pages.
if (!IsSystemXHR() && aSystem) {
nsCOMPtr<nsIDocument> doc = window->GetExtantDoc();
if (!doc) {
nsIGlobalObject* global = GetOwnerGlobal();
if (NS_WARN_IF(!global)) {
SetParameters(aAnon, false);
return;
}
nsIPrincipal* principal = global->PrincipalOrNull();
if (NS_WARN_IF(!principal)) {
SetParameters(aAnon, false);
return;
}
nsCOMPtr<nsIPrincipal> principal = doc->NodePrincipal();
nsCOMPtr<nsIPermissionManager> permMgr =
services::GetPermissionManager();
if (!permMgr)
if (NS_WARN_IF(!permMgr)) {
SetParameters(aAnon, false);
return;
}
uint32_t permission;
nsresult rv =
permMgr->TestPermissionFromPrincipal(principal, "systemXHR", &permission);
if (NS_FAILED(rv) || permission != nsIPermissionManager::ALLOW_ACTION) {
SetParameters(aAnon, false);
return;
}
}

View File

@ -0,0 +1,16 @@
function run_test()
{
Components.utils.importGlobalProperties(["XMLHttpRequest"]);
var x = new XMLHttpRequest({mozAnon: true, mozSystem: false});
do_check_true(x.mozAnon);
do_check_true(x.mozSystem); // Because we're system principal
x = new XMLHttpRequest({mozAnon: true});
do_check_true(x.mozAnon);
do_check_true(x.mozSystem);
x = new XMLHttpRequest();
do_check_false(x.mozAnon);
do_check_true(x.mozSystem);
}

View File

@ -23,3 +23,4 @@ skip-if = os == "android"
[test_geolocation_position_unavailable_wrap.js]
skip-if = os == "mac" || os == "android"
[test_PromiseDebugging.js]
[test_xhr_init.js]