Bug 1715167 - Part 6: Use the unsandboxed result principal as precursor for sandbox principals, r=ckerschb,ngogge

This change stores a generated nsID directly on the LoadInfo, rather
than the full SandboxedLoadingPrincipal. This allows for the sandboxed
principal to be constructed from GetChannelResultPrincipal using the
unsandboxed result principal as a precursor, rather than the loading
principal.

The nsID is reset by HttpChannelBase whenever a non-internal redirect
occurs to reduce the chance of multiple null result principals during a
redirect with the same nsID, but different precursors.

Depends on D119692

Differential Revision: https://phabricator.services.mozilla.com/D119693
This commit is contained in:
Nika Layzell
2021-07-15 21:09:15 +00:00
parent d8df30464e
commit 3e36d2878d
11 changed files with 84 additions and 62 deletions

View File

@@ -304,10 +304,24 @@ nsresult nsScriptSecurityManager::GetChannelResultPrincipal(
}
if (!aIgnoreSandboxing && loadInfo->GetLoadingSandboxed()) {
nsCOMPtr<nsIPrincipal> sandboxedLoadingPrincipal =
loadInfo->GetSandboxedLoadingPrincipal();
MOZ_ASSERT(sandboxedLoadingPrincipal);
sandboxedLoadingPrincipal.forget(aPrincipal);
// Determine the unsandboxed result principal to use as this null
// principal's precursor. Ignore errors here, as the precursor isn't
// required.
nsCOMPtr<nsIPrincipal> precursor;
GetChannelResultPrincipal(aChannel, getter_AddRefs(precursor),
/*aIgnoreSandboxing*/ true);
// Construct a deterministic null principal URI from the precursor and the
// loadinfo's nullPrincipalID.
nsCOMPtr<nsIURI> nullPrincipalURI = NullPrincipal::CreateURI(
precursor, &loadInfo->GetSandboxedNullPrincipalID());
// Use the URI to construct the sandboxed result principal.
OriginAttributes attrs;
loadInfo->GetOriginAttributes(&attrs);
nsCOMPtr<nsIPrincipal> sandboxedPrincipal =
NullPrincipal::Create(attrs, nullPrincipalURI);
sandboxedPrincipal.forget(aPrincipal);
return NS_OK;
}