Bug 1912810 - Don't call ShouldAllowAccessFor if GetURI returns null. r=bvandersloot

Differential Revision: https://phabricator.services.mozilla.com/D219614
This commit is contained in:
Tim Huang 2024-08-22 15:44:14 +00:00
parent 8bfa144ed7
commit 0b53a24daa

View File

@ -850,12 +850,24 @@ BasePrincipal::HasFirstpartyStorageAccess(mozIDOMWindow* aCheckWindow,
*aRejectedReason = 0;
*aOutAllowed = false;
if (IsSystemPrincipal()) {
// System principal is always considered to have first-party storage access.
*aOutAllowed = true;
return NS_OK;
}
nsPIDOMWindowInner* win = nsPIDOMWindowInner::From(aCheckWindow);
nsCOMPtr<nsIURI> uri;
nsresult rv = GetURI(getter_AddRefs(uri));
if (NS_FAILED(rv)) {
return rv;
}
// The uri could be null if the principal is an expanded principal.
if (!uri) {
return NS_ERROR_UNEXPECTED;
}
*aOutAllowed = ShouldAllowAccessFor(win, uri, aRejectedReason);
return NS_OK;
}