From bebf6a1109e33faaca9c40ff6b45fb6e8be5d646 Mon Sep 17 00:00:00 2001 From: Tim Huang Date: Tue, 24 May 2022 08:17:28 +0000 Subject: [PATCH] Bug 1768193 - Part 1: Use maybe to hold mIsThirdPartyContextToTopWindow in LoadInfo. r=anti-tracking-reviewers,necko-reviewers,bvandersloot,kershaw In order to know if the mIsThirdPartyContextToTopWindow was set in the loadInfo of the channel, we use maybe to hold the value. So, we can know if it was set before. This patch also addes two methods in LoadInfo to clear and know if the value is set. Differential Revision: https://phabricator.services.mozilla.com/D146491 --- ipc/glue/BackgroundUtils.cpp | 37 ++++++++++++++++++++++------ netwerk/base/LoadInfo.cpp | 7 +++--- netwerk/base/LoadInfo.h | 14 ++++++++--- netwerk/ipc/NeckoChannelParams.ipdlh | 4 +-- 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/ipc/glue/BackgroundUtils.cpp b/ipc/glue/BackgroundUtils.cpp index ebeab035cea8..df63b2b4b123 100644 --- a/ipc/glue/BackgroundUtils.cpp +++ b/ipc/glue/BackgroundUtils.cpp @@ -490,6 +490,13 @@ nsresult LoadInfoToLoadInfoArgs(nsILoadInfo* aLoadInfo, nsCOMPtr unstrippedURI; Unused << aLoadInfo->GetUnstrippedURI(getter_AddRefs(unstrippedURI)); + Maybe isThirdPartyContextToTopWindow; + if (static_cast(aLoadInfo) + ->HasIsThirdPartyContextToTopWindowSet()) { + isThirdPartyContextToTopWindow.emplace( + aLoadInfo->GetIsThirdPartyContextToTopWindow()); + } + *aOptionalLoadInfoArgs = Some(LoadInfoArgs( loadingPrincipalInfo, triggeringPrincipalInfo, principalToInheritInfo, topLevelPrincipalInfo, optionalResultPrincipalURI, @@ -510,8 +517,7 @@ nsresult LoadInfoToLoadInfoArgs(nsILoadInfo* aLoadInfo, aLoadInfo->GetInnerWindowID(), aLoadInfo->GetBrowsingContextID(), aLoadInfo->GetFrameBrowsingContextID(), aLoadInfo->GetInitialSecurityCheckDone(), - aLoadInfo->GetIsInThirdPartyContext(), - aLoadInfo->GetIsThirdPartyContextToTopWindow(), + aLoadInfo->GetIsInThirdPartyContext(), isThirdPartyContextToTopWindow, aLoadInfo->GetIsFormSubmission(), aLoadInfo->GetSendCSPViolationEvents(), aLoadInfo->GetOriginAttributes(), redirectChainIncludingInternalRedirects, redirectChain, ipcClientInfo, ipcReservedClientInfo, ipcInitialClientInfo, @@ -728,6 +734,12 @@ nsresult LoadInfoArgsToLoadInfo( loadingContext = frameBrowsingContext->GetEmbedderElement(); } + Maybe isThirdPartyContextToTopWindow; + if (loadInfoArgs.isThirdPartyContextToTopWindow().isSome()) { + isThirdPartyContextToTopWindow.emplace( + loadInfoArgs.isThirdPartyContextToTopWindow().ref()); + } + RefPtr loadInfo = new mozilla::net::LoadInfo( loadingPrincipal, triggeringPrincipal, principalToInherit, topLevelPrincipal, resultPrincipalURI, cookieJarSettings, cspToInherit, @@ -748,8 +760,7 @@ nsresult LoadInfoArgsToLoadInfo( loadInfoArgs.forceInheritPrincipalDropped(), loadInfoArgs.innerWindowID(), loadInfoArgs.browsingContextID(), loadInfoArgs.frameBrowsingContextID(), loadInfoArgs.initialSecurityCheckDone(), - loadInfoArgs.isInThirdPartyContext(), - loadInfoArgs.isThirdPartyContextToTopWindow(), + loadInfoArgs.isInThirdPartyContext(), isThirdPartyContextToTopWindow, loadInfoArgs.isFormSubmission(), loadInfoArgs.sendCSPViolationEvents(), loadInfoArgs.originAttributes(), std::move(redirectChainIncludingInternalRedirects), @@ -817,6 +828,13 @@ void LoadInfoToParentLoadInfoForwarder( nsCOMPtr unstrippedURI; Unused << aLoadInfo->GetUnstrippedURI(getter_AddRefs(unstrippedURI)); + Maybe isThirdPartyContextToTopWindow; + if (static_cast(aLoadInfo) + ->HasIsThirdPartyContextToTopWindowSet()) { + isThirdPartyContextToTopWindow.emplace( + aLoadInfo->GetIsThirdPartyContextToTopWindow()); + } + *aForwarderArgsOut = ParentLoadInfoForwarderArgs( aLoadInfo->GetAllowInsecureRedirectToDataURI(), ipcController, tainting, aLoadInfo->GetSkipContentSniffing(), aLoadInfo->GetHttpsOnlyStatus(), @@ -829,8 +847,8 @@ void LoadInfoToParentLoadInfoForwarder( aLoadInfo->GetAllowListFutureDocumentsCreatedFromThisRedirectChain(), cookieJarSettingsArgs, aLoadInfo->GetRequestBlockingReason(), aLoadInfo->GetStoragePermission(), aLoadInfo->GetIsMetaRefresh(), - aLoadInfo->GetIsThirdPartyContextToTopWindow(), - aLoadInfo->GetIsInThirdPartyContext(), unstrippedURI); + isThirdPartyContextToTopWindow, aLoadInfo->GetIsInThirdPartyContext(), + unstrippedURI); } nsresult MergeParentLoadInfoForwarder( @@ -905,8 +923,11 @@ nsresult MergeParentLoadInfoForwarder( rv = aLoadInfo->SetIsMetaRefresh(aForwarderArgs.isMetaRefresh()); NS_ENSURE_SUCCESS(rv, rv); - rv = aLoadInfo->SetIsThirdPartyContextToTopWindow( - aForwarderArgs.isThirdPartyContextToTopWindow()); + static_cast(aLoadInfo)->ClearIsThirdPartyContextToTopWindow(); + if (aForwarderArgs.isThirdPartyContextToTopWindow().isSome()) { + rv = aLoadInfo->SetIsThirdPartyContextToTopWindow( + aForwarderArgs.isThirdPartyContextToTopWindow().ref()); + } NS_ENSURE_SUCCESS(rv, rv); rv = aLoadInfo->SetIsInThirdPartyContext( diff --git a/netwerk/base/LoadInfo.cpp b/netwerk/base/LoadInfo.cpp index 06461c121a3d..c70ae05224c3 100644 --- a/netwerk/base/LoadInfo.cpp +++ b/netwerk/base/LoadInfo.cpp @@ -612,7 +612,7 @@ LoadInfo::LoadInfo( bool aForceInheritPrincipalDropped, uint64_t aInnerWindowID, uint64_t aBrowsingContextID, uint64_t aFrameBrowsingContextID, bool aInitialSecurityCheckDone, bool aIsThirdPartyContext, - bool aIsThirdPartyContextToTopWindow, bool aIsFormSubmission, + const Maybe& aIsThirdPartyContextToTopWindow, bool aIsFormSubmission, bool aSendCSPViolationEvents, const OriginAttributes& aOriginAttributes, RedirectHistoryArray&& aRedirectChainIncludingInternalRedirects, RedirectHistoryArray&& aRedirectChain, @@ -978,14 +978,15 @@ LoadInfo::SetIsInThirdPartyContext(bool aIsInThirdPartyContext) { NS_IMETHODIMP LoadInfo::GetIsThirdPartyContextToTopWindow( bool* aIsThirdPartyContextToTopWindow) { - *aIsThirdPartyContextToTopWindow = mIsThirdPartyContextToTopWindow; + *aIsThirdPartyContextToTopWindow = + mIsThirdPartyContextToTopWindow.valueOr(true); return NS_OK; } NS_IMETHODIMP LoadInfo::SetIsThirdPartyContextToTopWindow( bool aIsThirdPartyContextToTopWindow) { - mIsThirdPartyContextToTopWindow = aIsThirdPartyContextToTopWindow; + mIsThirdPartyContextToTopWindow = Some(aIsThirdPartyContextToTopWindow); return NS_OK; } diff --git a/netwerk/base/LoadInfo.h b/netwerk/base/LoadInfo.h index 5ccb50fbcfe3..6452948b199c 100644 --- a/netwerk/base/LoadInfo.h +++ b/netwerk/base/LoadInfo.h @@ -178,6 +178,13 @@ class LoadInfo final : public nsILoadInfo { mCspToInherit = aCspToInherit; } + bool HasIsThirdPartyContextToTopWindowSet() { + return mIsThirdPartyContextToTopWindow.isSome(); + } + void ClearIsThirdPartyContextToTopWindow() { + mIsThirdPartyContextToTopWindow.reset(); + } + private: // private constructor that is only allowed to be called from within // HttpChannelParent and FTPChannelParent declared as friends undeneath. @@ -204,8 +211,9 @@ class LoadInfo final : public nsILoadInfo { bool aForceInheritPrincipalDropped, uint64_t aInnerWindowID, uint64_t aBrowsingContextID, uint64_t aFrameBrowsingContextID, bool aInitialSecurityCheckDone, bool aIsThirdPartyContext, - bool aIsThirdPartyContextToTopWindow, bool aIsFormSubmission, - bool aSendCSPViolationEvents, const OriginAttributes& aOriginAttributes, + const Maybe& aIsThirdPartyContextToTopWindow, + bool aIsFormSubmission, bool aSendCSPViolationEvents, + const OriginAttributes& aOriginAttributes, RedirectHistoryArray&& aRedirectChainIncludingInternalRedirects, RedirectHistoryArray&& aRedirectChain, nsTArray>&& aAncestorPrincipals, @@ -300,7 +308,7 @@ class LoadInfo final : public nsILoadInfo { bool mInitialSecurityCheckDone = false; // NB: TYPE_DOCUMENT implies !third-party. bool mIsThirdPartyContext = false; - bool mIsThirdPartyContextToTopWindow = true; + Maybe mIsThirdPartyContextToTopWindow; bool mIsFormSubmission = false; bool mSendCSPViolationEvents = true; OriginAttributes mOriginAttributes; diff --git a/netwerk/ipc/NeckoChannelParams.ipdlh b/netwerk/ipc/NeckoChannelParams.ipdlh index d9b4d66e6669..91484637f1a8 100644 --- a/netwerk/ipc/NeckoChannelParams.ipdlh +++ b/netwerk/ipc/NeckoChannelParams.ipdlh @@ -108,7 +108,7 @@ struct LoadInfoArgs uint64_t frameBrowsingContextID; bool initialSecurityCheckDone; bool isInThirdPartyContext; - bool isThirdPartyContextToTopWindow; + bool? isThirdPartyContextToTopWindow; bool isFormSubmission; bool sendCSPViolationEvents; OriginAttributes originAttributes; @@ -230,7 +230,7 @@ struct ParentLoadInfoForwarderArgs bool isMetaRefresh; - bool isThirdPartyContextToTopWindow; + bool? isThirdPartyContextToTopWindow; bool isInThirdPartyContext;