Bug 1639833 - IntrisincStoragePrincipal should always be partitioned - part 2 - Expose PartitionedPrincipal, r=dimi

Differential Revision: https://phabricator.services.mozilla.com/D76915
This commit is contained in:
Andrea Marchesini 2020-06-02 08:28:05 +00:00
Родитель 466cab1be4
Коммит e31c7313ca
55 изменённых файлов: 370 добавлений и 344 удалений

Просмотреть файл

@ -231,14 +231,15 @@ interface nsIScriptSecurityManager : nsISupports
nsIPrincipal getChannelResultStoragePrincipal(in nsIChannel aChannel); nsIPrincipal getChannelResultStoragePrincipal(in nsIChannel aChannel);
/** /**
* This method does getChannelResultPrincipal() + * This method returns 2 principals from a nsIChannel:
* getChannelResultStoragePrincipal(). * - aPrincipal is the regular principal.
* This method is mainly done for Document::Reset(). There are no other * - aPartitionedPrincipal is aPrincipal plus an isolation key in its
* reasons to use this method. * originAttributes.
* See more in StoragePrincipalHelper.h
*/ */
void getChannelResultPrincipals(in nsIChannel aChannel, void getChannelResultPrincipals(in nsIChannel aChannel,
out nsIPrincipal aPrincipal, out nsIPrincipal aPrincipal,
out nsIPrincipal aStoragePrincipal); out nsIPrincipal aPartitionedPrincipal);
/** /**
* Temporary API until bug 1220687 is fixed. * Temporary API until bug 1220687 is fixed.

Просмотреть файл

@ -251,13 +251,14 @@ nsScriptSecurityManager::GetChannelResultStoragePrincipal(
return rv; return rv;
} }
return StoragePrincipalHelper::Create(aChannel, principal, aPrincipal); return StoragePrincipalHelper::Create(
aChannel, principal, /* aForceIsolation */ false, aPrincipal);
} }
NS_IMETHODIMP NS_IMETHODIMP
nsScriptSecurityManager::GetChannelResultPrincipals( nsScriptSecurityManager::GetChannelResultPrincipals(
nsIChannel* aChannel, nsIPrincipal** aPrincipal, nsIChannel* aChannel, nsIPrincipal** aPrincipal,
nsIPrincipal** aStoragePrincipal) { nsIPrincipal** aPartitionedPrincipal) {
nsresult rv = GetChannelResultPrincipal(aChannel, aPrincipal, nsresult rv = GetChannelResultPrincipal(aChannel, aPrincipal,
/*aIgnoreSandboxing*/ false); /*aIgnoreSandboxing*/ false);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
@ -269,12 +270,12 @@ nsScriptSecurityManager::GetChannelResultPrincipals(
// principal for the storage principal too, since attempting to create a // principal for the storage principal too, since attempting to create a
// storage principal would fail anyway. // storage principal would fail anyway.
nsCOMPtr<nsIPrincipal> copy = *aPrincipal; nsCOMPtr<nsIPrincipal> copy = *aPrincipal;
copy.forget(aStoragePrincipal); copy.forget(aPartitionedPrincipal);
return NS_OK; return NS_OK;
} }
return StoragePrincipalHelper::Create(aChannel, *aPrincipal, return StoragePrincipalHelper::Create(
aStoragePrincipal); aChannel, *aPrincipal, /* aForceIsolation */ true, aPartitionedPrincipal);
} }
nsresult nsScriptSecurityManager::GetChannelResultPrincipal( nsresult nsScriptSecurityManager::GetChannelResultPrincipal(

Просмотреть файл

@ -6254,7 +6254,7 @@ nsresult nsDocShell::EnsureContentViewer() {
nsCOMPtr<nsIContentSecurityPolicy> cspToInheritForAboutBlank; nsCOMPtr<nsIContentSecurityPolicy> cspToInheritForAboutBlank;
nsCOMPtr<nsIURI> baseURI; nsCOMPtr<nsIURI> baseURI;
nsIPrincipal* principal = GetInheritedPrincipal(false); nsIPrincipal* principal = GetInheritedPrincipal(false);
nsIPrincipal* storagePrincipal = GetInheritedPrincipal(false, true); nsIPrincipal* partitionedPrincipal = GetInheritedPrincipal(false, true);
nsCOMPtr<nsIDocShellTreeItem> parentItem; nsCOMPtr<nsIDocShellTreeItem> parentItem;
GetInProcessSameTypeParent(getter_AddRefs(parentItem)); GetInProcessSameTypeParent(getter_AddRefs(parentItem));
@ -6269,7 +6269,7 @@ nsresult nsDocShell::EnsureContentViewer() {
} }
nsresult rv = CreateAboutBlankContentViewer( nsresult rv = CreateAboutBlankContentViewer(
principal, storagePrincipal, cspToInheritForAboutBlank, baseURI); principal, partitionedPrincipal, cspToInheritForAboutBlank, baseURI);
NS_ENSURE_STATE(mContentViewer); NS_ENSURE_STATE(mContentViewer);
@ -6295,7 +6295,7 @@ nsresult nsDocShell::EnsureContentViewer() {
} }
nsresult nsDocShell::CreateAboutBlankContentViewer( nsresult nsDocShell::CreateAboutBlankContentViewer(
nsIPrincipal* aPrincipal, nsIPrincipal* aStoragePrincipal, nsIPrincipal* aPrincipal, nsIPrincipal* aPartitionedPrincipal,
nsIContentSecurityPolicy* aCSP, nsIURI* aBaseURI, nsIContentSecurityPolicy* aCSP, nsIURI* aBaseURI,
bool aTryToSaveOldPresentation, bool aCheckPermitUnload, bool aTryToSaveOldPresentation, bool aCheckPermitUnload,
WindowGlobalChild* aActor) { WindowGlobalChild* aActor) {
@ -6389,7 +6389,7 @@ nsresult nsDocShell::CreateAboutBlankContentViewer(
NS_LITERAL_CSTRING("text/html")); NS_LITERAL_CSTRING("text/html"));
if (docFactory) { if (docFactory) {
nsCOMPtr<nsIPrincipal> principal, storagePrincipal; nsCOMPtr<nsIPrincipal> principal, partitionedPrincipal;
uint32_t sandboxFlags = mBrowsingContext->GetSandboxFlags(); uint32_t sandboxFlags = mBrowsingContext->GetSandboxFlags();
// If we're sandboxed, then create a new null principal. We skip // If we're sandboxed, then create a new null principal. We skip
// this if we're being created from WindowGlobalChild, since in // this if we're being created from WindowGlobalChild, since in
@ -6403,17 +6403,17 @@ nsresult nsDocShell::CreateAboutBlankContentViewer(
} else { } else {
principal = NullPrincipal::CreateWithInheritedAttributes(this); principal = NullPrincipal::CreateWithInheritedAttributes(this);
} }
storagePrincipal = principal; partitionedPrincipal = principal;
} else { } else {
principal = aPrincipal; principal = aPrincipal;
storagePrincipal = aStoragePrincipal; partitionedPrincipal = aPartitionedPrincipal;
} }
MaybeCreateInitialClientSource(principal); MaybeCreateInitialClientSource(principal);
// generate (about:blank) document to load // generate (about:blank) document to load
blankDoc = nsContentDLF::CreateBlankDocument(mLoadGroup, principal, blankDoc = nsContentDLF::CreateBlankDocument(mLoadGroup, principal,
storagePrincipal, this); partitionedPrincipal, this);
if (blankDoc) { if (blankDoc) {
// Hack: manually set the CSP for the new document // Hack: manually set the CSP for the new document
// Please create an actual copy of the CSP (do not share the same // Please create an actual copy of the CSP (do not share the same
@ -6465,9 +6465,9 @@ nsresult nsDocShell::CreateAboutBlankContentViewer(
NS_IMETHODIMP NS_IMETHODIMP
nsDocShell::CreateAboutBlankContentViewer(nsIPrincipal* aPrincipal, nsDocShell::CreateAboutBlankContentViewer(nsIPrincipal* aPrincipal,
nsIPrincipal* aStoragePrincipal, nsIPrincipal* aPartitionedPrincipal,
nsIContentSecurityPolicy* aCSP) { nsIContentSecurityPolicy* aCSP) {
return CreateAboutBlankContentViewer(aPrincipal, aStoragePrincipal, aCSP, return CreateAboutBlankContentViewer(aPrincipal, aPartitionedPrincipal, aCSP,
nullptr); nullptr);
} }
@ -6475,7 +6475,7 @@ nsresult nsDocShell::CreateContentViewerForActor(
WindowGlobalChild* aWindowActor) { WindowGlobalChild* aWindowActor) {
MOZ_ASSERT(aWindowActor); MOZ_ASSERT(aWindowActor);
// FIXME: WindowGlobalChild should provide the StoragePrincipal. // FIXME: WindowGlobalChild should provide the PartitionedPrincipal.
nsresult rv = CreateAboutBlankContentViewer( nsresult rv = CreateAboutBlankContentViewer(
aWindowActor->DocumentPrincipal(), aWindowActor->DocumentPrincipal(), aWindowActor->DocumentPrincipal(), aWindowActor->DocumentPrincipal(),
/* aCsp */ nullptr, /* aCsp */ nullptr,
@ -8365,17 +8365,18 @@ nsresult nsDocShell::HandleSameDocumentNavigation(
* recorded in session and global history. * recorded in session and global history.
*/ */
nsCOMPtr<nsIPrincipal> newURITriggeringPrincipal, newURIPrincipalToInherit, nsCOMPtr<nsIPrincipal> newURITriggeringPrincipal, newURIPrincipalToInherit,
newURIStoragePrincipalToInherit; newURIPartitionedPrincipalToInherit;
nsCOMPtr<nsIContentSecurityPolicy> newCsp; nsCOMPtr<nsIContentSecurityPolicy> newCsp;
if (mOSHE) { if (mOSHE) {
newURITriggeringPrincipal = mOSHE->GetTriggeringPrincipal(); newURITriggeringPrincipal = mOSHE->GetTriggeringPrincipal();
newURIPrincipalToInherit = mOSHE->GetPrincipalToInherit(); newURIPrincipalToInherit = mOSHE->GetPrincipalToInherit();
newURIStoragePrincipalToInherit = mOSHE->GetStoragePrincipalToInherit(); newURIPartitionedPrincipalToInherit =
mOSHE->GetPartitionedPrincipalToInherit();
newCsp = mOSHE->GetCsp(); newCsp = mOSHE->GetCsp();
} else { } else {
newURITriggeringPrincipal = aLoadState->TriggeringPrincipal(); newURITriggeringPrincipal = aLoadState->TriggeringPrincipal();
newURIPrincipalToInherit = doc->NodePrincipal(); newURIPrincipalToInherit = doc->NodePrincipal();
newURIStoragePrincipalToInherit = doc->IntrinsicStoragePrincipal(); newURIPartitionedPrincipalToInherit = doc->PartitionedPrincipal();
newCsp = doc->GetCsp(); newCsp = doc->GetCsp();
} }
// Pass true for aCloneSHChildren, since we're not // Pass true for aCloneSHChildren, since we're not
@ -8387,8 +8388,8 @@ nsresult nsDocShell::HandleSameDocumentNavigation(
// Anyway, aCloneSHChildren param is simply reflecting // Anyway, aCloneSHChildren param is simply reflecting
// doSameDocumentNavigation in this scope. // doSameDocumentNavigation in this scope.
OnNewURI(aLoadState->URI(), nullptr, newURITriggeringPrincipal, OnNewURI(aLoadState->URI(), nullptr, newURITriggeringPrincipal,
newURIPrincipalToInherit, newURIStoragePrincipalToInherit, mLoadType, newURIPrincipalToInherit, newURIPartitionedPrincipalToInherit,
newCsp, true, true, true); mLoadType, newCsp, true, true, true);
nsCOMPtr<nsIInputStream> postData; nsCOMPtr<nsIInputStream> postData;
uint32_t cacheKey = 0; uint32_t cacheKey = 0;
@ -8967,7 +8968,7 @@ bool nsDocShell::CanLoadInParentProcess(nsIURI* aURI) {
} }
nsIPrincipal* nsDocShell::GetInheritedPrincipal( nsIPrincipal* nsDocShell::GetInheritedPrincipal(
bool aConsiderCurrentDocument, bool aConsiderStoragePrincipal) { bool aConsiderCurrentDocument, bool aConsiderPartitionedPrincipal) {
RefPtr<Document> document; RefPtr<Document> document;
bool inheritedFromCurrent = false; bool inheritedFromCurrent = false;
@ -9000,8 +9001,8 @@ nsIPrincipal* nsDocShell::GetInheritedPrincipal(
//-- Get the document's principal //-- Get the document's principal
if (document) { if (document) {
nsIPrincipal* docPrincipal = aConsiderStoragePrincipal nsIPrincipal* docPrincipal = aConsiderPartitionedPrincipal
? document->IntrinsicStoragePrincipal() ? document->PartitionedPrincipal()
: document->NodePrincipal(); : document->NodePrincipal();
// Don't allow loads in typeContent docShells to inherit the system // Don't allow loads in typeContent docShells to inherit the system
@ -10024,7 +10025,7 @@ void nsDocShell::SetupReferrerInfoFromChannel(nsIChannel* aChannel) {
bool nsDocShell::OnNewURI(nsIURI* aURI, nsIChannel* aChannel, bool nsDocShell::OnNewURI(nsIURI* aURI, nsIChannel* aChannel,
nsIPrincipal* aTriggeringPrincipal, nsIPrincipal* aTriggeringPrincipal,
nsIPrincipal* aPrincipalToInherit, nsIPrincipal* aPrincipalToInherit,
nsIPrincipal* aStoragePrincipalToInherit, nsIPrincipal* aPartitionedPrincipalToInherit,
uint32_t aLoadType, nsIContentSecurityPolicy* aCsp, uint32_t aLoadType, nsIContentSecurityPolicy* aCsp,
bool aFireOnLocationChange, bool aAddToGlobalHistory, bool aFireOnLocationChange, bool aAddToGlobalHistory,
bool aCloneSHChildren) { bool aCloneSHChildren) {
@ -10189,8 +10190,9 @@ bool nsDocShell::OnNewURI(nsIURI* aURI, nsIChannel* aChannel,
* rootDocShell * rootDocShell
*/ */
(void)AddToSessionHistory(aURI, aChannel, aTriggeringPrincipal, (void)AddToSessionHistory(aURI, aChannel, aTriggeringPrincipal,
aPrincipalToInherit, aStoragePrincipalToInherit, aPrincipalToInherit,
aCsp, aCloneSHChildren, getter_AddRefs(mLSHE)); aPartitionedPrincipalToInherit, aCsp,
aCloneSHChildren, getter_AddRefs(mLSHE));
} }
} else if (GetSessionHistory() && mLSHE && mURIResultedInDocument) { } else if (GetSessionHistory() && mLSHE && mURIResultedInDocument) {
// Even if we don't add anything to SHistory, ensure the current index // Even if we don't add anything to SHistory, ensure the current index
@ -10659,7 +10661,8 @@ bool nsDocShell::ShouldAddToSessionHistory(nsIURI* aURI, nsIChannel* aChannel) {
nsresult nsDocShell::AddToSessionHistory( nsresult nsDocShell::AddToSessionHistory(
nsIURI* aURI, nsIChannel* aChannel, nsIPrincipal* aTriggeringPrincipal, nsIURI* aURI, nsIChannel* aChannel, nsIPrincipal* aTriggeringPrincipal,
nsIPrincipal* aPrincipalToInherit, nsIPrincipal* aStoragePrincipalToInherit, nsIPrincipal* aPrincipalToInherit,
nsIPrincipal* aPartitionedPrincipalToInherit,
nsIContentSecurityPolicy* aCsp, bool aCloneChildren, nsIContentSecurityPolicy* aCsp, bool aCloneChildren,
nsISHEntry** aNewEntry) { nsISHEntry** aNewEntry) {
MOZ_ASSERT(aURI, "uri is null"); MOZ_ASSERT(aURI, "uri is null");
@ -10718,7 +10721,8 @@ nsresult nsDocShell::AddToSessionHistory(
uint32_t cacheKey = 0; uint32_t cacheKey = 0;
nsCOMPtr<nsIPrincipal> triggeringPrincipal = aTriggeringPrincipal; nsCOMPtr<nsIPrincipal> triggeringPrincipal = aTriggeringPrincipal;
nsCOMPtr<nsIPrincipal> principalToInherit = aPrincipalToInherit; nsCOMPtr<nsIPrincipal> principalToInherit = aPrincipalToInherit;
nsCOMPtr<nsIPrincipal> storagePrincipalToInherit = aStoragePrincipalToInherit; nsCOMPtr<nsIPrincipal> partitionedPrincipalToInherit =
aPartitionedPrincipalToInherit;
nsCOMPtr<nsIContentSecurityPolicy> csp = aCsp; nsCOMPtr<nsIContentSecurityPolicy> csp = aCsp;
bool expired = false; // by default the page is not expired bool expired = false; // by default the page is not expired
bool discardLayoutState = false; bool discardLayoutState = false;
@ -10780,12 +10784,12 @@ nsresult nsDocShell::AddToSessionHistory(
} }
} }
if (!storagePrincipalToInherit) { if (!partitionedPrincipalToInherit) {
// XXXehsan is it correct to fall back to the principal to inherit in all // XXXehsan is it correct to fall back to the principal to inherit in all
// cases? For example, what about the cases where we are using the load // cases? For example, what about the cases where we are using the load
// info's principal to inherit? Do we need to add a similar concept to // info's principal to inherit? Do we need to add a similar concept to
// load info for storage principal? // load info for partitioned principal?
storagePrincipalToInherit = principalToInherit; partitionedPrincipalToInherit = principalToInherit;
} }
} }
@ -10828,10 +10832,10 @@ nsresult nsDocShell::AddToSessionHistory(
cacheKey, // CacheKey cacheKey, // CacheKey
mContentTypeHint, // Content-type mContentTypeHint, // Content-type
triggeringPrincipal, // Channel or provided principal triggeringPrincipal, // Channel or provided principal
principalToInherit, storagePrincipalToInherit, csp, HistoryID(), principalToInherit, partitionedPrincipalToInherit, csp,
mDynamicallyCreated, originalURI, resultPrincipalURI, HistoryID(), mDynamicallyCreated, originalURI,
loadReplace, referrerInfo, srcdoc, srcdocEntry, baseURI, resultPrincipalURI, loadReplace, referrerInfo, srcdoc,
saveLayoutState, expired); srcdocEntry, baseURI, saveLayoutState, expired);
if (root == static_cast<nsIDocShellTreeItem*>(this) && GetSessionHistory()) { if (root == static_cast<nsIDocShellTreeItem*>(this) && GetSessionHistory()) {
bool shouldPersist = ShouldAddToSessionHistory(aURI, aChannel); bool shouldPersist = ShouldAddToSessionHistory(aURI, aChannel);
@ -10894,9 +10898,10 @@ nsresult nsDocShell::LoadHistoryEntry(nsISHEntry* aEntry, uint32_t aLoadType) {
// Don't cache the presentation if we're going to just reload the // Don't cache the presentation if we're going to just reload the
// current entry. Caching would lead to trying to save the different // current entry. Caching would lead to trying to save the different
// content viewers in the same nsISHEntry object. // content viewers in the same nsISHEntry object.
rv = CreateAboutBlankContentViewer(loadState->PrincipalToInherit(), rv = CreateAboutBlankContentViewer(
loadState->StoragePrincipalToInherit(), loadState->PrincipalToInherit(),
nullptr, nullptr, aEntry != mOSHE); loadState->PartitionedPrincipalToInherit(), nullptr, nullptr,
aEntry != mOSHE);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
// The creation of the intermittent about:blank content // The creation of the intermittent about:blank content
@ -12100,7 +12105,7 @@ nsDocShell::InitOrReusePrintPreviewViewer(nsIWebBrowserPrint** aPrintPreview) {
NullPrincipal::CreateWithInheritedAttributes(this); NullPrincipal::CreateWithInheritedAttributes(this);
nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIURI> uri;
NS_NewURI(getter_AddRefs(uri), NS_LITERAL_CSTRING("about:printpreview")); NS_NewURI(getter_AddRefs(uri), NS_LITERAL_CSTRING("about:printpreview"));
// Reuse the null principal for the storage principal. // Reuse the null principal for the partitioned principal.
// XXXehsan is that the right principal to use here? // XXXehsan is that the right principal to use here?
nsresult rv = CreateAboutBlankContentViewer(principal, principal, nsresult rv = CreateAboutBlankContentViewer(principal, principal,
/* aCsp = */ nullptr, uri); /* aCsp = */ nullptr, uri);

Просмотреть файл

@ -602,7 +602,7 @@ class nsDocShell final : public nsDocLoader,
// passed in, the about:blank principal will end up being used. // passed in, the about:blank principal will end up being used.
// aCSP, if any, will be used for the new about:blank load. // aCSP, if any, will be used for the new about:blank load.
nsresult CreateAboutBlankContentViewer( nsresult CreateAboutBlankContentViewer(
nsIPrincipal* aPrincipal, nsIPrincipal* aStoragePrincipal, nsIPrincipal* aPrincipal, nsIPrincipal* aPartitionedPrincipal,
nsIContentSecurityPolicy* aCSP, nsIURI* aBaseURI, nsIContentSecurityPolicy* aCSP, nsIURI* aBaseURI,
bool aTryToSaveOldPresentation = true, bool aCheckPermitUnload = true, bool aTryToSaveOldPresentation = true, bool aCheckPermitUnload = true,
mozilla::dom::WindowGlobalChild* aActor = nullptr); mozilla::dom::WindowGlobalChild* aActor = nullptr);
@ -642,7 +642,7 @@ class nsDocShell final : public nsDocLoader,
nsresult AddToSessionHistory(nsIURI* aURI, nsIChannel* aChannel, nsresult AddToSessionHistory(nsIURI* aURI, nsIChannel* aChannel,
nsIPrincipal* aTriggeringPrincipal, nsIPrincipal* aTriggeringPrincipal,
nsIPrincipal* aPrincipalToInherit, nsIPrincipal* aPrincipalToInherit,
nsIPrincipal* aStoragePrincipalToInherit, nsIPrincipal* aPartitionedPrincipalToInherit,
nsIContentSecurityPolicy* aCsp, nsIContentSecurityPolicy* aCsp,
bool aCloneChildren, nsISHEntry** aNewEntry); bool aCloneChildren, nsISHEntry** aNewEntry);
@ -717,9 +717,10 @@ class nsDocShell final : public nsDocLoader,
bool OnNewURI(nsIURI* aURI, nsIChannel* aChannel, bool OnNewURI(nsIURI* aURI, nsIChannel* aChannel,
nsIPrincipal* aTriggeringPrincipal, nsIPrincipal* aTriggeringPrincipal,
nsIPrincipal* aPrincipalToInherit, nsIPrincipal* aPrincipalToInherit,
nsIPrincipal* aStoragePrincipalToInehrit, uint32_t aLoadType, nsIPrincipal* aPartitionedPrincipalToInehrit,
nsIContentSecurityPolicy* aCsp, bool aFireOnLocationChange, uint32_t aLoadType, nsIContentSecurityPolicy* aCsp,
bool aAddToGlobalHistory, bool aCloneSHChildren); bool aFireOnLocationChange, bool aAddToGlobalHistory,
bool aCloneSHChildren);
// Helper method that is called when a new document (including any // Helper method that is called when a new document (including any
// sub-documents - ie. frames) has been completely loaded. // sub-documents - ie. frames) has been completely loaded.
@ -757,10 +758,11 @@ class nsDocShell final : public nsDocLoader,
// If that fails too, we force creation of a content viewer and use the // If that fails too, we force creation of a content viewer and use the
// resulting principal. If aConsiderCurrentDocument is false, we just look // resulting principal. If aConsiderCurrentDocument is false, we just look
// at the parent. // at the parent.
// If aConsiderStoragePrincipal is true, we consider the storage principal // If aConsiderPartitionedPrincipal is true, we consider the partitioned
// instead of the node principal. // principal instead of the node principal.
nsIPrincipal* GetInheritedPrincipal(bool aConsiderCurrentDocument, nsIPrincipal* GetInheritedPrincipal(
bool aConsiderStoragePrincipal = false); bool aConsiderCurrentDocument,
bool aConsiderPartitionedPrincipal = false);
/** /**
* Helper function that caches a URI and a transition for saving later. * Helper function that caches a URI and a transition for saving later.

Просмотреть файл

@ -127,7 +127,7 @@ nsDocShellLoadState::nsDocShellLoadState(
mBaseURI = aLoadState.BaseURI(); mBaseURI = aLoadState.BaseURI();
mTriggeringPrincipal = aLoadState.TriggeringPrincipal(); mTriggeringPrincipal = aLoadState.TriggeringPrincipal();
mPrincipalToInherit = aLoadState.PrincipalToInherit(); mPrincipalToInherit = aLoadState.PrincipalToInherit();
mStoragePrincipalToInherit = aLoadState.StoragePrincipalToInherit(); mPartitionedPrincipalToInherit = aLoadState.PartitionedPrincipalToInherit();
mCsp = aLoadState.Csp(); mCsp = aLoadState.Csp();
mOriginalURIString = aLoadState.OriginalURIString(); mOriginalURIString = aLoadState.OriginalURIString();
mCancelContentJSEpoch = aLoadState.CancelContentJSEpoch(); mCancelContentJSEpoch = aLoadState.CancelContentJSEpoch();
@ -150,7 +150,7 @@ nsDocShellLoadState::nsDocShellLoadState(const nsDocShellLoadState& aOther)
mInheritPrincipal(aOther.mInheritPrincipal), mInheritPrincipal(aOther.mInheritPrincipal),
mPrincipalIsExplicit(aOther.mPrincipalIsExplicit), mPrincipalIsExplicit(aOther.mPrincipalIsExplicit),
mPrincipalToInherit(aOther.mPrincipalToInherit), mPrincipalToInherit(aOther.mPrincipalToInherit),
mStoragePrincipalToInherit(aOther.mStoragePrincipalToInherit), mPartitionedPrincipalToInherit(aOther.mPartitionedPrincipalToInherit),
mForceAllowDataURI(aOther.mForceAllowDataURI), mForceAllowDataURI(aOther.mForceAllowDataURI),
mOriginalFrameSrc(aOther.mOriginalFrameSrc), mOriginalFrameSrc(aOther.mOriginalFrameSrc),
mIsFormSubmission(aOther.mIsFormSubmission), mIsFormSubmission(aOther.mIsFormSubmission),
@ -432,13 +432,13 @@ void nsDocShellLoadState::SetPrincipalToInherit(
mPrincipalToInherit = aPrincipalToInherit; mPrincipalToInherit = aPrincipalToInherit;
} }
nsIPrincipal* nsDocShellLoadState::StoragePrincipalToInherit() const { nsIPrincipal* nsDocShellLoadState::PartitionedPrincipalToInherit() const {
return mStoragePrincipalToInherit; return mPartitionedPrincipalToInherit;
} }
void nsDocShellLoadState::SetStoragePrincipalToInherit( void nsDocShellLoadState::SetPartitionedPrincipalToInherit(
nsIPrincipal* aStoragePrincipalToInherit) { nsIPrincipal* aPartitionedPrincipalToInherit) {
mStoragePrincipalToInherit = aStoragePrincipalToInherit; mPartitionedPrincipalToInherit = aPartitionedPrincipalToInherit;
} }
void nsDocShellLoadState::SetCsp(nsIContentSecurityPolicy* aCsp) { void nsDocShellLoadState::SetCsp(nsIContentSecurityPolicy* aCsp) {
@ -885,7 +885,7 @@ DocShellLoadStateInit nsDocShellLoadState::Serialize() {
loadState.BaseURI() = mBaseURI; loadState.BaseURI() = mBaseURI;
loadState.TriggeringPrincipal() = mTriggeringPrincipal; loadState.TriggeringPrincipal() = mTriggeringPrincipal;
loadState.PrincipalToInherit() = mPrincipalToInherit; loadState.PrincipalToInherit() = mPrincipalToInherit;
loadState.StoragePrincipalToInherit() = mStoragePrincipalToInherit; loadState.PartitionedPrincipalToInherit() = mPartitionedPrincipalToInherit;
loadState.Csp() = mCsp; loadState.Csp() = mCsp;
loadState.OriginalURIString() = mOriginalURIString; loadState.OriginalURIString() = mOriginalURIString;
loadState.CancelContentJSEpoch() = mCancelContentJSEpoch; loadState.CancelContentJSEpoch() = mCancelContentJSEpoch;

Просмотреть файл

@ -85,9 +85,10 @@ class nsDocShellLoadState final {
void SetPrincipalToInherit(nsIPrincipal* aPrincipalToInherit); void SetPrincipalToInherit(nsIPrincipal* aPrincipalToInherit);
nsIPrincipal* StoragePrincipalToInherit() const; nsIPrincipal* PartitionedPrincipalToInherit() const;
void SetStoragePrincipalToInherit(nsIPrincipal* aStoragePrincipalToInherit); void SetPartitionedPrincipalToInherit(
nsIPrincipal* aPartitionedPrincipalToInherit);
bool LoadReplace() const; bool LoadReplace() const;
@ -332,7 +333,7 @@ class nsDocShellLoadState final {
nsCOMPtr<nsIPrincipal> mPrincipalToInherit; nsCOMPtr<nsIPrincipal> mPrincipalToInherit;
nsCOMPtr<nsIPrincipal> mStoragePrincipalToInherit; nsCOMPtr<nsIPrincipal> mPartitionedPrincipalToInherit;
// If this attribute is true, then a top-level navigation // If this attribute is true, then a top-level navigation
// to a data URI will be allowed. // to a data URI will be allowed.

Просмотреть файл

@ -545,11 +545,12 @@ interface nsIDocShell : nsIDocShellTreeItem
/** /**
* Create a new about:blank document and content viewer. * Create a new about:blank document and content viewer.
* @param aPrincipal the principal to use for the new document. * @param aPrincipal the principal to use for the new document.
* @param aStoragePrincipal the storage principal to use for the new document. * @param aPartitionedPrincipal the partitioned principal to use for the new
* document.
* @param aCsp the CSP to use for the new document. * @param aCsp the CSP to use for the new document.
*/ */
void createAboutBlankContentViewer(in nsIPrincipal aPrincipal, void createAboutBlankContentViewer(in nsIPrincipal aPrincipal,
in nsIPrincipal aStoragePrincipal, in nsIPrincipal aPartitionedPrincipal,
[optional] in nsIContentSecurityPolicy aCSP); [optional] in nsIContentSecurityPolicy aCSP);
/** /**

Просмотреть файл

@ -47,8 +47,8 @@ SessionHistoryEntry::SessionHistoryEntry(nsISHistory* aSessionHistory,
mID(++gEntryID) { mID(++gEntryID) {
mSharedInfo->mTriggeringPrincipal = aLoadState->TriggeringPrincipal(); mSharedInfo->mTriggeringPrincipal = aLoadState->TriggeringPrincipal();
mSharedInfo->mPrincipalToInherit = aLoadState->PrincipalToInherit(); mSharedInfo->mPrincipalToInherit = aLoadState->PrincipalToInherit();
mSharedInfo->mStoragePrincipalToInherit = mSharedInfo->mPartitionedPrincipalToInherit =
aLoadState->StoragePrincipalToInherit(); aLoadState->PartitionedPrincipalToInherit();
mSharedInfo->mCsp = aLoadState->Csp(); mSharedInfo->mCsp = aLoadState->Csp();
// FIXME Set remaining shared fields! // FIXME Set remaining shared fields!
} }
@ -348,18 +348,18 @@ SessionHistoryEntry::SetPrincipalToInherit(nsIPrincipal* aPrincipalToInherit) {
} }
NS_IMETHODIMP NS_IMETHODIMP
SessionHistoryEntry::GetStoragePrincipalToInherit( SessionHistoryEntry::GetPartitionedPrincipalToInherit(
nsIPrincipal** aStoragePrincipalToInherit) { nsIPrincipal** aPartitionedPrincipalToInherit) {
nsCOMPtr<nsIPrincipal> storagePrincipalToInherit = nsCOMPtr<nsIPrincipal> partitionedPrincipalToInherit =
mSharedInfo->mStoragePrincipalToInherit; mSharedInfo->mPartitionedPrincipalToInherit;
storagePrincipalToInherit.forget(aStoragePrincipalToInherit); partitionedPrincipalToInherit.forget(aPartitionedPrincipalToInherit);
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
SessionHistoryEntry::SetStoragePrincipalToInherit( SessionHistoryEntry::SetPartitionedPrincipalToInherit(
nsIPrincipal* aStoragePrincipalToInherit) { nsIPrincipal* aPartitionedPrincipalToInherit) {
mSharedInfo->mStoragePrincipalToInherit = aStoragePrincipalToInherit; mSharedInfo->mPartitionedPrincipalToInherit = aPartitionedPrincipalToInherit;
return NS_OK; return NS_OK;
} }
@ -553,11 +553,11 @@ SessionHistoryEntry::Create(
nsIURI* aURI, const nsAString& aTitle, nsIInputStream* aInputStream, nsIURI* aURI, const nsAString& aTitle, nsIInputStream* aInputStream,
uint32_t aCacheKey, const nsACString& aContentType, uint32_t aCacheKey, const nsACString& aContentType,
nsIPrincipal* aTriggeringPrincipal, nsIPrincipal* aPrincipalToInherit, nsIPrincipal* aTriggeringPrincipal, nsIPrincipal* aPrincipalToInherit,
nsIPrincipal* aStoragePrincipalToInherit, nsIContentSecurityPolicy* aCsp, nsIPrincipal* aPartitionedPrincipalToInherit,
const nsID& aDocshellID, bool aDynamicCreation, nsIURI* aOriginalURI, nsIContentSecurityPolicy* aCsp, const nsID& aDocshellID,
nsIURI* aResultPrincipalURI, bool aLoadReplace, bool aDynamicCreation, nsIURI* aOriginalURI, nsIURI* aResultPrincipalURI,
nsIReferrerInfo* aReferrerInfo, const nsAString& aSrcdoc, bool aSrcdocEntry, bool aLoadReplace, nsIReferrerInfo* aReferrerInfo, const nsAString& aSrcdoc,
nsIURI* aBaseURI, bool aSaveLayoutState, bool aExpired) { bool aSrcdocEntry, nsIURI* aBaseURI, bool aSaveLayoutState, bool aExpired) {
MOZ_CRASH("Might need to implement this"); MOZ_CRASH("Might need to implement this");
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
} }
@ -690,8 +690,8 @@ SessionHistoryEntry::CreateLoadInfo(nsDocShellLoadState** aLoadState) {
loadState->SetTypeHint(mSharedInfo->mContentType); loadState->SetTypeHint(mSharedInfo->mContentType);
loadState->SetTriggeringPrincipal(mSharedInfo->mTriggeringPrincipal); loadState->SetTriggeringPrincipal(mSharedInfo->mTriggeringPrincipal);
loadState->SetPrincipalToInherit(mSharedInfo->mPrincipalToInherit); loadState->SetPrincipalToInherit(mSharedInfo->mPrincipalToInherit);
loadState->SetStoragePrincipalToInherit( loadState->SetPartitionedPrincipalToInherit(
mSharedInfo->mStoragePrincipalToInherit); mSharedInfo->mPartitionedPrincipalToInherit);
loadState->SetCsp(mSharedInfo->mCsp); loadState->SetCsp(mSharedInfo->mCsp);
// Do not inherit principal from document (security-critical!); // Do not inherit principal from document (security-critical!);

Просмотреть файл

@ -164,7 +164,7 @@ interface nsISHEntry : nsISupports
* Get the storage principal, if any, that is used when the inherit flag is * Get the storage principal, if any, that is used when the inherit flag is
* set. * set.
*/ */
[infallible] attribute nsIPrincipal storagePrincipalToInherit; [infallible] attribute nsIPrincipal partitionedPrincipalToInherit;
/** /**
* Get the csp, if any, that was used for this document load. That * Get the csp, if any, that was used for this document load. That
@ -298,7 +298,7 @@ interface nsISHEntry : nsISupports
in ACString contentType, in ACString contentType,
in nsIPrincipal triggeringPrincipal, in nsIPrincipal triggeringPrincipal,
in nsIPrincipal principalToInherit, in nsIPrincipal principalToInherit,
in nsIPrincipal storagePrincipalToInherit, in nsIPrincipal partitionedPrincipalToInherit,
in nsIContentSecurityPolicy aCsp, in nsIContentSecurityPolicy aCsp,
in nsIDRef docshellID, in nsIDRef docshellID,
in boolean dynamicCreation, in boolean dynamicCreation,

Просмотреть файл

@ -323,15 +323,18 @@ nsSHEntry::SetContentType(const nsACString& aContentType) {
} }
NS_IMETHODIMP NS_IMETHODIMP
nsSHEntry::Create( nsSHEntry::Create(nsIURI* aURI, const nsAString& aTitle,
nsIURI* aURI, const nsAString& aTitle, nsIInputStream* aInputStream, nsIInputStream* aInputStream, uint32_t aCacheKey,
uint32_t aCacheKey, const nsACString& aContentType, const nsACString& aContentType,
nsIPrincipal* aTriggeringPrincipal, nsIPrincipal* aPrincipalToInherit, nsIPrincipal* aTriggeringPrincipal,
nsIPrincipal* aStoragePrincipalToInherit, nsIContentSecurityPolicy* aCsp, nsIPrincipal* aPrincipalToInherit,
const nsID& aDocShellID, bool aDynamicCreation, nsIURI* aOriginalURI, nsIPrincipal* aPartitionedPrincipalToInherit,
nsIURI* aResultPrincipalURI, bool aLoadReplace, nsIContentSecurityPolicy* aCsp, const nsID& aDocShellID,
nsIReferrerInfo* aReferrerInfo, const nsAString& aSrcdocData, bool aDynamicCreation, nsIURI* aOriginalURI,
bool aSrcdocEntry, nsIURI* aBaseURI, bool aSaveLayoutState, bool aExpired) { nsIURI* aResultPrincipalURI, bool aLoadReplace,
nsIReferrerInfo* aReferrerInfo, const nsAString& aSrcdocData,
bool aSrcdocEntry, nsIURI* aBaseURI, bool aSaveLayoutState,
bool aExpired) {
MOZ_ASSERT( MOZ_ASSERT(
aTriggeringPrincipal, aTriggeringPrincipal,
"need a valid triggeringPrincipal to create a session history entry"); "need a valid triggeringPrincipal to create a session history entry");
@ -347,7 +350,7 @@ nsSHEntry::Create(
mShared->mContentType = aContentType; mShared->mContentType = aContentType;
mShared->mTriggeringPrincipal = aTriggeringPrincipal; mShared->mTriggeringPrincipal = aTriggeringPrincipal;
mShared->mPrincipalToInherit = aPrincipalToInherit; mShared->mPrincipalToInherit = aPrincipalToInherit;
mShared->mStoragePrincipalToInherit = aStoragePrincipalToInherit; mShared->mPartitionedPrincipalToInherit = aPartitionedPrincipalToInherit;
mShared->mCsp = aCsp; mShared->mCsp = aCsp;
mShared->mDocShellID = aDocShellID; mShared->mDocShellID = aDocShellID;
mShared->mDynamicallyCreated = aDynamicCreation; mShared->mDynamicallyCreated = aDynamicCreation;
@ -431,17 +434,17 @@ nsSHEntry::SetPrincipalToInherit(nsIPrincipal* aPrincipalToInherit) {
} }
NS_IMETHODIMP NS_IMETHODIMP
nsSHEntry::GetStoragePrincipalToInherit( nsSHEntry::GetPartitionedPrincipalToInherit(
nsIPrincipal** aStoragePrincipalToInherit) { nsIPrincipal** aPartitionedPrincipalToInherit) {
NS_IF_ADDREF(*aStoragePrincipalToInherit = NS_IF_ADDREF(*aPartitionedPrincipalToInherit =
mShared->mStoragePrincipalToInherit); mShared->mPartitionedPrincipalToInherit);
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsSHEntry::SetStoragePrincipalToInherit( nsSHEntry::SetPartitionedPrincipalToInherit(
nsIPrincipal* aStoragePrincipalToInherit) { nsIPrincipal* aPartitionedPrincipalToInherit) {
mShared->mStoragePrincipalToInherit = aStoragePrincipalToInherit; mShared->mPartitionedPrincipalToInherit = aPartitionedPrincipalToInherit;
return NS_OK; return NS_OK;
} }
@ -849,9 +852,9 @@ nsSHEntry::CreateLoadInfo(nsDocShellLoadState** aLoadState) {
loadState->SetTriggeringPrincipal(triggeringPrincipal); loadState->SetTriggeringPrincipal(triggeringPrincipal);
nsCOMPtr<nsIPrincipal> principalToInherit = GetPrincipalToInherit(); nsCOMPtr<nsIPrincipal> principalToInherit = GetPrincipalToInherit();
loadState->SetPrincipalToInherit(principalToInherit); loadState->SetPrincipalToInherit(principalToInherit);
nsCOMPtr<nsIPrincipal> storagePrincipalToInherit = nsCOMPtr<nsIPrincipal> partitionedPrincipalToInherit =
GetStoragePrincipalToInherit(); GetPartitionedPrincipalToInherit();
loadState->SetStoragePrincipalToInherit(storagePrincipalToInherit); loadState->SetPartitionedPrincipalToInherit(partitionedPrincipalToInherit);
nsCOMPtr<nsIContentSecurityPolicy> csp = GetCsp(); nsCOMPtr<nsIContentSecurityPolicy> csp = GetCsp();
loadState->SetCsp(csp); loadState->SetCsp(csp);
nsCOMPtr<nsIReferrerInfo> referrerInfo = GetReferrerInfo(); nsCOMPtr<nsIReferrerInfo> referrerInfo = GetReferrerInfo();

Просмотреть файл

@ -51,7 +51,7 @@ void SHEntrySharedParentState::CopyFrom(SHEntrySharedParentState* aEntry) {
mDocShellID = aEntry->mDocShellID; mDocShellID = aEntry->mDocShellID;
mTriggeringPrincipal = aEntry->mTriggeringPrincipal; mTriggeringPrincipal = aEntry->mTriggeringPrincipal;
mPrincipalToInherit = aEntry->mPrincipalToInherit; mPrincipalToInherit = aEntry->mPrincipalToInherit;
mStoragePrincipalToInherit = aEntry->mStoragePrincipalToInherit; mPartitionedPrincipalToInherit = aEntry->mPartitionedPrincipalToInherit;
mCsp = aEntry->mCsp; mCsp = aEntry->mCsp;
mSaveLayoutState = aEntry->mSaveLayoutState; mSaveLayoutState = aEntry->mSaveLayoutState;
mContentType.Assign(aEntry->mContentType); mContentType.Assign(aEntry->mContentType);

Просмотреть файл

@ -72,7 +72,7 @@ class SHEntrySharedParentState {
nsID mDocShellID; nsID mDocShellID;
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal; nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
nsCOMPtr<nsIPrincipal> mPrincipalToInherit; nsCOMPtr<nsIPrincipal> mPrincipalToInherit;
nsCOMPtr<nsIPrincipal> mStoragePrincipalToInherit; nsCOMPtr<nsIPrincipal> mPartitionedPrincipalToInherit;
nsCOMPtr<nsIContentSecurityPolicy> mCsp; nsCOMPtr<nsIContentSecurityPolicy> mCsp;
// Child side updates layout history state when page is being unloaded or // Child side updates layout history state when page is being unloaded or
// moved to bfcache. // moved to bfcache.

Просмотреть файл

@ -2412,7 +2412,7 @@ bool Document::IsVisibleConsideringAncestors() const {
void Document::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) { void Document::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) {
nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIURI> uri;
nsCOMPtr<nsIPrincipal> principal; nsCOMPtr<nsIPrincipal> principal;
nsCOMPtr<nsIPrincipal> storagePrincipal; nsCOMPtr<nsIPrincipal> partitionedPrincipal;
if (aChannel) { if (aChannel) {
// Note: this code is duplicated in PrototypeDocumentContentSink::Init and // Note: this code is duplicated in PrototypeDocumentContentSink::Init and
// nsScriptSecurityManager::GetChannelResultPrincipals. // nsScriptSecurityManager::GetChannelResultPrincipals.
@ -2425,20 +2425,20 @@ void Document::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) {
if (securityManager) { if (securityManager) {
securityManager->GetChannelResultPrincipals( securityManager->GetChannelResultPrincipals(
aChannel, getter_AddRefs(principal), aChannel, getter_AddRefs(principal),
getter_AddRefs(storagePrincipal)); getter_AddRefs(partitionedPrincipal));
} }
} }
bool equal = principal->Equals(storagePrincipal); bool equal = principal->Equals(partitionedPrincipal);
principal = MaybeDowngradePrincipal(principal); principal = MaybeDowngradePrincipal(principal);
if (equal) { if (equal) {
storagePrincipal = principal; partitionedPrincipal = principal;
} else { } else {
storagePrincipal = MaybeDowngradePrincipal(storagePrincipal); partitionedPrincipal = MaybeDowngradePrincipal(partitionedPrincipal);
} }
ResetToURI(uri, aLoadGroup, principal, storagePrincipal); ResetToURI(uri, aLoadGroup, principal, partitionedPrincipal);
// Note that, since mTiming does not change during a reset, the // Note that, since mTiming does not change during a reset, the
// navigationStart time remains unchanged and therefore any future new // navigationStart time remains unchanged and therefore any future new
@ -2500,9 +2500,9 @@ void Document::DisconnectNodeTree() {
void Document::ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup, void Document::ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup,
nsIPrincipal* aPrincipal, nsIPrincipal* aPrincipal,
nsIPrincipal* aStoragePrincipal) { nsIPrincipal* aPartitionedPrincipal) {
MOZ_ASSERT(aURI, "Null URI passed to ResetToURI"); MOZ_ASSERT(aURI, "Null URI passed to ResetToURI");
MOZ_ASSERT(!!aPrincipal == !!aStoragePrincipal); MOZ_ASSERT(!!aPrincipal == !!aPartitionedPrincipal);
MOZ_LOG(gDocumentLeakPRLog, LogLevel::Debug, MOZ_LOG(gDocumentLeakPRLog, LogLevel::Debug,
("DOCUMENT %p ResetToURI %s", this, aURI->GetSpecOrDefault().get())); ("DOCUMENT %p ResetToURI %s", this, aURI->GetSpecOrDefault().get()));
@ -2587,7 +2587,7 @@ void Document::ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup,
// Now get our new principal // Now get our new principal
if (aPrincipal) { if (aPrincipal) {
SetPrincipals(aPrincipal, aStoragePrincipal); SetPrincipals(aPrincipal, aPartitionedPrincipal);
} else { } else {
nsIScriptSecurityManager* securityManager = nsIScriptSecurityManager* securityManager =
nsContentUtils::GetSecurityManager(); nsContentUtils::GetSecurityManager();
@ -3717,8 +3717,8 @@ void Document::RemoveFromIdTable(Element* aElement, nsAtom* aId) {
} }
void Document::SetPrincipals(nsIPrincipal* aNewPrincipal, void Document::SetPrincipals(nsIPrincipal* aNewPrincipal,
nsIPrincipal* aNewStoragePrincipal) { nsIPrincipal* aNewPartitionedPrincipal) {
MOZ_ASSERT(!!aNewPrincipal == !!aNewStoragePrincipal); MOZ_ASSERT(!!aNewPrincipal == !!aNewPartitionedPrincipal);
if (aNewPrincipal && mAllowDNSPrefetch && if (aNewPrincipal && mAllowDNSPrefetch &&
StaticPrefs::network_dns_disablePrefetchFromHTTPS()) { StaticPrefs::network_dns_disablePrefetchFromHTTPS()) {
if (aNewPrincipal->SchemeIs("https")) { if (aNewPrincipal->SchemeIs("https")) {
@ -3726,7 +3726,7 @@ void Document::SetPrincipals(nsIPrincipal* aNewPrincipal,
} }
} }
mNodeInfoManager->SetDocumentPrincipal(aNewPrincipal); mNodeInfoManager->SetDocumentPrincipal(aNewPrincipal);
mIntrinsicStoragePrincipal = aNewStoragePrincipal; mPartitionedPrincipal = aNewPartitionedPrincipal;
ContentBlockingAllowList::ComputePrincipal( ContentBlockingAllowList::ComputePrincipal(
aNewPrincipal, getter_AddRefs(mContentBlockingAllowListPrincipal)); aNewPrincipal, getter_AddRefs(mContentBlockingAllowListPrincipal));
@ -11057,8 +11057,7 @@ nsresult Document::CloneDocHelper(Document* clone) const {
} }
clone->mChannel = channel; clone->mChannel = channel;
if (uri) { if (uri) {
clone->ResetToURI(uri, loadGroup, NodePrincipal(), clone->ResetToURI(uri, loadGroup, NodePrincipal(), mPartitionedPrincipal);
EffectiveStoragePrincipal());
} }
clone->SetContainer(mDocumentContainer); clone->SetContainer(mDocumentContainer);
@ -11082,7 +11081,7 @@ nsresult Document::CloneDocHelper(Document* clone) const {
// them. // them.
clone->SetDocumentURI(Document::GetDocumentURI()); clone->SetDocumentURI(Document::GetDocumentURI());
clone->SetChromeXHRDocURI(mChromeXHRDocURI); clone->SetChromeXHRDocURI(mChromeXHRDocURI);
clone->SetPrincipals(NodePrincipal(), mIntrinsicStoragePrincipal); clone->SetPrincipals(NodePrincipal(), mPartitionedPrincipal);
clone->mActiveStoragePrincipal = mActiveStoragePrincipal; clone->mActiveStoragePrincipal = mActiveStoragePrincipal;
clone->mDocumentBaseURI = mDocumentBaseURI; clone->mDocumentBaseURI = mDocumentBaseURI;
clone->SetChromeXHRDocBaseURI(mChromeXHRDocBaseURI); clone->SetChromeXHRDocBaseURI(mChromeXHRDocBaseURI);
@ -16302,7 +16301,7 @@ nsIPrincipal* Document::EffectiveStoragePrincipal() const {
return mActiveStoragePrincipal = NodePrincipal(); return mActiveStoragePrincipal = NodePrincipal();
} }
return mActiveStoragePrincipal = mIntrinsicStoragePrincipal; return mActiveStoragePrincipal = mPartitionedPrincipal;
} }
void Document::SetIsInitialDocument(bool aIsInitialDocument) { void Document::SetIsInitialDocument(bool aIsInitialDocument) {

Просмотреть файл

@ -578,13 +578,11 @@ class Document : public nsINode,
return EffectiveStoragePrincipal(); return EffectiveStoragePrincipal();
} }
// You should probably not be using this function, since it performs no // You should probably not be using this function, since it performs no checks
// checks to ensure that the intrinsic storage principal should really be // to ensure that the partitioned principal should really be used here. It is
// used here. It is only designed to be used in very specific circumstances, // only designed to be used in very specific circumstances, such as when
// such as when inheriting the document/storage principal. // inheriting the document/storage principal.
nsIPrincipal* IntrinsicStoragePrincipal() final { nsIPrincipal* PartitionedPrincipal() final { return mPartitionedPrincipal; }
return mIntrinsicStoragePrincipal;
}
void ClearActiveStoragePrincipal() { mActiveStoragePrincipal = nullptr; } void ClearActiveStoragePrincipal() { mActiveStoragePrincipal = nullptr; }
@ -855,7 +853,8 @@ class Document : public nsINode,
* Set the principals responsible for this document. Chances are, you do not * Set the principals responsible for this document. Chances are, you do not
* want to be using this. * want to be using this.
*/ */
void SetPrincipals(nsIPrincipal* aPrincipal, nsIPrincipal* aStoragePrincipal); void SetPrincipals(nsIPrincipal* aPrincipal,
nsIPrincipal* aPartitionedPrincipal);
/** /**
* Get the list of ancestor principals for a document. This is the same as * Get the list of ancestor principals for a document. This is the same as
@ -2089,13 +2088,13 @@ class Document : public nsINode,
virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup); virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup);
/** /**
* Reset this document to aURI, aLoadGroup, aPrincipal and aStoragePrincipal. * Reset this document to aURI, aLoadGroup, aPrincipal and
* aURI must not be null. If aPrincipal is null, a content principal based * aPartitionedPrincipal. aURI must not be null. If aPrincipal is null, a
* on aURI will be used. * content principal based on aURI will be used.
*/ */
virtual void ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup, virtual void ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup,
nsIPrincipal* aPrincipal, nsIPrincipal* aPrincipal,
nsIPrincipal* aStoragePrincipal); nsIPrincipal* aPartitionedPrincipal);
/** /**
* Set the container (docshell) for this document. Virtual so that * Set the container (docshell) for this document. Virtual so that
@ -5045,8 +5044,9 @@ class Document : public nsINode,
int32_t mCachedTabSizeGeneration; int32_t mCachedTabSizeGeneration;
nsTabSizes mCachedTabSizes; nsTabSizes mCachedTabSizes;
// The principal to use for the storage area of this document. // This is equal to document's principal but with an isolation key. See
nsCOMPtr<nsIPrincipal> mIntrinsicStoragePrincipal; // StoragePrincipalHelper.h to know more.
nsCOMPtr<nsIPrincipal> mPartitionedPrincipal;
// The cached storage principal for this document. // The cached storage principal for this document.
// This is mutable so that we can keep EffectiveStoragePrincipal() const // This is mutable so that we can keep EffectiveStoragePrincipal() const

Просмотреть файл

@ -1099,7 +1099,7 @@ void nsGlobalWindowInner::FreeInnerObjects() {
// Remember the document's principal, URI, and CSP. // Remember the document's principal, URI, and CSP.
mDocumentPrincipal = mDoc->NodePrincipal(); mDocumentPrincipal = mDoc->NodePrincipal();
mDocumentStoragePrincipal = mDoc->EffectiveStoragePrincipal(); mDocumentStoragePrincipal = mDoc->EffectiveStoragePrincipal();
mDocumentIntrinsicStoragePrincipal = mDoc->IntrinsicStoragePrincipal(); mDocumentPartitionedPrincipal = mDoc->PartitionedPrincipal();
mDocumentURI = mDoc->GetDocumentURI(); mDocumentURI = mDoc->GetDocumentURI();
mDocBaseURI = mDoc->GetDocBaseURI(); mDocBaseURI = mDoc->GetDocBaseURI();
mDocContentBlockingAllowListPrincipal = mDocContentBlockingAllowListPrincipal =
@ -1327,7 +1327,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindowInner)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIndexedDB) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIndexedDB)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentPrincipal) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentPrincipal)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentStoragePrincipal) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentStoragePrincipal)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentIntrinsicStoragePrincipal) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentPartitionedPrincipal)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentCsp) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentCsp)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBrowserChild) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBrowserChild)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDoc) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDoc)
@ -1434,7 +1434,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindowInner)
} }
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentPrincipal) NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentPrincipal)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentStoragePrincipal) NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentStoragePrincipal)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentIntrinsicStoragePrincipal) NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentPartitionedPrincipal)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentCsp) NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentCsp)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mBrowserChild) NS_IMPL_CYCLE_COLLECTION_UNLINK(mBrowserChild)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDoc) NS_IMPL_CYCLE_COLLECTION_UNLINK(mDoc)
@ -2102,24 +2102,24 @@ nsIPrincipal* nsGlobalWindowInner::GetEffectiveStoragePrincipal() {
return nullptr; return nullptr;
} }
nsIPrincipal* nsGlobalWindowInner::IntrinsicStoragePrincipal() { nsIPrincipal* nsGlobalWindowInner::PartitionedPrincipal() {
if (mDoc) { if (mDoc) {
// If we have a document, get the principal from the document // If we have a document, get the principal from the document
return mDoc->EffectiveStoragePrincipal(); return mDoc->PartitionedPrincipal();
} }
if (mDocumentIntrinsicStoragePrincipal) { if (mDocumentPartitionedPrincipal) {
return mDocumentIntrinsicStoragePrincipal; return mDocumentPartitionedPrincipal;
} }
// If we don't have a storage principal and we don't have a document we ask // If we don't have a partitioned principal and we don't have a document we
// the parent window for the storage principal. // ask the parent window for the partitioned principal.
nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal = nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal =
do_QueryInterface(GetInProcessParentInternal()); do_QueryInterface(GetInProcessParentInternal());
if (objPrincipal) { if (objPrincipal) {
return objPrincipal->IntrinsicStoragePrincipal(); return objPrincipal->PartitionedPrincipal();
} }
return nullptr; return nullptr;
@ -4346,10 +4346,10 @@ already_AddRefed<nsICSSDeclaration> nsGlobalWindowInner::GetComputedStyleHelper(
Storage* nsGlobalWindowInner::GetSessionStorage(ErrorResult& aError) { Storage* nsGlobalWindowInner::GetSessionStorage(ErrorResult& aError) {
nsIPrincipal* principal = GetPrincipal(); nsIPrincipal* principal = GetPrincipal();
nsIPrincipal* storagePrincipal = IntrinsicStoragePrincipal(); nsIPrincipal* partitionedPrincipal = PartitionedPrincipal();
BrowsingContext* browsingContext = GetBrowsingContext(); BrowsingContext* browsingContext = GetBrowsingContext();
if (!principal || !storagePrincipal || !browsingContext || if (!principal || !partitionedPrincipal || !browsingContext ||
!Storage::StoragePrefIsEnabled()) { !Storage::StoragePrefIsEnabled()) {
return nullptr; return nullptr;
} }
@ -4360,7 +4360,7 @@ Storage* nsGlobalWindowInner::GetSessionStorage(ErrorResult& aError) {
mSessionStorage.get())); mSessionStorage.get()));
bool canAccess = bool canAccess =
principal->Subsumes(mSessionStorage->Principal()) && principal->Subsumes(mSessionStorage->Principal()) &&
storagePrincipal->Subsumes(mSessionStorage->StoragePrincipal()); partitionedPrincipal->Subsumes(mSessionStorage->StoragePrincipal());
if (!canAccess) { if (!canAccess) {
mSessionStorage = nullptr; mSessionStorage = nullptr;
} }
@ -4438,9 +4438,9 @@ Storage* nsGlobalWindowInner::GetSessionStorage(ErrorResult& aError) {
} }
RefPtr<Storage> storage; RefPtr<Storage> storage;
aError = storageManager->CreateStorage(this, principal, storagePrincipal, aError = storageManager->CreateStorage(
documentURI, IsPrivateBrowsing(), this, principal, partitionedPrincipal, documentURI, IsPrivateBrowsing(),
getter_AddRefs(storage)); getter_AddRefs(storage));
if (aError.Failed()) { if (aError.Failed()) {
return nullptr; return nullptr;
} }
@ -5023,11 +5023,6 @@ void nsGlobalWindowInner::ObserveStorageNotification(
return; return;
} }
nsIPrincipal* storagePrincipal = GetEffectiveStoragePrincipal();
if (!storagePrincipal) {
return;
}
bool fireMozStorageChanged = false; bool fireMozStorageChanged = false;
nsAutoString eventType; nsAutoString eventType;
eventType.AssignLiteral("storage"); eventType.AssignLiteral("storage");
@ -5040,7 +5035,7 @@ void nsGlobalWindowInner::ObserveStorageNotification(
if (const RefPtr<SessionStorageManager> storageManager = if (const RefPtr<SessionStorageManager> storageManager =
GetBrowsingContext()->GetSessionStorageManager()) { GetBrowsingContext()->GetSessionStorageManager()) {
nsresult rv = storageManager->CheckStorage(storagePrincipal, nsresult rv = storageManager->CheckStorage(PartitionedPrincipal(),
changingStorage, &check); changingStorage, &check);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
return; return;
@ -5067,6 +5062,11 @@ void nsGlobalWindowInner::ObserveStorageNotification(
else { else {
MOZ_ASSERT(!NS_strcmp(aStorageType, u"localStorage")); MOZ_ASSERT(!NS_strcmp(aStorageType, u"localStorage"));
nsIPrincipal* storagePrincipal = GetEffectiveStoragePrincipal();
if (!storagePrincipal) {
return;
}
MOZ_DIAGNOSTIC_ASSERT(StorageUtils::PrincipalsEqual(aEvent->GetPrincipal(), MOZ_DIAGNOSTIC_ASSERT(StorageUtils::PrincipalsEqual(aEvent->GetPrincipal(),
storagePrincipal)); storagePrincipal));

Просмотреть файл

@ -266,7 +266,7 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
virtual nsIPrincipal* GetEffectiveStoragePrincipal() override; virtual nsIPrincipal* GetEffectiveStoragePrincipal() override;
virtual nsIPrincipal* IntrinsicStoragePrincipal() override; virtual nsIPrincipal* PartitionedPrincipal() override;
// nsIDOMWindow // nsIDOMWindow
NS_DECL_NSIDOMWINDOW NS_DECL_NSIDOMWINDOW
@ -1339,7 +1339,7 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
// FreeInnerObjects has been called. // FreeInnerObjects has been called.
nsCOMPtr<nsIPrincipal> mDocumentPrincipal; nsCOMPtr<nsIPrincipal> mDocumentPrincipal;
nsCOMPtr<nsIPrincipal> mDocumentStoragePrincipal; nsCOMPtr<nsIPrincipal> mDocumentStoragePrincipal;
nsCOMPtr<nsIPrincipal> mDocumentIntrinsicStoragePrincipal; nsCOMPtr<nsIPrincipal> mDocumentPartitionedPrincipal;
nsCOMPtr<nsIContentSecurityPolicy> mDocumentCsp; nsCOMPtr<nsIContentSecurityPolicy> mDocumentCsp;
RefPtr<mozilla::dom::DebuggerNotificationManager> RefPtr<mozilla::dom::DebuggerNotificationManager>

Просмотреть файл

@ -1588,7 +1588,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindowOuter)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSuspendedDoc) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSuspendedDoc)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentPrincipal) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentPrincipal)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentStoragePrincipal) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentStoragePrincipal)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentIntrinsicStoragePrincipal) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocumentPartitionedPrincipal)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDoc) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDoc)
// Traverse stuff from nsPIDOMWindow // Traverse stuff from nsPIDOMWindow
@ -1620,7 +1620,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindowOuter)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSuspendedDoc) NS_IMPL_CYCLE_COLLECTION_UNLINK(mSuspendedDoc)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentPrincipal) NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentPrincipal)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentStoragePrincipal) NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentStoragePrincipal)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentIntrinsicStoragePrincipal) NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentPartitionedPrincipal)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDoc) NS_IMPL_CYCLE_COLLECTION_UNLINK(mDoc)
// Unlink stuff from nsPIDOMWindow // Unlink stuff from nsPIDOMWindow
@ -2044,8 +2044,8 @@ nsresult nsGlobalWindowOuter::SetNewDocument(Document* aDocument,
"mDocumentPrincipal prematurely set!"); "mDocumentPrincipal prematurely set!");
MOZ_ASSERT(mDocumentStoragePrincipal == nullptr, MOZ_ASSERT(mDocumentStoragePrincipal == nullptr,
"mDocumentStoragePrincipal prematurely set!"); "mDocumentStoragePrincipal prematurely set!");
MOZ_ASSERT(mDocumentIntrinsicStoragePrincipal == nullptr, MOZ_ASSERT(mDocumentPartitionedPrincipal == nullptr,
"mDocumentIntrinsicStoragePrincipal prematurely set!"); "mDocumentPartitionedPrincipal prematurely set!");
MOZ_ASSERT(aDocument); MOZ_ASSERT(aDocument);
// Bail out early if we're in process of closing down the window. // Bail out early if we're in process of closing down the window.
@ -2697,7 +2697,7 @@ void nsGlobalWindowOuter::DetachFromDocShell(bool aIsBeingDiscarded) {
// Remember the document's principal and URI. // Remember the document's principal and URI.
mDocumentPrincipal = mDoc->NodePrincipal(); mDocumentPrincipal = mDoc->NodePrincipal();
mDocumentStoragePrincipal = mDoc->EffectiveStoragePrincipal(); mDocumentStoragePrincipal = mDoc->EffectiveStoragePrincipal();
mDocumentIntrinsicStoragePrincipal = mDoc->IntrinsicStoragePrincipal(); mDocumentPartitionedPrincipal = mDoc->PartitionedPrincipal();
mDocumentURI = mDoc->GetDocumentURI(); mDocumentURI = mDoc->GetDocumentURI();
// Release our document reference // Release our document reference
@ -2970,24 +2970,24 @@ nsIPrincipal* nsGlobalWindowOuter::GetEffectiveStoragePrincipal() {
return nullptr; return nullptr;
} }
nsIPrincipal* nsGlobalWindowOuter::IntrinsicStoragePrincipal() { nsIPrincipal* nsGlobalWindowOuter::PartitionedPrincipal() {
if (mDoc) { if (mDoc) {
// If we have a document, get the principal from the document // If we have a document, get the principal from the document
return mDoc->IntrinsicStoragePrincipal(); return mDoc->PartitionedPrincipal();
} }
if (mDocumentIntrinsicStoragePrincipal) { if (mDocumentPartitionedPrincipal) {
return mDocumentIntrinsicStoragePrincipal; return mDocumentPartitionedPrincipal;
} }
// If we don't have a storage principal and we don't have a document we ask // If we don't have a partitioned principal and we don't have a document we
// the parent window for the storage principal. // ask the parent window for the partitioned principal.
nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal = nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal =
do_QueryInterface(GetInProcessParentInternal()); do_QueryInterface(GetInProcessParentInternal());
if (objPrincipal) { if (objPrincipal) {
return objPrincipal->IntrinsicStoragePrincipal(); return objPrincipal->PartitionedPrincipal();
} }
return nullptr; return nullptr;

Просмотреть файл

@ -244,7 +244,7 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,
virtual nsIPrincipal* GetEffectiveStoragePrincipal() override; virtual nsIPrincipal* GetEffectiveStoragePrincipal() override;
virtual nsIPrincipal* IntrinsicStoragePrincipal() override; virtual nsIPrincipal* PartitionedPrincipal() override;
// nsIDOMWindow // nsIDOMWindow
NS_DECL_NSIDOMWINDOW NS_DECL_NSIDOMWINDOW
@ -1098,7 +1098,7 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,
nsCOMPtr<nsIPrincipal> mDocumentPrincipal; nsCOMPtr<nsIPrincipal> mDocumentPrincipal;
nsCOMPtr<nsIPrincipal> mDocumentStoragePrincipal; nsCOMPtr<nsIPrincipal> mDocumentStoragePrincipal;
nsCOMPtr<nsIPrincipal> mDocumentIntrinsicStoragePrincipal; nsCOMPtr<nsIPrincipal> mDocumentPartitionedPrincipal;
#ifdef DEBUG #ifdef DEBUG
uint32_t mSerial; uint32_t mSerial;

Просмотреть файл

@ -29,7 +29,7 @@ class nsIScriptObjectPrincipal : public nsISupports {
virtual nsIPrincipal* GetEffectiveStoragePrincipal() = 0; virtual nsIPrincipal* GetEffectiveStoragePrincipal() = 0;
virtual nsIPrincipal* IntrinsicStoragePrincipal() = 0; virtual nsIPrincipal* PartitionedPrincipal() = 0;
}; };
NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptObjectPrincipal, NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptObjectPrincipal,

Просмотреть файл

@ -234,9 +234,7 @@ already_AddRefed<BroadcastChannel> BroadcastChannel::Constructor(
storageAccess = workerPrivate->StorageAccess(); storageAccess = workerPrivate->StorageAccess();
storagePrincipalInfo = workerPrivate->GetEffectiveStoragePrincipalInfo(); storagePrincipalInfo = workerPrivate->GetEffectiveStoragePrincipalInfo();
origin = workerPrivate->StoragePrincipalOrigin();
// TODO This is broken, it will be fixed in the following patches.
origin = workerPrivate->PartitionedOrigin();
originNoSuffix = workerPrivate->GetLocationInfo().mOrigin; originNoSuffix = workerPrivate->GetLocationInfo().mOrigin;

Просмотреть файл

@ -162,10 +162,10 @@ void nsHTMLDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) {
void nsHTMLDocument::ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup, void nsHTMLDocument::ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup,
nsIPrincipal* aPrincipal, nsIPrincipal* aPrincipal,
nsIPrincipal* aStoragePrincipal) { nsIPrincipal* aPartitionedPrincipal) {
mLoadFlags = nsIRequest::LOAD_NORMAL; mLoadFlags = nsIRequest::LOAD_NORMAL;
Document::ResetToURI(aURI, aLoadGroup, aPrincipal, aStoragePrincipal); Document::ResetToURI(aURI, aLoadGroup, aPrincipal, aPartitionedPrincipal);
mImages = nullptr; mImages = nullptr;
mApplets = nullptr; mApplets = nullptr;

Просмотреть файл

@ -51,7 +51,7 @@ class nsHTMLDocument : public mozilla::dom::Document {
virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) override; virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) override;
virtual void ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup, virtual void ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup,
nsIPrincipal* aPrincipal, nsIPrincipal* aPrincipal,
nsIPrincipal* aStoragePrincipal) override; nsIPrincipal* aPartitionedPrincipal) override;
virtual nsresult StartDocumentLoad(const char* aCommand, nsIChannel* aChannel, virtual nsresult StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
nsILoadGroup* aLoadGroup, nsILoadGroup* aLoadGroup,

Просмотреть файл

@ -77,7 +77,7 @@ interface nsIBrowser : nsISupports
readonly attribute nsIWebProgress remoteWebProgressManager; readonly attribute nsIWebProgress remoteWebProgressManager;
readonly attribute nsIPrincipal contentPrincipal; readonly attribute nsIPrincipal contentPrincipal;
readonly attribute nsIPrincipal contentStoragePrincipal; readonly attribute nsIPrincipal contentPartitionedPrincipal;
readonly attribute nsIPrincipal contentBlockingAllowListPrincipal; readonly attribute nsIPrincipal contentBlockingAllowListPrincipal;
readonly attribute nsIContentSecurityPolicy csp; readonly attribute nsIContentSecurityPolicy csp;
readonly attribute nsIReferrerInfo referrerInfo; readonly attribute nsIReferrerInfo referrerInfo;
@ -133,8 +133,8 @@ interface nsIBrowser : nsISupports
* @param aDocumentURI the URI of the new document * @param aDocumentURI the URI of the new document
* @param aTitle the title of the new doucment * @param aTitle the title of the new doucment
* @param aContentPrincipal the security principal of the new document * @param aContentPrincipal the security principal of the new document
* @param aContentStoragePrincipal the security principal for the new * @param aContentPartitionedPrincipal the security principal for the new
* document's storage * document's storage
* @param aCSP the content security policy of the new document * @param aCSP the content security policy of the new document
* @param aReferrerInfo the referrer info of the new document * @param aReferrerInfo the referrer info of the new document
* @param aIsSynthetic whether or not the document is synthetic * @param aIsSynthetic whether or not the document is synthetic
@ -151,7 +151,7 @@ interface nsIBrowser : nsISupports
in nsIURI aDocumentURI, in nsIURI aDocumentURI,
in AString aTitle, in AString aTitle,
in nsIPrincipal aContentPrincipal, in nsIPrincipal aContentPrincipal,
in nsIPrincipal aContentStoragePrincipal, in nsIPrincipal aContentPartitionedPrincipal,
in nsIContentSecurityPolicy aCSP, in nsIContentSecurityPolicy aCSP,
in nsIReferrerInfo aReferrerInfo, in nsIReferrerInfo aReferrerInfo,
in boolean aIsSynthetic, in boolean aIsSynthetic,

Просмотреть файл

@ -3647,8 +3647,8 @@ NS_IMETHODIMP BrowserChild::OnLocationChange(nsIWebProgress* aWebProgress,
docShell->GetCharsetAutodetected(); docShell->GetCharsetAutodetected();
locationChangeData->contentPrincipal() = document->NodePrincipal(); locationChangeData->contentPrincipal() = document->NodePrincipal();
locationChangeData->contentStoragePrincipal() = locationChangeData->contentPartitionedPrincipal() =
document->EffectiveStoragePrincipal(); document->PartitionedPrincipal();
locationChangeData->csp() = document->GetCsp(); locationChangeData->csp() = document->GetCsp();
locationChangeData->referrerInfo() = document->ReferrerInfo(); locationChangeData->referrerInfo() = document->ReferrerInfo();
locationChangeData->isSyntheticDocument() = document->IsSyntheticDocument(); locationChangeData->isSyntheticDocument() = document->IsSyntheticDocument();

Просмотреть файл

@ -2692,7 +2692,7 @@ mozilla::ipc::IPCResult BrowserParent::RecvOnLocationChange(
aLocationChangeData->charsetAutodetected(), aLocationChangeData->charsetAutodetected(),
aLocationChangeData->documentURI(), aLocationChangeData->title(), aLocationChangeData->documentURI(), aLocationChangeData->title(),
aLocationChangeData->contentPrincipal(), aLocationChangeData->contentPrincipal(),
aLocationChangeData->contentStoragePrincipal(), aLocationChangeData->contentPartitionedPrincipal(),
aLocationChangeData->csp(), aLocationChangeData->referrerInfo(), aLocationChangeData->csp(), aLocationChangeData->referrerInfo(),
aLocationChangeData->isSyntheticDocument(), aLocationChangeData->isSyntheticDocument(),
aWebProgressData->innerDOMWindowID(), aWebProgressData->innerDOMWindowID(),

Просмотреть файл

@ -241,7 +241,7 @@ struct DocShellLoadStateInit
bool InheritPrincipal; bool InheritPrincipal;
bool PrincipalIsExplicit; bool PrincipalIsExplicit;
nsIPrincipal PrincipalToInherit; nsIPrincipal PrincipalToInherit;
nsIPrincipal StoragePrincipalToInherit; nsIPrincipal PartitionedPrincipalToInherit;
bool ForceAllowDataURI; bool ForceAllowDataURI;
bool OriginalFrameSrc; bool OriginalFrameSrc;
bool IsFormSubmission; bool IsFormSubmission;

Просмотреть файл

@ -147,7 +147,7 @@ struct WebProgressLocationChangeData
nsString charset; nsString charset;
nsIURI documentURI; nsIURI documentURI;
nsIPrincipal contentPrincipal; nsIPrincipal contentPrincipal;
nsIPrincipal contentStoragePrincipal; nsIPrincipal contentPartitionedPrincipal;
nsIContentSecurityPolicy csp; nsIContentSecurityPolicy csp;
nsIReferrerInfo referrerInfo; nsIReferrerInfo referrerInfo;
uint64_t? requestContextID; uint64_t? requestContextID;

Просмотреть файл

@ -1705,9 +1705,9 @@ nsresult ServiceWorkerPrivate::SpawnWorkerIfNeeded(WakeUpReason aWhy,
info.mPrincipal = mInfo->Principal(); info.mPrincipal = mInfo->Principal();
info.mLoadingPrincipal = info.mPrincipal; info.mLoadingPrincipal = info.mPrincipal;
// StoragePrincipal for ServiceWorkers is equal to mPrincipal because, at the // PartitionedPrincipal for ServiceWorkers is equal to mPrincipal because, at
// moment, ServiceWorkers are not exposed in partitioned contexts. // the moment, ServiceWorkers are not exposed in partitioned contexts.
info.mStoragePrincipal = info.mPrincipal; info.mPartitionedPrincipal = info.mPrincipal;
info.mCookieJarSettings = mozilla::net::CookieJarSettings::Create(); info.mCookieJarSettings = mozilla::net::CookieJarSettings::Create();
MOZ_ASSERT(info.mCookieJarSettings); MOZ_ASSERT(info.mCookieJarSettings);
@ -1735,7 +1735,7 @@ nsresult ServiceWorkerPrivate::SpawnWorkerIfNeeded(WakeUpReason aWhy,
WorkerPrivate::OverrideLoadInfoLoadGroup(info, info.mPrincipal); WorkerPrivate::OverrideLoadInfoLoadGroup(info, info.mPrincipal);
rv = info.SetPrincipalsAndCSPOnMainThread( rv = info.SetPrincipalsAndCSPOnMainThread(
info.mPrincipal, info.mStoragePrincipal, info.mLoadGroup, nullptr); info.mPrincipal, info.mPartitionedPrincipal, info.mLoadGroup, nullptr);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }

Просмотреть файл

@ -69,7 +69,7 @@ ServiceWorkerPrivateImpl::RAIIActorPtrHolder::~RAIIActorPtrHolder() {
} }
RemoteWorkerControllerChild* RemoteWorkerControllerChild*
ServiceWorkerPrivateImpl::RAIIActorPtrHolder::operator->() const { ServiceWorkerPrivateImpl::RAIIActorPtrHolder::operator->() const {
AssertIsOnMainThread(); AssertIsOnMainThread();
return get(); return get();
@ -168,9 +168,10 @@ nsresult ServiceWorkerPrivateImpl::Initialize() {
mRemoteWorkerData.loadingPrincipalInfo() = principalInfo; mRemoteWorkerData.loadingPrincipalInfo() = principalInfo;
mRemoteWorkerData.principalInfo() = principalInfo; mRemoteWorkerData.principalInfo() = principalInfo;
// storagePrincipalInfo for ServiceWorkers is equal to principalInfo because, // partitionedPrincipalInfo for ServiceWorkers is equal to principalInfo
// at the moment, ServiceWorkers are not exposed in partitioned contexts. // because, at the moment, ServiceWorkers are not exposed in partitioned
mRemoteWorkerData.storagePrincipalInfo() = principalInfo; // contexts.
mRemoteWorkerData.partitionedPrincipalInfo() = principalInfo;
rv = uri->GetHost(mRemoteWorkerData.domain()); rv = uri->GetHost(mRemoteWorkerData.domain());
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);

Просмотреть файл

@ -390,6 +390,13 @@ partial interface Document {
[ChromeOnly] [ChromeOnly]
readonly attribute Principal effectiveStoragePrincipal; readonly attribute Principal effectiveStoragePrincipal;
// You should probably not be using this principal getter since it performs
// no checks to ensure that the partitioned principal should really be used
// here. It is only designed to be used in very specific circumstances, such
// as when inheriting the document/storage principal.
[ChromeOnly]
readonly attribute Principal partitionedPrincipal;
// The principal to use for the content blocking allow list // The principal to use for the content blocking allow list
[ChromeOnly] [ChromeOnly]
readonly attribute Principal? contentBlockingAllowListPrincipal; readonly attribute Principal? contentBlockingAllowListPrincipal;

Просмотреть файл

@ -1430,8 +1430,8 @@ class ScriptLoaderRunnable final : public nsIRunnable, public nsINamed {
// referrer logic depends on the WorkerPrivate principal having a URL // referrer logic depends on the WorkerPrivate principal having a URL
// that matches the worker script URL. If bug 1340694 is ever fixed // that matches the worker script URL. If bug 1340694 is ever fixed
// this can be removed. // this can be removed.
// XXX: force the storagePrincipal to be equal to the response one. This // XXX: force the partitionedPrincipal to be equal to the response one.
// is OK for now because we don't want to expose storagePrincipal // This is OK for now because we don't want to expose partitionedPrincipal
// functionality in ServiceWorkers yet. // functionality in ServiceWorkers yet.
rv = mWorkerPrivate->SetPrincipalsAndCSPOnMainThread( rv = mWorkerPrivate->SetPrincipalsAndCSPOnMainThread(
responsePrincipal, responsePrincipal, loadGroup, nullptr); responsePrincipal, responsePrincipal, loadGroup, nullptr);

Просмотреть файл

@ -98,13 +98,13 @@ WorkerLoadInfoData::WorkerLoadInfoData()
mSecureContext(eNotSet) {} mSecureContext(eNotSet) {}
nsresult WorkerLoadInfo::SetPrincipalsAndCSPOnMainThread( nsresult WorkerLoadInfo::SetPrincipalsAndCSPOnMainThread(
nsIPrincipal* aPrincipal, nsIPrincipal* aStoragePrincipal, nsIPrincipal* aPrincipal, nsIPrincipal* aPartitionedPrincipal,
nsILoadGroup* aLoadGroup, nsIContentSecurityPolicy* aCsp) { nsILoadGroup* aLoadGroup, nsIContentSecurityPolicy* aCsp) {
AssertIsOnMainThread(); AssertIsOnMainThread();
MOZ_ASSERT(NS_LoadGroupMatchesPrincipal(aLoadGroup, aPrincipal)); MOZ_ASSERT(NS_LoadGroupMatchesPrincipal(aLoadGroup, aPrincipal));
mPrincipal = aPrincipal; mPrincipal = aPrincipal;
mStoragePrincipal = aStoragePrincipal; mPartitionedPrincipal = aPartitionedPrincipal;
mPrincipalIsSystem = aPrincipal->IsSystemPrincipal(); mPrincipalIsSystem = aPrincipal->IsSystemPrincipal();
mPrincipalIsAddonOrExpandedAddon = mPrincipalIsAddonOrExpandedAddon =
aPrincipal->GetIsAddonOrExpandedAddonPrincipal(); aPrincipal->GetIsAddonOrExpandedAddonPrincipal();
@ -126,7 +126,7 @@ nsresult WorkerLoadInfo::SetPrincipalsAndCSPOnMainThread(
mLoadGroup = aLoadGroup; mLoadGroup = aLoadGroup;
mPrincipalInfo = MakeUnique<PrincipalInfo>(); mPrincipalInfo = MakeUnique<PrincipalInfo>();
mStoragePrincipalInfo = MakeUnique<PrincipalInfo>(); mPartitionedPrincipalInfo = MakeUnique<PrincipalInfo>();
StoragePrincipalHelper::GetRegularPrincipalOriginAttributes( StoragePrincipalHelper::GetRegularPrincipalOriginAttributes(
aLoadGroup, mOriginAttributes); aLoadGroup, mOriginAttributes);
@ -139,16 +139,16 @@ nsresult WorkerLoadInfo::SetPrincipalsAndCSPOnMainThread(
rv = aPrincipal->GetOrigin(mOrigin); rv = aPrincipal->GetOrigin(mOrigin);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
if (aPrincipal->Equals(aStoragePrincipal)) { if (aPrincipal->Equals(aPartitionedPrincipal)) {
*mStoragePrincipalInfo = *mPrincipalInfo; *mPartitionedPrincipalInfo = *mPrincipalInfo;
mPartitionedOrigin = mOrigin; mPartitionedOrigin = mOrigin;
} else { } else {
mStoragePrincipalInfo = MakeUnique<PrincipalInfo>(); mPartitionedPrincipalInfo = MakeUnique<PrincipalInfo>();
rv = PrincipalToPrincipalInfo(aStoragePrincipal, rv = PrincipalToPrincipalInfo(aPartitionedPrincipal,
mStoragePrincipalInfo.get()); mPartitionedPrincipalInfo.get());
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
rv = aStoragePrincipal->GetOrigin(mPartitionedOrigin); rv = aPartitionedPrincipal->GetOrigin(mPartitionedOrigin);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }
@ -157,11 +157,11 @@ nsresult WorkerLoadInfo::SetPrincipalsAndCSPOnMainThread(
nsresult WorkerLoadInfo::GetPrincipalsAndLoadGroupFromChannel( nsresult WorkerLoadInfo::GetPrincipalsAndLoadGroupFromChannel(
nsIChannel* aChannel, nsIPrincipal** aPrincipalOut, nsIChannel* aChannel, nsIPrincipal** aPrincipalOut,
nsIPrincipal** aStoragePrincipalOut, nsILoadGroup** aLoadGroupOut) { nsIPrincipal** aPartitionedPrincipalOut, nsILoadGroup** aLoadGroupOut) {
AssertIsOnMainThread(); AssertIsOnMainThread();
MOZ_DIAGNOSTIC_ASSERT(aChannel); MOZ_DIAGNOSTIC_ASSERT(aChannel);
MOZ_DIAGNOSTIC_ASSERT(aPrincipalOut); MOZ_DIAGNOSTIC_ASSERT(aPrincipalOut);
MOZ_DIAGNOSTIC_ASSERT(aStoragePrincipalOut); MOZ_DIAGNOSTIC_ASSERT(aPartitionedPrincipalOut);
MOZ_DIAGNOSTIC_ASSERT(aLoadGroupOut); MOZ_DIAGNOSTIC_ASSERT(aLoadGroupOut);
// Initial triggering principal should be set // Initial triggering principal should be set
@ -171,10 +171,10 @@ nsresult WorkerLoadInfo::GetPrincipalsAndLoadGroupFromChannel(
MOZ_DIAGNOSTIC_ASSERT(ssm); MOZ_DIAGNOSTIC_ASSERT(ssm);
nsCOMPtr<nsIPrincipal> channelPrincipal; nsCOMPtr<nsIPrincipal> channelPrincipal;
nsCOMPtr<nsIPrincipal> channelStoragePrincipal; nsCOMPtr<nsIPrincipal> channelPartitionedPrincipal;
nsresult rv = ssm->GetChannelResultPrincipals( nsresult rv = ssm->GetChannelResultPrincipals(
aChannel, getter_AddRefs(channelPrincipal), aChannel, getter_AddRefs(channelPrincipal),
getter_AddRefs(channelStoragePrincipal)); getter_AddRefs(channelPartitionedPrincipal));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// Every time we call GetChannelResultPrincipal() it will return a different // Every time we call GetChannelResultPrincipal() it will return a different
@ -188,7 +188,7 @@ nsresult WorkerLoadInfo::GetPrincipalsAndLoadGroupFromChannel(
if (mPrincipal && mPrincipal->GetIsNullPrincipal() && if (mPrincipal && mPrincipal->GetIsNullPrincipal() &&
channelPrincipal->GetIsNullPrincipal()) { channelPrincipal->GetIsNullPrincipal()) {
channelPrincipal = mPrincipal; channelPrincipal = mPrincipal;
channelStoragePrincipal = mPrincipal; channelPartitionedPrincipal = mPrincipal;
} }
nsCOMPtr<nsILoadGroup> channelLoadGroup; nsCOMPtr<nsILoadGroup> channelLoadGroup;
@ -221,7 +221,7 @@ nsresult WorkerLoadInfo::GetPrincipalsAndLoadGroupFromChannel(
// Assign the system principal to the resource:// worker only if it // Assign the system principal to the resource:// worker only if it
// was loaded from code using the system principal. // was loaded from code using the system principal.
channelPrincipal = mLoadingPrincipal; channelPrincipal = mLoadingPrincipal;
channelStoragePrincipal = mLoadingPrincipal; channelPartitionedPrincipal = mLoadingPrincipal;
} else { } else {
return NS_ERROR_DOM_BAD_URI; return NS_ERROR_DOM_BAD_URI;
} }
@ -233,7 +233,7 @@ nsresult WorkerLoadInfo::GetPrincipalsAndLoadGroupFromChannel(
MOZ_ASSERT(NS_LoadGroupMatchesPrincipal(channelLoadGroup, channelPrincipal)); MOZ_ASSERT(NS_LoadGroupMatchesPrincipal(channelLoadGroup, channelPrincipal));
channelPrincipal.forget(aPrincipalOut); channelPrincipal.forget(aPrincipalOut);
channelStoragePrincipal.forget(aStoragePrincipalOut); channelPartitionedPrincipal.forget(aPartitionedPrincipalOut);
channelLoadGroup.forget(aLoadGroupOut); channelLoadGroup.forget(aLoadGroupOut);
return NS_OK; return NS_OK;
@ -243,10 +243,10 @@ nsresult WorkerLoadInfo::SetPrincipalsAndCSPFromChannel(nsIChannel* aChannel) {
AssertIsOnMainThread(); AssertIsOnMainThread();
nsCOMPtr<nsIPrincipal> principal; nsCOMPtr<nsIPrincipal> principal;
nsCOMPtr<nsIPrincipal> storagePrincipal; nsCOMPtr<nsIPrincipal> partitionedPrincipal;
nsCOMPtr<nsILoadGroup> loadGroup; nsCOMPtr<nsILoadGroup> loadGroup;
nsresult rv = GetPrincipalsAndLoadGroupFromChannel( nsresult rv = GetPrincipalsAndLoadGroupFromChannel(
aChannel, getter_AddRefs(principal), getter_AddRefs(storagePrincipal), aChannel, getter_AddRefs(principal), getter_AddRefs(partitionedPrincipal),
getter_AddRefs(loadGroup)); getter_AddRefs(loadGroup));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -257,18 +257,18 @@ nsresult WorkerLoadInfo::SetPrincipalsAndCSPFromChannel(nsIChannel* aChannel) {
nsCOMPtr<nsILoadInfo> loadinfo = aChannel->LoadInfo(); nsCOMPtr<nsILoadInfo> loadinfo = aChannel->LoadInfo();
csp = loadinfo->GetCsp(); csp = loadinfo->GetCsp();
} }
return SetPrincipalsAndCSPOnMainThread(principal, storagePrincipal, loadGroup, return SetPrincipalsAndCSPOnMainThread(principal, partitionedPrincipal,
csp); loadGroup, csp);
} }
bool WorkerLoadInfo::FinalChannelPrincipalIsValid(nsIChannel* aChannel) { bool WorkerLoadInfo::FinalChannelPrincipalIsValid(nsIChannel* aChannel) {
AssertIsOnMainThread(); AssertIsOnMainThread();
nsCOMPtr<nsIPrincipal> principal; nsCOMPtr<nsIPrincipal> principal;
nsCOMPtr<nsIPrincipal> storagePrincipal; nsCOMPtr<nsIPrincipal> partitionedPrincipal;
nsCOMPtr<nsILoadGroup> loadGroup; nsCOMPtr<nsILoadGroup> loadGroup;
nsresult rv = GetPrincipalsAndLoadGroupFromChannel( nsresult rv = GetPrincipalsAndLoadGroupFromChannel(
aChannel, getter_AddRefs(principal), getter_AddRefs(storagePrincipal), aChannel, getter_AddRefs(principal), getter_AddRefs(partitionedPrincipal),
getter_AddRefs(loadGroup)); getter_AddRefs(loadGroup));
NS_ENSURE_SUCCESS(rv, false); NS_ENSURE_SUCCESS(rv, false);
@ -293,9 +293,9 @@ bool WorkerLoadInfo::PrincipalIsValid() const {
return mPrincipal && mPrincipalInfo && return mPrincipal && mPrincipalInfo &&
mPrincipalInfo->type() != PrincipalInfo::T__None && mPrincipalInfo->type() != PrincipalInfo::T__None &&
mPrincipalInfo->type() <= PrincipalInfo::T__Last && mPrincipalInfo->type() <= PrincipalInfo::T__Last &&
mStoragePrincipal && mStoragePrincipalInfo && mPartitionedPrincipal && mPartitionedPrincipalInfo &&
mStoragePrincipalInfo->type() != PrincipalInfo::T__None && mPartitionedPrincipalInfo->type() != PrincipalInfo::T__None &&
mStoragePrincipalInfo->type() <= PrincipalInfo::T__Last; mPartitionedPrincipalInfo->type() <= PrincipalInfo::T__Last;
} }
bool WorkerLoadInfo::PrincipalURIMatchesScriptURL() { bool WorkerLoadInfo::PrincipalURIMatchesScriptURL() {
@ -375,7 +375,7 @@ bool WorkerLoadInfo::ProxyReleaseMainThreadObjects(
SwapToISupportsArray(mBaseURI, doomed); SwapToISupportsArray(mBaseURI, doomed);
SwapToISupportsArray(mResolvedScriptURI, doomed); SwapToISupportsArray(mResolvedScriptURI, doomed);
SwapToISupportsArray(mPrincipal, doomed); SwapToISupportsArray(mPrincipal, doomed);
SwapToISupportsArray(mStoragePrincipal, doomed); SwapToISupportsArray(mPartitionedPrincipal, doomed);
SwapToISupportsArray(mLoadingPrincipal, doomed); SwapToISupportsArray(mLoadingPrincipal, doomed);
SwapToISupportsArray(mChannel, doomed); SwapToISupportsArray(mChannel, doomed);
SwapToISupportsArray(mCSP, doomed); SwapToISupportsArray(mCSP, doomed);

Просмотреть файл

@ -52,7 +52,7 @@ struct WorkerLoadInfoData {
// If we load a data: URL, mPrincipal will be a null principal. // If we load a data: URL, mPrincipal will be a null principal.
nsCOMPtr<nsIPrincipal> mLoadingPrincipal; nsCOMPtr<nsIPrincipal> mLoadingPrincipal;
nsCOMPtr<nsIPrincipal> mPrincipal; nsCOMPtr<nsIPrincipal> mPrincipal;
nsCOMPtr<nsIPrincipal> mStoragePrincipal; nsCOMPtr<nsIPrincipal> mPartitionedPrincipal;
// Taken from the parent context. // Taken from the parent context.
nsCOMPtr<nsICookieJarSettings> mCookieJarSettings; nsCOMPtr<nsICookieJarSettings> mCookieJarSettings;
@ -102,7 +102,7 @@ struct WorkerLoadInfoData {
RefPtr<InterfaceRequestor> mInterfaceRequestor; RefPtr<InterfaceRequestor> mInterfaceRequestor;
UniquePtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo; UniquePtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo;
UniquePtr<mozilla::ipc::PrincipalInfo> mStoragePrincipalInfo; UniquePtr<mozilla::ipc::PrincipalInfo> mPartitionedPrincipalInfo;
nsCString mDomain; nsCString mDomain;
nsString mOriginNoSuffix; // Derived from mPrincipal; can be used on worker nsString mOriginNoSuffix; // Derived from mPrincipal; can be used on worker
// thread. // thread.
@ -157,13 +157,13 @@ struct WorkerLoadInfo : WorkerLoadInfoData {
WorkerLoadInfo& operator=(WorkerLoadInfo&& aOther) = default; WorkerLoadInfo& operator=(WorkerLoadInfo&& aOther) = default;
nsresult SetPrincipalsAndCSPOnMainThread(nsIPrincipal* aPrincipal, nsresult SetPrincipalsAndCSPOnMainThread(nsIPrincipal* aPrincipal,
nsIPrincipal* aStoragePrincipal, nsIPrincipal* aPartitionedPrincipal,
nsILoadGroup* aLoadGroup, nsILoadGroup* aLoadGroup,
nsIContentSecurityPolicy* aCSP); nsIContentSecurityPolicy* aCSP);
nsresult GetPrincipalsAndLoadGroupFromChannel( nsresult GetPrincipalsAndLoadGroupFromChannel(
nsIChannel* aChannel, nsIPrincipal** aPrincipalOut, nsIChannel* aChannel, nsIPrincipal** aPrincipalOut,
nsIPrincipal** aStoragePrincipalOut, nsILoadGroup** aLoadGroupOut); nsIPrincipal** aPartitionedPrincipalOut, nsILoadGroup** aLoadGroupOut);
nsresult SetPrincipalsAndCSPFromChannel(nsIChannel* aChannel); nsresult SetPrincipalsAndCSPFromChannel(nsIChannel* aChannel);

Просмотреть файл

@ -2028,10 +2028,10 @@ void WorkerPrivate::SetBaseURI(nsIURI* aBaseURI) {
} }
nsresult WorkerPrivate::SetPrincipalsAndCSPOnMainThread( nsresult WorkerPrivate::SetPrincipalsAndCSPOnMainThread(
nsIPrincipal* aPrincipal, nsIPrincipal* aStoragePrincipal, nsIPrincipal* aPrincipal, nsIPrincipal* aPartitionedPrincipal,
nsILoadGroup* aLoadGroup, nsIContentSecurityPolicy* aCsp) { nsILoadGroup* aLoadGroup, nsIContentSecurityPolicy* aCsp) {
return mLoadInfo.SetPrincipalsAndCSPOnMainThread( return mLoadInfo.SetPrincipalsAndCSPOnMainThread(
aPrincipal, aStoragePrincipal, aLoadGroup, aCsp); aPrincipal, aPartitionedPrincipal, aLoadGroup, aCsp);
} }
nsresult WorkerPrivate::SetPrincipalsAndCSPFromChannel(nsIChannel* aChannel) { nsresult WorkerPrivate::SetPrincipalsAndCSPFromChannel(nsIChannel* aChannel) {
@ -5333,6 +5333,23 @@ void WorkerPrivate::EnsureOwnerEmbedderPolicy() {
} }
} }
const mozilla::ipc::PrincipalInfo&
WorkerPrivate::GetEffectiveStoragePrincipalInfo() const {
AssertIsOnWorkerThread();
if (mLoadInfo.mFirstPartyStorageAccessGranted) {
return *mLoadInfo.mPrincipalInfo;
}
// TODO: this is wrong and it will be fixed by the next patch.
return *mLoadInfo.mPartitionedPrincipalInfo;
}
const nsACString& WorkerPrivate::StoragePrincipalOrigin() const {
// TODO: this is wrong and it will be fixed by the next patch.
return mLoadInfo.mPartitionedOrigin;
}
NS_IMPL_ADDREF(WorkerPrivate::EventTarget) NS_IMPL_ADDREF(WorkerPrivate::EventTarget)
NS_IMPL_RELEASE(WorkerPrivate::EventTarget) NS_IMPL_RELEASE(WorkerPrivate::EventTarget)

Просмотреть файл

@ -694,11 +694,6 @@ class WorkerPrivate : public RelativeTimeline {
return mLoadInfo.mPrincipal; return mLoadInfo.mPrincipal;
} }
nsIPrincipal* GetEffectiveStoragePrincipal() const {
AssertIsOnMainThread();
return mLoadInfo.mStoragePrincipal;
}
nsIPrincipal* GetLoadingPrincipal() const { nsIPrincipal* GetLoadingPrincipal() const {
AssertIsOnMainThread(); AssertIsOnMainThread();
return mLoadInfo.mLoadingPrincipal; return mLoadInfo.mLoadingPrincipal;
@ -708,6 +703,8 @@ class WorkerPrivate : public RelativeTimeline {
const nsACString& Origin() const { return mLoadInfo.mOrigin; } const nsACString& Origin() const { return mLoadInfo.mOrigin; }
const nsACString& StoragePrincipalOrigin() const;
const nsACString& PartitionedOrigin() const { const nsACString& PartitionedOrigin() const {
return mLoadInfo.mPartitionedOrigin; return mLoadInfo.mPartitionedOrigin;
} }
@ -726,9 +723,7 @@ class WorkerPrivate : public RelativeTimeline {
return *mLoadInfo.mPrincipalInfo; return *mLoadInfo.mPrincipalInfo;
} }
const mozilla::ipc::PrincipalInfo& GetEffectiveStoragePrincipalInfo() const { const mozilla::ipc::PrincipalInfo& GetEffectiveStoragePrincipalInfo() const;
return *mLoadInfo.mStoragePrincipalInfo;
}
already_AddRefed<nsIChannel> ForgetWorkerChannel() { already_AddRefed<nsIChannel> ForgetWorkerChannel() {
AssertIsOnMainThread(); AssertIsOnMainThread();
@ -863,7 +858,7 @@ class WorkerPrivate : public RelativeTimeline {
void CycleCollect(bool aDummy); void CycleCollect(bool aDummy);
nsresult SetPrincipalsAndCSPOnMainThread(nsIPrincipal* aPrincipal, nsresult SetPrincipalsAndCSPOnMainThread(nsIPrincipal* aPrincipal,
nsIPrincipal* aStoragePrincipal, nsIPrincipal* aPartitionedPrincipal,
nsILoadGroup* aLoadGroup, nsILoadGroup* aLoadGroup,
nsIContentSecurityPolicy* aCsp); nsIContentSecurityPolicy* aCsp);

Просмотреть файл

@ -325,10 +325,10 @@ nsresult RemoteWorkerChild::ExecWorkerOnMainThread(RemoteWorkerData&& aData) {
return loadingPrincipalOrErr.unwrapErr(); return loadingPrincipalOrErr.unwrapErr();
} }
auto storagePrincipalOrErr = auto partitionedPrincipalOrErr =
PrincipalInfoToPrincipal(aData.storagePrincipalInfo()); PrincipalInfoToPrincipal(aData.partitionedPrincipalInfo());
if (NS_WARN_IF(storagePrincipalOrErr.isErr())) { if (NS_WARN_IF(partitionedPrincipalOrErr.isErr())) {
return storagePrincipalOrErr.unwrapErr(); return partitionedPrincipalOrErr.unwrapErr();
} }
WorkerLoadInfo info; WorkerLoadInfo info;
@ -336,13 +336,13 @@ nsresult RemoteWorkerChild::ExecWorkerOnMainThread(RemoteWorkerData&& aData) {
info.mResolvedScriptURI = DeserializeURI(aData.resolvedScriptURL()); info.mResolvedScriptURI = DeserializeURI(aData.resolvedScriptURL());
info.mPrincipalInfo = MakeUnique<PrincipalInfo>(aData.principalInfo()); info.mPrincipalInfo = MakeUnique<PrincipalInfo>(aData.principalInfo());
info.mStoragePrincipalInfo = info.mPartitionedPrincipalInfo =
MakeUnique<PrincipalInfo>(aData.storagePrincipalInfo()); MakeUnique<PrincipalInfo>(aData.partitionedPrincipalInfo());
info.mReferrerInfo = aData.referrerInfo(); info.mReferrerInfo = aData.referrerInfo();
info.mDomain = aData.domain(); info.mDomain = aData.domain();
info.mPrincipal = principal; info.mPrincipal = principal;
info.mStoragePrincipal = storagePrincipalOrErr.unwrap(); info.mPartitionedPrincipal = partitionedPrincipalOrErr.unwrap();
info.mLoadingPrincipal = loadingPrincipalOrErr.unwrap(); info.mLoadingPrincipal = loadingPrincipalOrErr.unwrap();
info.mStorageAccess = aData.storageAccess(); info.mStorageAccess = aData.storageAccess();
info.mOriginAttributes = info.mOriginAttributes =
@ -383,7 +383,7 @@ nsresult RemoteWorkerChild::ExecWorkerOnMainThread(RemoteWorkerData&& aData) {
} }
rv = info.SetPrincipalsAndCSPOnMainThread( rv = info.SetPrincipalsAndCSPOnMainThread(
info.mPrincipal, info.mStoragePrincipal, info.mLoadGroup, info.mCSP); info.mPrincipal, info.mPartitionedPrincipal, info.mLoadGroup, info.mCSP);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }

Просмотреть файл

@ -49,7 +49,7 @@ struct RemoteWorkerData
PrincipalInfo loadingPrincipalInfo; PrincipalInfo loadingPrincipalInfo;
PrincipalInfo principalInfo; PrincipalInfo principalInfo;
PrincipalInfo storagePrincipalInfo; PrincipalInfo partitionedPrincipalInfo;
nsCString domain; nsCString domain;

Просмотреть файл

@ -121,9 +121,9 @@ already_AddRefed<SharedWorker> SharedWorker::Constructor(
return nullptr; return nullptr;
} }
// Here, the StoragePrincipal is always equal to the SharedWorker's principal // Here, the PartitionedPrincipal is always equal to the SharedWorker's
// because the channel is not opened yet, and, because of this, it's not // principal because the channel is not opened yet, and, because of this, it's
// classified. We need to force the correct originAttributes. // not classified. We need to force the correct originAttributes.
if (ShouldPartitionStorage(storageAllowed)) { if (ShouldPartitionStorage(storageAllowed)) {
nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(window); nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(window);
if (!sop) { if (!sop) {
@ -137,27 +137,27 @@ already_AddRefed<SharedWorker> SharedWorker::Constructor(
return nullptr; return nullptr;
} }
nsIPrincipal* windowStoragePrincipal = sop->GetEffectiveStoragePrincipal(); nsIPrincipal* windowPartitionedPrincipal = sop->PartitionedPrincipal();
if (!windowStoragePrincipal) { if (!windowPartitionedPrincipal) {
aRv.Throw(NS_ERROR_UNEXPECTED); aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr; return nullptr;
} }
if (!windowPrincipal->Equals(windowStoragePrincipal)) { if (!windowPrincipal->Equals(windowPartitionedPrincipal)) {
loadInfo.mStoragePrincipal = loadInfo.mPartitionedPrincipal =
BasePrincipal::Cast(loadInfo.mPrincipal) BasePrincipal::Cast(loadInfo.mPrincipal)
->CloneForcingOriginAttributes( ->CloneForcingOriginAttributes(
BasePrincipal::Cast(windowStoragePrincipal) BasePrincipal::Cast(windowPartitionedPrincipal)
->OriginAttributesRef()); ->OriginAttributesRef());
} }
} }
PrincipalInfo storagePrincipalInfo; PrincipalInfo partitionedPrincipalInfo;
if (loadInfo.mPrincipal->Equals(loadInfo.mStoragePrincipal)) { if (loadInfo.mPrincipal->Equals(loadInfo.mPartitionedPrincipal)) {
storagePrincipalInfo = principalInfo; partitionedPrincipalInfo = principalInfo;
} else { } else {
aRv = PrincipalToPrincipalInfo(loadInfo.mStoragePrincipal, aRv = PrincipalToPrincipalInfo(loadInfo.mPartitionedPrincipal,
&storagePrincipalInfo); &partitionedPrincipalInfo);
if (NS_WARN_IF(aRv.Failed())) { if (NS_WARN_IF(aRv.Failed())) {
return nullptr; return nullptr;
} }
@ -195,7 +195,7 @@ already_AddRefed<SharedWorker> SharedWorker::Constructor(
RemoteWorkerData remoteWorkerData( RemoteWorkerData remoteWorkerData(
nsString(aScriptURL), baseURL, resolvedScriptURL, name, nsString(aScriptURL), baseURL, resolvedScriptURL, name,
loadingPrincipalInfo, principalInfo, storagePrincipalInfo, loadingPrincipalInfo, principalInfo, partitionedPrincipalInfo,
loadInfo.mDomain, isSecureContext, ipcClientInfo, loadInfo.mReferrerInfo, loadInfo.mDomain, isSecureContext, ipcClientInfo, loadInfo.mReferrerInfo,
storageAllowed, void_t() /* OptionalServiceWorkerData */, agentClusterId); storageAllowed, void_t() /* OptionalServiceWorkerData */, agentClusterId);

Просмотреть файл

@ -22,12 +22,12 @@ namespace dom {
already_AddRefed<SharedWorkerManagerHolder> SharedWorkerManager::Create( already_AddRefed<SharedWorkerManagerHolder> SharedWorkerManager::Create(
SharedWorkerService* aService, nsIEventTarget* aPBackgroundEventTarget, SharedWorkerService* aService, nsIEventTarget* aPBackgroundEventTarget,
const RemoteWorkerData& aData, nsIPrincipal* aLoadingPrincipal, const RemoteWorkerData& aData, nsIPrincipal* aLoadingPrincipal,
const OriginAttributes& aStoragePrincipalAttrs) { const OriginAttributes& aPartitionedPrincipalAttrs) {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
RefPtr<SharedWorkerManager> manager = RefPtr<SharedWorkerManager> manager =
new SharedWorkerManager(aPBackgroundEventTarget, aData, aLoadingPrincipal, new SharedWorkerManager(aPBackgroundEventTarget, aData, aLoadingPrincipal,
aStoragePrincipalAttrs); aPartitionedPrincipalAttrs);
RefPtr<SharedWorkerManagerHolder> holder = RefPtr<SharedWorkerManagerHolder> holder =
new SharedWorkerManagerHolder(manager, aService); new SharedWorkerManagerHolder(manager, aService);
@ -37,11 +37,11 @@ already_AddRefed<SharedWorkerManagerHolder> SharedWorkerManager::Create(
SharedWorkerManager::SharedWorkerManager( SharedWorkerManager::SharedWorkerManager(
nsIEventTarget* aPBackgroundEventTarget, const RemoteWorkerData& aData, nsIEventTarget* aPBackgroundEventTarget, const RemoteWorkerData& aData,
nsIPrincipal* aLoadingPrincipal, nsIPrincipal* aLoadingPrincipal,
const OriginAttributes& aStoragePrincipalAttrs) const OriginAttributes& aPartitionedPrincipalAttrs)
: mPBackgroundEventTarget(aPBackgroundEventTarget), : mPBackgroundEventTarget(aPBackgroundEventTarget),
mLoadingPrincipal(aLoadingPrincipal), mLoadingPrincipal(aLoadingPrincipal),
mDomain(aData.domain()), mDomain(aData.domain()),
mStoragePrincipalAttrs(aStoragePrincipalAttrs), mPartitionedPrincipalAttrs(aPartitionedPrincipalAttrs),
mResolvedScriptURL(DeserializeURI(aData.resolvedScriptURL())), mResolvedScriptURL(DeserializeURI(aData.resolvedScriptURL())),
mName(aData.name()), mName(aData.name()),
mIsSecureContext(aData.isSecureContext()), mIsSecureContext(aData.isSecureContext()),
@ -83,7 +83,7 @@ already_AddRefed<SharedWorkerManagerHolder>
SharedWorkerManager::MatchOnMainThread( SharedWorkerManager::MatchOnMainThread(
SharedWorkerService* aService, const nsACString& aDomain, SharedWorkerService* aService, const nsACString& aDomain,
nsIURI* aScriptURL, const nsAString& aName, nsIPrincipal* aLoadingPrincipal, nsIURI* aScriptURL, const nsAString& aName, nsIPrincipal* aLoadingPrincipal,
const OriginAttributes& aStoragePrincipalAttrs) { const OriginAttributes& aPartitionedPrincipalAttrs) {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
bool urlEquals; bool urlEquals;
@ -96,7 +96,7 @@ SharedWorkerManager::MatchOnMainThread(
// SharedWorker's loading principal and vice versa. // SharedWorker's loading principal and vice versa.
mLoadingPrincipal->Subsumes(aLoadingPrincipal) && mLoadingPrincipal->Subsumes(aLoadingPrincipal) &&
aLoadingPrincipal->Subsumes(mLoadingPrincipal) && aLoadingPrincipal->Subsumes(mLoadingPrincipal) &&
mStoragePrincipalAttrs == aStoragePrincipalAttrs; mPartitionedPrincipalAttrs == aPartitionedPrincipalAttrs;
if (!match) { if (!match) {
return nullptr; return nullptr;
} }

Просмотреть файл

@ -70,7 +70,7 @@ class SharedWorkerManager final : public RemoteWorkerObserver {
static already_AddRefed<SharedWorkerManagerHolder> Create( static already_AddRefed<SharedWorkerManagerHolder> Create(
SharedWorkerService* aService, nsIEventTarget* aPBackgroundEventTarget, SharedWorkerService* aService, nsIEventTarget* aPBackgroundEventTarget,
const RemoteWorkerData& aData, nsIPrincipal* aLoadingPrincipal, const RemoteWorkerData& aData, nsIPrincipal* aLoadingPrincipal,
const OriginAttributes& aStoragePrincipalAttrs); const OriginAttributes& aPartitionedPrincipalAttrs);
// Returns a holder if this manager matches. The holder blocks the shutdown of // Returns a holder if this manager matches. The holder blocks the shutdown of
// the manager. // the manager.
@ -78,7 +78,7 @@ class SharedWorkerManager final : public RemoteWorkerObserver {
SharedWorkerService* aService, const nsACString& aDomain, SharedWorkerService* aService, const nsACString& aDomain,
nsIURI* aScriptURL, const nsAString& aName, nsIURI* aScriptURL, const nsAString& aName,
nsIPrincipal* aLoadingPrincipal, nsIPrincipal* aLoadingPrincipal,
const OriginAttributes& aStoragePrincipalAttrs); const OriginAttributes& aPartitionedPrincipalAttrs);
// RemoteWorkerObserver // RemoteWorkerObserver
@ -119,7 +119,7 @@ class SharedWorkerManager final : public RemoteWorkerObserver {
SharedWorkerManager(nsIEventTarget* aPBackgroundEventTarget, SharedWorkerManager(nsIEventTarget* aPBackgroundEventTarget,
const RemoteWorkerData& aData, const RemoteWorkerData& aData,
nsIPrincipal* aLoadingPrincipal, nsIPrincipal* aLoadingPrincipal,
const OriginAttributes& aStoragePrincipalAttrs); const OriginAttributes& aPartitionedPrincipalAttrs);
~SharedWorkerManager(); ~SharedWorkerManager();
@ -127,7 +127,7 @@ class SharedWorkerManager final : public RemoteWorkerObserver {
nsCOMPtr<nsIPrincipal> mLoadingPrincipal; nsCOMPtr<nsIPrincipal> mLoadingPrincipal;
const nsCString mDomain; const nsCString mDomain;
const OriginAttributes mStoragePrincipalAttrs; const OriginAttributes mPartitionedPrincipalAttrs;
const nsCOMPtr<nsIURI> mResolvedScriptURL; const nsCOMPtr<nsIURI> mResolvedScriptURL;
const nsString mName; const nsString mName;
const bool mIsSecureContext; const bool mIsSecureContext;

Просмотреть файл

@ -166,11 +166,11 @@ void SharedWorkerService::GetOrCreateWorkerManagerOnMainThread(
MOZ_ASSERT(aBackgroundEventTarget); MOZ_ASSERT(aBackgroundEventTarget);
MOZ_ASSERT(aActor); MOZ_ASSERT(aActor);
auto storagePrincipalOrErr = auto partitionedPrincipalOrErr =
PrincipalInfoToPrincipal(aData.storagePrincipalInfo()); PrincipalInfoToPrincipal(aData.partitionedPrincipalInfo());
if (NS_WARN_IF(storagePrincipalOrErr.isErr())) { if (NS_WARN_IF(partitionedPrincipalOrErr.isErr())) {
ErrorPropagationOnMainThread(aBackgroundEventTarget, aActor, ErrorPropagationOnMainThread(aBackgroundEventTarget, aActor,
storagePrincipalOrErr.unwrapErr()); partitionedPrincipalOrErr.unwrapErr());
return; return;
} }
@ -185,7 +185,8 @@ void SharedWorkerService::GetOrCreateWorkerManagerOnMainThread(
RefPtr<SharedWorkerManagerHolder> managerHolder; RefPtr<SharedWorkerManagerHolder> managerHolder;
nsCOMPtr<nsIPrincipal> loadingPrincipal = loadingPrincipalOrErr.unwrap(); nsCOMPtr<nsIPrincipal> loadingPrincipal = loadingPrincipalOrErr.unwrap();
nsCOMPtr<nsIPrincipal> storagePrincipal = storagePrincipalOrErr.unwrap(); nsCOMPtr<nsIPrincipal> partitionedPrincipal =
partitionedPrincipalOrErr.unwrap();
// Let's see if there is already a SharedWorker to share. // Let's see if there is already a SharedWorker to share.
nsCOMPtr<nsIURI> resolvedScriptURL = nsCOMPtr<nsIURI> resolvedScriptURL =
@ -193,7 +194,7 @@ void SharedWorkerService::GetOrCreateWorkerManagerOnMainThread(
for (SharedWorkerManager* workerManager : mWorkerManagers) { for (SharedWorkerManager* workerManager : mWorkerManagers) {
managerHolder = workerManager->MatchOnMainThread( managerHolder = workerManager->MatchOnMainThread(
this, aData.domain(), resolvedScriptURL, aData.name(), loadingPrincipal, this, aData.domain(), resolvedScriptURL, aData.name(), loadingPrincipal,
BasePrincipal::Cast(storagePrincipal)->OriginAttributesRef()); BasePrincipal::Cast(partitionedPrincipal)->OriginAttributesRef());
if (managerHolder) { if (managerHolder) {
break; break;
} }
@ -203,7 +204,7 @@ void SharedWorkerService::GetOrCreateWorkerManagerOnMainThread(
if (!managerHolder) { if (!managerHolder) {
managerHolder = SharedWorkerManager::Create( managerHolder = SharedWorkerManager::Create(
this, aBackgroundEventTarget, aData, loadingPrincipal, this, aBackgroundEventTarget, aData, loadingPrincipal,
BasePrincipal::Cast(storagePrincipal)->OriginAttributesRef()); BasePrincipal::Cast(partitionedPrincipal)->OriginAttributesRef());
mWorkerManagers.AppendElement(managerHolder->Manager()); mWorkerManagers.AppendElement(managerHolder->Manager());
} else { } else {

Просмотреть файл

@ -216,14 +216,14 @@ void XMLDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) {
void XMLDocument::ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup, void XMLDocument::ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup,
nsIPrincipal* aPrincipal, nsIPrincipal* aPrincipal,
nsIPrincipal* aStoragePrincipal) { nsIPrincipal* aPartitionedPrincipal) {
if (mChannelIsPending) { if (mChannelIsPending) {
StopDocumentLoad(); StopDocumentLoad();
mChannel->Cancel(NS_BINDING_ABORTED); mChannel->Cancel(NS_BINDING_ABORTED);
mChannelIsPending = false; mChannelIsPending = false;
} }
Document::ResetToURI(aURI, aLoadGroup, aPrincipal, aStoragePrincipal); Document::ResetToURI(aURI, aLoadGroup, aPrincipal, aPartitionedPrincipal);
} }
void XMLDocument::SetSuppressParserErrorElement(bool aSuppress) { void XMLDocument::SetSuppressParserErrorElement(bool aSuppress) {

Просмотреть файл

@ -27,7 +27,7 @@ class XMLDocument : public Document {
virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) override; virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) override;
virtual void ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup, virtual void ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup,
nsIPrincipal* aPrincipal, nsIPrincipal* aPrincipal,
nsIPrincipal* aStoragePrincipal) override; nsIPrincipal* aPartitionedPrincipal) override;
virtual void SetSuppressParserErrorElement(bool aSuppress) override; virtual void SetSuppressParserErrorElement(bool aSuppress) override;
virtual bool SuppressParserErrorElement() override; virtual bool SuppressParserErrorElement() override;

Просмотреть файл

@ -46,7 +46,7 @@ void URIUtils::resolveHref(const nsAString& href, const nsAString& base,
void URIUtils::ResetWithSource(Document* aNewDoc, nsINode* aSourceNode) { void URIUtils::ResetWithSource(Document* aNewDoc, nsINode* aSourceNode) {
nsCOMPtr<Document> sourceDoc = aSourceNode->OwnerDoc(); nsCOMPtr<Document> sourceDoc = aSourceNode->OwnerDoc();
nsIPrincipal* sourcePrincipal = sourceDoc->NodePrincipal(); nsIPrincipal* sourcePrincipal = sourceDoc->NodePrincipal();
nsIPrincipal* sourceStoragePrincipal = sourceDoc->EffectiveStoragePrincipal(); nsIPrincipal* sourcePartitionedPrincipal = sourceDoc->PartitionedPrincipal();
// Copy the channel and loadgroup from the source document. // Copy the channel and loadgroup from the source document.
nsCOMPtr<nsILoadGroup> loadGroup = sourceDoc->GetDocumentLoadGroup(); nsCOMPtr<nsILoadGroup> loadGroup = sourceDoc->GetDocumentLoadGroup();
@ -67,7 +67,7 @@ void URIUtils::ResetWithSource(Document* aNewDoc, nsINode* aSourceNode) {
} }
aNewDoc->Reset(channel, loadGroup); aNewDoc->Reset(channel, loadGroup);
aNewDoc->SetPrincipals(sourcePrincipal, sourceStoragePrincipal); aNewDoc->SetPrincipals(sourcePrincipal, sourcePartitionedPrincipal);
aNewDoc->SetBaseURI(sourceDoc->GetDocBaseURI()); aNewDoc->SetBaseURI(sourceDoc->GetDocBaseURI());
// Inherit the csp if there is one // Inherit the csp if there is one

Просмотреть файл

@ -64,8 +64,8 @@ class ImageCacheKey final {
static void* GetSpecialCaseDocumentToken(dom::Document* aDocument); static void* GetSpecialCaseDocumentToken(dom::Document* aDocument);
// For anti-tracking we need to use an isolation key. It can be the suffix of // For anti-tracking we need to use an isolation key. It can be the suffix of
// the IntrinsicStoragePrincipal (see StoragePrincipalHelper.h) or the // the PatitionedPrincipal (see StoragePrincipalHelper.h) or the top-level
// top-level document's base domain. This is handled by this method. // document's base domain. This is handled by this method.
static nsCString GetIsolationKey(dom::Document* aDocument, nsIURI* aURI); static nsCString GetIsolationKey(dom::Document* aDocument, nsIURI* aURI);
void EnsureHash() const; void EnsureHash() const;

Просмотреть файл

@ -35,9 +35,7 @@ class BackstagePass : public nsIGlobalObject,
return mPrincipal; return mPrincipal;
} }
virtual nsIPrincipal* IntrinsicStoragePrincipal() override { virtual nsIPrincipal* PartitionedPrincipal() override { return mPrincipal; }
return mPrincipal;
}
JSObject* GetGlobalJSObject() override; JSObject* GetGlobalJSObject() override;
JSObject* GetGlobalJSObjectPreserveColor() const override; JSObject* GetGlobalJSObjectPreserveColor() const override;

Просмотреть файл

@ -46,7 +46,7 @@ class SandboxPrivate : public nsIGlobalObject,
nsIPrincipal* GetEffectiveStoragePrincipal() override { return mPrincipal; } nsIPrincipal* GetEffectiveStoragePrincipal() override { return mPrincipal; }
nsIPrincipal* IntrinsicStoragePrincipal() override { return mPrincipal; } nsIPrincipal* PartitionedPrincipal() override { return mPrincipal; }
JSObject* GetGlobalJSObject() override { return GetWrapper(); } JSObject* GetGlobalJSObject() override { return GetWrapper(); }
JSObject* GetGlobalJSObjectPreserveColor() const override { JSObject* GetGlobalJSObjectPreserveColor() const override {

Просмотреть файл

@ -226,7 +226,7 @@ nsContentDLF::CreateInstanceForDocument(nsISupports* aContainer,
/* static */ /* static */
already_AddRefed<Document> nsContentDLF::CreateBlankDocument( already_AddRefed<Document> nsContentDLF::CreateBlankDocument(
nsILoadGroup* aLoadGroup, nsIPrincipal* aPrincipal, nsILoadGroup* aLoadGroup, nsIPrincipal* aPrincipal,
nsIPrincipal* aStoragePrincipal, nsDocShell* aContainer) { nsIPrincipal* aPartitionedPrincipal, nsDocShell* aContainer) {
// create a new blank HTML document // create a new blank HTML document
RefPtr<Document> blankDoc; RefPtr<Document> blankDoc;
mozilla::Unused << NS_NewHTMLDocument(getter_AddRefs(blankDoc)); mozilla::Unused << NS_NewHTMLDocument(getter_AddRefs(blankDoc));
@ -241,7 +241,7 @@ already_AddRefed<Document> nsContentDLF::CreateBlankDocument(
if (!uri) { if (!uri) {
return nullptr; return nullptr;
} }
blankDoc->ResetToURI(uri, aLoadGroup, aPrincipal, aStoragePrincipal); blankDoc->ResetToURI(uri, aLoadGroup, aPrincipal, aPartitionedPrincipal);
blankDoc->SetContainer(aContainer); blankDoc->SetContainer(aContainer);
// add some simple content structure // add some simple content structure

Просмотреть файл

@ -46,7 +46,7 @@ class nsContentDLF final : public nsIDocumentLoaderFactory {
*/ */
static already_AddRefed<mozilla::dom::Document> CreateBlankDocument( static already_AddRefed<mozilla::dom::Document> CreateBlankDocument(
nsILoadGroup* aLoadGroup, nsIPrincipal* aPrincipal, nsILoadGroup* aLoadGroup, nsIPrincipal* aPrincipal,
nsIPrincipal* aStoragePrincipal, nsDocShell* aContainer); nsIPrincipal* aPartitionedPrincipal, nsDocShell* aContainer);
private: private:
static nsresult EnsureUAStyleSheet(); static nsresult EnsureUAStyleSheet();

Просмотреть файл

@ -17,7 +17,7 @@ namespace mozilla {
namespace { namespace {
bool ChooseOriginAttributes(nsIChannel* aChannel, OriginAttributes& aAttrs, bool ChooseOriginAttributes(nsIChannel* aChannel, OriginAttributes& aAttrs,
bool aForceInstrinsicStoragePrincipal) { bool aForcePartitionedPrincipal) {
MOZ_ASSERT(aChannel); MOZ_ASSERT(aChannel);
nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo(); nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
@ -26,7 +26,7 @@ bool ChooseOriginAttributes(nsIChannel* aChannel, OriginAttributes& aAttrs,
return false; return false;
} }
if (!aForceInstrinsicStoragePrincipal) { if (!aForcePartitionedPrincipal) {
nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIURI> uri;
nsresult rv = aChannel->GetURI(getter_AddRefs(uri)); nsresult rv = aChannel->GetURI(getter_AddRefs(uri));
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
@ -80,6 +80,7 @@ bool ChooseOriginAttributes(nsIChannel* aChannel, OriginAttributes& aAttrs,
// static // static
nsresult StoragePrincipalHelper::Create(nsIChannel* aChannel, nsresult StoragePrincipalHelper::Create(nsIChannel* aChannel,
nsIPrincipal* aPrincipal, nsIPrincipal* aPrincipal,
bool aForceIsolation,
nsIPrincipal** aStoragePrincipal) { nsIPrincipal** aStoragePrincipal) {
MOZ_ASSERT(aChannel); MOZ_ASSERT(aChannel);
MOZ_ASSERT(aPrincipal); MOZ_ASSERT(aPrincipal);
@ -91,7 +92,7 @@ nsresult StoragePrincipalHelper::Create(nsIChannel* aChannel,
}); });
OriginAttributes attrs = aPrincipal->OriginAttributesRef(); OriginAttributes attrs = aPrincipal->OriginAttributesRef();
if (!ChooseOriginAttributes(aChannel, attrs, false)) { if (!ChooseOriginAttributes(aChannel, attrs, aForceIsolation)) {
return NS_OK; return NS_OK;
} }
@ -283,20 +284,7 @@ void StoragePrincipalHelper::GetOriginAttributesForNetworkState(
return; return;
} }
// This part is required because the intrisicStoragePrincipal is not always aAttributes = aDocument->PartitionedPrincipal()->OriginAttributesRef();
// partitioned. This should probably change. TODO - bug 1639833.
nsCOMPtr<nsICookieJarSettings> cjs = aDocument->CookieJarSettings();
MOZ_ASSERT(cjs);
nsAutoString domain;
Unused << cjs->GetFirstPartyDomain(domain);
if (!domain.IsEmpty()) {
aAttributes.SetFirstPartyDomain(false, domain, true /* aForced */);
return;
}
aAttributes = aDocument->IntrinsicStoragePrincipal()->OriginAttributesRef();
} }
} // namespace mozilla } // namespace mozilla

Просмотреть файл

@ -59,23 +59,27 @@
* From a Document: * From a Document:
* - Regular Principal: nsINode::NodePrincipal * - Regular Principal: nsINode::NodePrincipal
* - Storage Access Principal: Document::EffectiveStoragePrincipal * - Storage Access Principal: Document::EffectiveStoragePrincipal
* - Partitioned Principal: Document::IntrinsicStoragePrincipal * - Partitioned Principal: Document::PartitionedPrincipal
* *
* From a Global object: * From a Global object:
* - Regular Principal: nsIScriptObjectPrincipal::GetPrincipal * - Regular Principal: nsIScriptObjectPrincipal::GetPrincipal
* - Storage Access Principal: * - Storage Access Principal:
* nsIScriptObjectPrincipal::GetEffectiveStoragePrincipal * nsIScriptObjectPrincipal::GetEffectiveStoragePrincipal
* - Partitioned Principal: nsIScriptObjectPrincipal::IntrinsicStoragePrincipal * - Partitioned Principal: nsIScriptObjectPrincipal::PartitionedPrincipal
* *
* From a Worker: * From a Worker:
* - Regular Principal: WorkerPrivate::GetPrincipal * - Regular Principal: WorkerPrivate::GetPrincipal (main-thread)
* - Storage Access Principal: WorkerPrivate::GetEffectiveStoragePrincipal * - Regular Principal: WorkerPrivate::GetPrincipalInfo (worker thread)
* - Storage Access Principal: WorkerPrivate::GetEffectiveStoragePrincipalInfo
* (worker-thread)
* *
* For a nsIChannel, the final principals must be calculated and they can be * For a nsIChannel, the final principals must be calculated and they can be
* obtained by calling: * obtained by calling:
* - Regular Principal: nsIScriptSecurityManager::getChannelResultPrincipal * - Regular Principal: nsIScriptSecurityManager::getChannelResultPrincipal
* - Storage Access Principal: * - Storage Access Principal:
* nsIScriptSecurityManager::getChannelResultStoragePrincipal * nsIScriptSecurityManager::getChannelResultStoragePrincipal
* - Partitioned and regular Principal:
* nsIScriptSecurityManager::getChannelResultPrincipals
* *
* Each use of nsIPrincipal is unique and it should be reviewed by anti-tracking * Each use of nsIPrincipal is unique and it should be reviewed by anti-tracking
* peers. But we can group the use of nsIPrincipal in these categories: * peers. But we can group the use of nsIPrincipal in these categories:
@ -214,6 +218,7 @@ class OriginAttributes;
class StoragePrincipalHelper final { class StoragePrincipalHelper final {
public: public:
static nsresult Create(nsIChannel* aChannel, nsIPrincipal* aPrincipal, static nsresult Create(nsIChannel* aChannel, nsIPrincipal* aPrincipal,
bool aForceIsolation,
nsIPrincipal** aStoragePrincipal); nsIPrincipal** aStoragePrincipal);
static nsresult PrepareEffectiveStoragePrincipalOriginAttributes( static nsresult PrepareEffectiveStoragePrincipalOriginAttributes(
@ -229,7 +234,7 @@ class StoragePrincipalHelper final {
// This is a dynamic principal based on the current state of the origin. If // This is a dynamic principal based on the current state of the origin. If
// the origin has the storage permission granted, effective storagePrincipal // the origin has the storage permission granted, effective storagePrincipal
// will be the regular principal, otherwise, the intrinsic storagePrincipal // will be the regular principal, otherwise, the partitioned Principal
// will be used. // will be used.
eStorageAccessPrincipal, eStorageAccessPrincipal,

Просмотреть файл

@ -1097,7 +1097,7 @@ static void ReadAllEntriesFromStorage(nsPIDOMWindowOuter* aWindow,
return; return;
} }
nsCOMPtr<nsIPrincipal> storagePrincipal = doc->IntrinsicStoragePrincipal(); nsCOMPtr<nsIPrincipal> storagePrincipal = doc->EffectiveStoragePrincipal();
if (!storagePrincipal) { if (!storagePrincipal) {
return; return;
} }

Просмотреть файл

@ -35,16 +35,16 @@ addMessageListener("BrowserElement:CreateAboutBlank", message => {
if (!content.document || content.document.documentURI != "about:blank") { if (!content.document || content.document.documentURI != "about:blank") {
throw new Error("Can't create a content viewer unless on about:blank"); throw new Error("Can't create a content viewer unless on about:blank");
} }
let { principal, storagePrincipal } = message.data; let { principal, partitionedPrincipal } = message.data;
principal = BrowserUtils.principalWithMatchingOA( principal = BrowserUtils.principalWithMatchingOA(
principal, principal,
content.document.nodePrincipal content.document.nodePrincipal
); );
storagePrincipal = BrowserUtils.principalWithMatchingOA( partitionedPrincipal = BrowserUtils.principalWithMatchingOA(
storagePrincipal, partitionedPrincipal,
content.document.effectiveStoragePrincipal content.document.partitionedPrincipal
); );
docShell.createAboutBlankContentViewer(principal, storagePrincipal); docShell.createAboutBlankContentViewer(principal, partitionedPrincipal);
}); });
// We may not get any responses to Browser:Init if the browser element // We may not get any responses to Browser:Init if the browser element

Просмотреть файл

@ -265,7 +265,7 @@
this._contentPrincipal = null; this._contentPrincipal = null;
this._contentStoragePrincipal = null; this._contentPartitionedPrincipal = null;
this._csp = null; this._csp = null;
@ -704,10 +704,10 @@
: this.contentDocument.nodePrincipal; : this.contentDocument.nodePrincipal;
} }
get contentStoragePrincipal() { get contentPartitionedPrincipal() {
return this.isRemoteBrowser return this.isRemoteBrowser
? this._contentStoragePrincipal ? this._contentPartitionedPrincipal
: this.contentDocument.effectiveStoragePrincipal; : this.contentDocument.partitionedPrincipal;
} }
get contentBlockingAllowListPrincipal() { get contentBlockingAllowListPrincipal() {
@ -1279,7 +1279,7 @@
aDocumentURI, aDocumentURI,
aTitle, aTitle,
aContentPrincipal, aContentPrincipal,
aContentStoragePrincipal, aContentPartitionedPrincipal,
aCSP, aCSP,
aReferrerInfo, aReferrerInfo,
aIsSynthetic, aIsSynthetic,
@ -1302,7 +1302,7 @@
this._remoteWebNavigation._currentURI = aLocation; this._remoteWebNavigation._currentURI = aLocation;
this._documentURI = aDocumentURI; this._documentURI = aDocumentURI;
this._contentPrincipal = aContentPrincipal; this._contentPrincipal = aContentPrincipal;
this._contentStoragePrincipal = aContentStoragePrincipal; this._contentPartitionedPrincipal = aContentPartitionedPrincipal;
this._csp = aCSP; this._csp = aCSP;
this._referrerInfo = aReferrerInfo; this._referrerInfo = aReferrerInfo;
this._isSyntheticDocument = aIsSynthetic; this._isSyntheticDocument = aIsSynthetic;
@ -1333,7 +1333,7 @@
} }
} }
createAboutBlankContentViewer(aPrincipal, aStoragePrincipal) { createAboutBlankContentViewer(aPrincipal, aPartitionedPrincipal) {
if (this.isRemoteBrowser) { if (this.isRemoteBrowser) {
// Ensure that the content process has the permissions which are // Ensure that the content process has the permissions which are
// needed to create a document with the given principal. // needed to create a document with the given principal.
@ -1359,7 +1359,7 @@
// solution. // solution.
this.messageManager.sendAsyncMessage( this.messageManager.sendAsyncMessage(
"BrowserElement:CreateAboutBlank", "BrowserElement:CreateAboutBlank",
{ principal: aPrincipal, storagePrincipal: aStoragePrincipal } { principal: aPrincipal, partitionedPrincipal: aPartitionedPrincipal }
); );
return; return;
} }
@ -1367,11 +1367,14 @@
aPrincipal, aPrincipal,
this.contentPrincipal this.contentPrincipal
); );
let storagePrincipal = BrowserUtils.principalWithMatchingOA( let partitionedPrincipal = BrowserUtils.principalWithMatchingOA(
aStoragePrincipal, aPartitionedPrincipal,
this.contentStoragePrincipal this.contentPartitionedPrincipal
);
this.docShell.createAboutBlankContentViewer(
principal,
partitionedPrincipal
); );
this.docShell.createAboutBlankContentViewer(principal, storagePrincipal);
} }
stopScroll() { stopScroll() {
@ -1699,7 +1702,7 @@
"_mayEnableCharacterEncodingMenu", "_mayEnableCharacterEncodingMenu",
"_charsetAutodetected", "_charsetAutodetected",
"_contentPrincipal", "_contentPrincipal",
"_contentStoragePrincipal", "_contentPartitionedPrincipal",
"_isSyntheticDocument", "_isSyntheticDocument",
"_innerWindowID", "_innerWindowID",
] ]

Просмотреть файл

@ -270,9 +270,9 @@ var SessionHistoryInternal = {
); );
} }
if (shEntry.storagePrincipalToInherit) { if (shEntry.partitionedPrincipalToInherit) {
entry.storagePrincipalToInherit_base64 = E10SUtils.serializePrincipal( entry.partitionedPrincipalToInherit_base64 = E10SUtils.serializePrincipal(
shEntry.storagePrincipalToInherit shEntry.partitionedPrincipalToInherit
); );
} }
@ -551,11 +551,11 @@ var SessionHistoryInternal = {
return Services.scriptSecurityManager.createNullPrincipal({}); return Services.scriptSecurityManager.createNullPrincipal({});
} }
); );
// As both storagePrincipal and principalToInherit are both not required to load // As both partitionedPrincipal and principalToInherit are both not required to load
// it's ok to keep these undefined when we don't have a previously defined principal. // it's ok to keep these undefined when we don't have a previously defined principal.
if (entry.storagePrincipalToInherit_base64) { if (entry.partitionedPrincipalToInherit_base64) {
shEntry.storagePrincipalToInherit = E10SUtils.deserializePrincipal( shEntry.partitionedPrincipalToInherit = E10SUtils.deserializePrincipal(
entry.storagePrincipalToInherit_base64 entry.partitionedPrincipalToInherit_base64
); );
} }
if (entry.principalToInherit_base64) { if (entry.principalToInherit_base64) {