From ae8751a56d3b928b828f07282ee7b9b67adb9f7b Mon Sep 17 00:00:00 2001 From: Dimi Lee Date: Tue, 19 May 2020 09:47:25 +0000 Subject: [PATCH] Bug 1637194 - P2. Set firstPartyDomain to CookieJarSetting in nsHttpChannel::AsyncOpen r=necko-reviewers,timhuang,baku,kershaw FirstPartyDomain is only set while loading a top-level document. We added in nsHttpChannel::AsyncOpen to ensure that the value is updated whenever we open a channel. Differential Revision: https://phabricator.services.mozilla.com/D75277 --- netwerk/ipc/DocumentLoadListener.cpp | 1 + netwerk/protocol/http/nsHttpChannel.cpp | 26 ++++++++++++++++++++----- netwerk/protocol/http/nsHttpChannel.h | 5 +++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/netwerk/ipc/DocumentLoadListener.cpp b/netwerk/ipc/DocumentLoadListener.cpp index a547c2d85bc4..b934edef74d3 100644 --- a/netwerk/ipc/DocumentLoadListener.cpp +++ b/netwerk/ipc/DocumentLoadListener.cpp @@ -433,6 +433,7 @@ bool DocumentLoadListener::Open( httpBaseChannel->SetTopWindowURI(topWindowURI); } + // TODO: Remove this in Bug 1639140 Unused << loadInfo->SetHasStoragePermission( AntiTrackingUtils::HasStoragePermissionInParent(mChannel)); diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index 1720fbe6d8dd..93e7b7ea8d53 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -1857,6 +1857,25 @@ void nsHttpChannel::SetCachedContentType() { mCacheEntry->SetContentType(contentType); } +void nsHttpChannel::UpdateAntiTrackingInfo() { + Unused << mLoadInfo->SetHasStoragePermission( + AntiTrackingUtils::HasStoragePermissionInParent(this)); + + AntiTrackingUtils::ComputeIsThirdPartyToTopWindow(this); + + // We only need to set FPD for top-level loads. FPD will automatically be + // propagated to non-top level loads via CookieJarSetting. + if (mLoadInfo->GetExternalContentPolicyType() == + nsIContentPolicy::TYPE_DOCUMENT) { + nsCOMPtr cookieJarSettings; + Unused << mLoadInfo->GetCookieJarSettings( + getter_AddRefs(cookieJarSettings)); + + mozilla::net::CookieJarSettings::Cast(cookieJarSettings) + ->SetFirstPartyDomain(mURI); + } +} + nsresult nsHttpChannel::CallOnStartRequest() { LOG(("nsHttpChannel::CallOnStartRequest [this=%p]", this)); @@ -6506,11 +6525,6 @@ nsHttpChannel::AsyncOpen(nsIStreamListener* aListener) { return NS_ERROR_NOT_AVAILABLE; } - Unused << mLoadInfo->SetHasStoragePermission( - AntiTrackingUtils::HasStoragePermissionInParent(this)); - - AntiTrackingUtils::ComputeIsThirdPartyToTopWindow(this); - static bool sRCWNInited = false; if (!sRCWNInited) { sRCWNInited = true; @@ -6542,6 +6556,8 @@ nsHttpChannel::AsyncOpen(nsIStreamListener* aListener) { UpdatePrivateBrowsing(); } + UpdateAntiTrackingInfo(); + if (WaitingForTailUnblock()) { // This channel is marked as Tail and is part of a request context // that has positive number of non-tailed requestst, hence this channel diff --git a/netwerk/protocol/http/nsHttpChannel.h b/netwerk/protocol/http/nsHttpChannel.h index 13b77b6616e6..e1c735b9ef48 100644 --- a/netwerk/protocol/http/nsHttpChannel.h +++ b/netwerk/protocol/http/nsHttpChannel.h @@ -569,6 +569,11 @@ class nsHttpChannel final : public HttpBaseChannel, // writing a new entry. The content type is used in cache internally only. void SetCachedContentType(); + // This function updates all the fields used by anti-tracking when a channel + // is opened. We have to do this in the parent to access cross-origin info + // that is not exposed to child processes. + void UpdateAntiTrackingInfo(); + private: // this section is for main-thread-only object // all the references need to be proxy released on main thread.