Bug 1637634 - Update IsOnContentBlockingAllowList in nsHttpChannel::AsyncOpen r=timhuang,necko-reviewers

This patch removes TYPE_DOCUMENT test in test_shouldclassify because the
testcase creates a non-top level channel with TYPE_DOCUMENT flag (this is wong!),
which triggers the assertion in UpdateIsOnContentBlockingAllowList.

File a follow-up bug 1640715 to add TYPE_DOCUMENT test back.

Differential Revision: https://phabricator.services.mozilla.com/D76152
This commit is contained in:
Dimi Lee 2020-05-25 18:30:43 +00:00
Родитель d2c1b033d5
Коммит ed4c44789a
4 изменённых файлов: 19 добавлений и 25 удалений

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

@ -431,19 +431,22 @@ void CookieJarSettings::UpdateIsOnContentBlockingAllowList(
MOZ_ASSERT(bc->IsTop());
#endif
nsCOMPtr<nsIURI> uriBeingLoaded =
AntiTrackingUtils::MaybeGetDocumentURIBeingLoaded(aChannel);
nsCOMPtr<nsIPrincipal> contentBlockingAllowListPrincipal;
nsCOMPtr<nsIURI> uri;
nsresult rv = aChannel->GetURI(getter_AddRefs(uri));
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
// We need to recompute the ContentBlockingAllowListPrincipal here for the
// top level channel because we might navigate from the the initial
// about:blank page or the existing page which may have a different origin
// than the URI we are going to load here. Thus, we need to recompute the
// prinicpal in order to get the correct ContentBlockingAllowListPrincipal.
nsCOMPtr<nsIPrincipal> contentBlockingAllowListPrincipal;
OriginAttributes attrs;
loadInfo->GetOriginAttributes(&attrs);
ContentBlockingAllowList::RecomputePrincipal(
uriBeingLoaded, attrs, getter_AddRefs(contentBlockingAllowListPrincipal));
uri, attrs, getter_AddRefs(contentBlockingAllowListPrincipal));
if (!contentBlockingAllowListPrincipal ||
!contentBlockingAllowListPrincipal->GetIsContentPrincipal()) {

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

@ -8,7 +8,6 @@
#include "DocumentLoadListener.h"
#include "mozilla/AntiTrackingUtils.h"
#include "mozilla/ContentBlockingAllowList.h"
#include "mozilla/LoadInfo.h"
#include "mozilla/MozPromiseInlines.h" // For MozPromise::FromDomPromise
#include "mozilla/StaticPrefs_fission.h"
@ -413,15 +412,6 @@ bool DocumentLoadListener::Open(
// If this is for the top level loading, the top window URI should be the
// URI which we are loading.
topWindowURI = uriBeingLoaded;
// Update the IsOnContentBlockingAllowList flag in the CookieJarSettings
// if this is a top level loading. For sub-document loading, this flag
// would inherit from the parent.
nsCOMPtr<nsICookieJarSettings> cookieJarSettings;
Unused << loadInfo->GetCookieJarSettings(
getter_AddRefs(cookieJarSettings));
net::CookieJarSettings::Cast(cookieJarSettings)
->UpdateIsOnContentBlockingAllowList(mChannel);
} else if (RefPtr<WindowGlobalParent> topWindow = AntiTrackingUtils::
GetTopWindowExcludingExtensionAccessibleContentFrames(
browsingContext, uriBeingLoaded)) {

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

@ -1863,14 +1863,20 @@ void nsHttpChannel::UpdateAntiTrackingInfo() {
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<nsICookieJarSettings> cookieJarSettings;
Unused << mLoadInfo->GetCookieJarSettings(
getter_AddRefs(cookieJarSettings));
// Update the IsOnContentBlockingAllowList flag in the CookieJarSettings
// if this is a top level loading. For sub-document loading, this flag
// would inherit from the parent.
mozilla::net::CookieJarSettings::Cast(cookieJarSettings)
->UpdateIsOnContentBlockingAllowList(this);
// We only need to set FPD for top-level loads. FPD will automatically be
// propagated to non-top level loads via CookieJarSetting.
mozilla::net::CookieJarSettings::Cast(cookieJarSettings)
->SetFirstPartyDomain(mURI);
}

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

@ -16,16 +16,15 @@ var normalOrigin, trackingOrigin;
// ShouldClassify algorithm uses the following parameters:
// 1. Ci.nsIChannel.LOAD_ BYPASS_URL_CLASSIFIER loadflags
// 2. Content type
// 2. Content type // TODO: Bug 1640715 to test this
// 3. triggering principal
// 4. be Conservative
// We test are the combinations here to make sure the algorithm is correct
const PARAM_LOAD_BYPASS_URL_CLASSIFIER = 1 << 0;
const PARAM_CONTENT_POLICY_TYPE_DOCUMENT = 1 << 1;
const PARAM_TRIGGERING_PRINCIPAL_SYSTEM = 1 << 2;
const PARAM_CAP_BE_CONSERVATIVE = 1 << 3;
const PARAM_MAX = 1 << 4;
const PARAM_TRIGGERING_PRINCIPAL_SYSTEM = 1 << 1;
const PARAM_CAP_BE_CONSERVATIVE = 1 << 2;
const PARAM_MAX = 1 << 3;
function getParameters(bitFlags) {
var params = {
@ -39,10 +38,6 @@ function getParameters(bitFlags) {
params.loadFlags = Ci.nsIChannel.LOAD_BYPASS_URL_CLASSIFIER;
}
if (bitFlags & PARAM_CONTENT_POLICY_TYPE_DOCUMENT) {
params.contentType = Ci.nsIContentPolicy.TYPE_DOCUMENT;
}
if (bitFlags & PARAM_TRIGGERING_PRINCIPAL_SYSTEM) {
params.system = true;
}