Backed out 3 changesets (bug 1622212) for causing wpt failures on requestStorageAccess.sub.window.html on central.

Backed out changeset a20db87bec25 (bug 1622212)
Backed out changeset 783ef2b63ef8 (bug 1622212)
Backed out changeset ece4c5394185 (bug 1622212)
This commit is contained in:
Cosmin Sabou 2020-07-01 02:33:27 +03:00
parent b707f6e54b
commit 16c941758d
16 changed files with 110 additions and 202 deletions

View File

@ -2460,12 +2460,51 @@ nsresult nsGlobalWindowOuter::SetNewDocument(Document* aDocument,
PreloadLocalStorage();
mStorageAccessPermissionGranted = ContentBlocking::ShouldAllowAccessFor(
newInnerWindow, aDocument->GetDocumentURI(), nullptr);
mStorageAccessPermissionGranted =
CheckStorageAccessPermission(aDocument, newInnerWindow);
return NS_OK;
}
bool nsGlobalWindowOuter::CheckStorageAccessPermission(
Document* aDocument, nsGlobalWindowInner* aInnerWindow) {
if (!aInnerWindow) {
return false;
}
nsIURI* uri = aDocument->GetDocumentURI();
if (!aDocument->CookieJarSettings()->GetRejectThirdPartyContexts() ||
!nsContentUtils::IsThirdPartyWindowOrChannel(aInnerWindow, nullptr,
uri)) {
return false;
}
uint32_t cookieBehavior = aDocument->CookieJarSettings()->GetCookieBehavior();
// Grant storage access by default if the first-party storage access
// permission has been granted already. Don't notify in this case, since we
// would be notifying the user needlessly.
bool checkStorageAccess = false;
if (net::CookieJarSettings::IsRejectThirdPartyWithExceptions(
cookieBehavior)) {
checkStorageAccess = true;
} else {
MOZ_ASSERT(
cookieBehavior == nsICookieService::BEHAVIOR_REJECT_TRACKER ||
cookieBehavior ==
nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN);
if (nsContentUtils::IsThirdPartyTrackingResourceWindow(aInnerWindow)) {
checkStorageAccess = true;
}
}
if (checkStorageAccess) {
return ContentBlocking::ShouldAllowAccessFor(aInnerWindow, uri, nullptr);
}
return false;
}
/* static */
void nsGlobalWindowOuter::PrepareForProcessChange(JSObject* aProxy) {
JS::Rooted<JSObject*> localProxy(RootingCx(), aProxy);

View File

@ -1035,6 +1035,9 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,
bool IsOnlyTopLevelDocumentInSHistory();
bool CheckStorageAccessPermission(Document* aDocument,
nsGlobalWindowInner* aInnerWindow);
public:
// Dispatch a runnable related to the global.
virtual nsresult Dispatch(mozilla::TaskCategory aCategory,

View File

@ -81,7 +81,6 @@ skip-if = os == "linux" && asan
[browser_doublyNestedTracker.js]
[browser_existingCookiesForSubresources.js]
[browser_firstPartyCookieRejectionHonoursAllowList.js]
[browser_hasStorageAccess.js]
[browser_imageCache4.js]
[browser_imageCache8.js]
[browser_onBeforeRequestNotificationForTrackingResources.js]

View File

@ -120,7 +120,11 @@ AntiTracking.runTestInNormalAndPrivateMode(
// Non blocking callback
async _ => {
/* import-globals-from storageAccessAPIHelpers.js */
await hasStorageAccessInitially();
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
is(document.cookie, "", "No cookies for me");

View File

@ -70,7 +70,11 @@ AntiTracking.runTest(
},
async _ => {
/* import-globals-from storageAccessAPIHelpers.js */
await hasStorageAccessInitially();
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
await caches.open("wow").then(
_ => {

View File

@ -70,7 +70,11 @@ AntiTracking.runTestInNormalAndPrivateMode(
// non-blocking callback
async _ => {
/* import-globals-from storageAccessAPIHelpers.js */
await hasStorageAccessInitially();
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
indexedDB.open("test", "1");
ok(true, "IDB should be allowed");

View File

@ -86,7 +86,11 @@ AntiTracking.runTestInNormalAndPrivateMode(
}
/* import-globals-from storageAccessAPIHelpers.js */
await hasStorageAccessInitially();
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
let blob = new Blob([nonBlockCode.toString() + "; nonBlockCode();"]);
ok(blob, "Blob has been created");

View File

@ -65,7 +65,11 @@ AntiTracking.runTestInNormalAndPrivateMode(
},
async _ => {
/* import-globals-from storageAccessAPIHelpers.js */
await hasStorageAccessInitially();
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
localStorage.foo = 42;
ok(true, "LocalStorage is allowed");

View File

@ -142,7 +142,11 @@ AntiTracking.runTestInNormalAndPrivateMode(
},
async _ => {
/* import-globals-from storageAccessAPIHelpers.js */
await hasStorageAccessInitially();
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
new BroadcastChannel("hello");
ok(true, "BroadcastChanneli can be used");
@ -252,7 +256,11 @@ AntiTracking.runTestInNormalAndPrivateMode(
}
/* import-globals-from storageAccessAPIHelpers.js */
await hasStorageAccessInitially();
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
let blob = new Blob([nonBlockingCode.toString() + "; nonBlockingCode();"]);
ok(blob, "Blob has been created");

View File

@ -65,7 +65,11 @@ AntiTracking.runTest(
},
async _ => {
/* import-globals-from storageAccessAPIHelpers.js */
await hasStorageAccessInitially();
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
await navigator.serviceWorker
.register("empty.js")

View File

@ -88,7 +88,11 @@ AntiTracking.runTestInNormalAndPrivateMode(
},
async _ => {
/* import-globals-from storageAccessAPIHelpers.js */
await hasStorageAccessInitially();
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
sessionStorage.foo = 42;
ok(true, "SessionStorage is always allowed");

View File

@ -65,7 +65,11 @@ AntiTracking.runTestInNormalAndPrivateMode(
},
async _ => {
/* import-globals-from storageAccessAPIHelpers.js */
await hasStorageAccessInitially();
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
new SharedWorker("a.js", "foo");
ok(true, "SharedWorker is allowed");

View File

@ -1,183 +0,0 @@
// This test ensures HasStorageAccess API returns the right value under different
// scenarios.
/* import-globals-from antitracking_head.js */
var settings = [
// 3rd-party no-tracker
{
name: "Test whether 3rd-party non-tracker frame has storage access",
topPage: TEST_TOP_PAGE,
thirdPartyPage: TEST_4TH_PARTY_PAGE,
},
// 3rd-party no-tracker with permission
{
name:
"Test whether 3rd-party non-tracker frame has storage access when storage permission is granted before",
topPage: TEST_TOP_PAGE,
thirdPartyPage: TEST_4TH_PARTY_PAGE,
setup: () => {
let type = "3rdPartyStorage^http://not-tracking.example.com";
let permission = Services.perms.ALLOW_ACTION;
let expireType = Services.perms.EXPIRE_SESSION;
PermissionTestUtils.add(TEST_DOMAIN, type, permission, expireType, 0);
registerCleanupFunction(_ => {
Services.perms.removeAll();
});
},
},
// 3rd-party tracker
{
name: "Test whether 3rd-party tracker frame has storage access",
topPage: TEST_TOP_PAGE,
thirdPartyPage: TEST_3RD_PARTY_PAGE,
},
// 3rd-party tracker with permission
{
name:
"Test whether 3rd-party tracker frame has storage access when storage access permission is granted before",
topPage: TEST_TOP_PAGE,
thirdPartyPage: TEST_3RD_PARTY_PAGE,
setup: () => {
let type = "3rdPartyStorage^https://tracking.example.org";
let permission = Services.perms.ALLOW_ACTION;
let expireType = Services.perms.EXPIRE_SESSION;
PermissionTestUtils.add(TEST_DOMAIN, type, permission, expireType, 0);
registerCleanupFunction(_ => {
Services.perms.removeAll();
});
},
},
// same-site 3rd-party tracker
{
name: "Test whether same-site 3rd-party tracker frame has storage access",
topPage: TEST_TOP_PAGE,
thirdPartyPage: TEST_ANOTHER_3RD_PARTY_PAGE,
},
// same-origin 3rd-party tracker
{
name: "Test whether same-origin 3rd-party tracker frame has storage access",
topPage: TEST_ANOTHER_3RD_PARTY_DOMAIN + TEST_PATH + "page.html",
thirdPartyPage: TEST_ANOTHER_3RD_PARTY_PAGE,
},
];
var testCases = [
{
behavior: BEHAVIOR_ACCEPT, // 0
hasStorageAccess: [
true /* 3rd-party non-tracker */,
true /* 3rd-party non-tracker with permission */,
true /* 3rd-party tracker */,
true /* 3rd-party tracker with permission */,
true /* same-site tracker */,
true /* same-origin tracker */,
],
},
{
behavior: BEHAVIOR_REJECT_FOREIGN, // 1
hasStorageAccess: [
false /* 3rd-party non-tracker */,
true /* 3rd-party non-tracker with permission */,
false /* 3rd-party tracker */,
true /* 3rd-party tracker with permission */,
true /* same-site tracker */,
true /* same-origin tracker */,
],
},
{
behavior: BEHAVIOR_REJECT, // 2
hasStorageAccess: [
false /* 3rd-party non-tracker */,
false /* 3rd-party non-tracker with permission */,
false /* 3rd-party tracker */,
false /* 3rd-party tracker with permission */,
false /* same-site tracker */,
true /* same-origin tracker */,
],
},
{
behavior: BEHAVIOR_LIMIT_FOREIGN, // 3
hasStorageAccess: [
false /* 3rd-party non-tracker */,
false /* 3rd-party non-tracker with permission */,
false /* 3rd-party tracker */,
false /* 3rd-party tracker with permission */,
true /* same-site tracker */,
true /* same-origin tracker */,
],
},
{
behavior: BEHAVIOR_REJECT_TRACKER, // 4
hasStorageAccess: [
true /* 3rd-party non-tracker */,
true /* 3rd-party non-tracker with permission */,
false /* 3rd-party tracker */,
true /* 3rd-party tracker with permission */,
true /* same-site tracker */,
true /* same-origin tracker */,
],
},
{
behavior: BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN, // 5
hasStorageAccess: [
false /* 3rd-party non-tracker */,
true /* 3rd-party non-tracker with permission */,
false /* 3rd-party tracker */,
true /* 3rd-party tracker with permission */,
true /* same-site tracker */,
true /* same-origin tracker */,
],
},
];
(function() {
settings.forEach(setting => {
if (setting.setup) {
add_task(async _ => {
setting.setup();
});
}
testCases.forEach(test => {
//if (test.behavior != 3) {
//return;
//}
let callback = test.hasStorageAccess[settings.indexOf(setting)]
? async _ => {
/* import-globals-from storageAccessAPIHelpers.js */
await hasStorageAccessInitially();
}
: async _ => {
/* import-globals-from storageAccessAPIHelpers.js */
await noStorageAccessInitially();
};
AntiTracking._createTask({
name: setting.name,
cookieBehavior: test.behavior,
allowList: false,
callback,
extraPrefs: null,
expectedBlockingNotifications: 0,
runInPrivateWindow: false,
iframeSandbox: null,
accessRemoval: null,
callbackAfterRemoval: null,
topPage: setting.topPage,
thirdPartyPage: setting.thirdPartyPage,
});
});
add_task(async _ => {
await new Promise(resolve => {
Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value =>
resolve()
);
});
});
});
})();

View File

@ -53,7 +53,11 @@ AntiTracking.runTestInNormalAndPrivateMode(
},
async _ => {
/* import-globals-from storageAccessAPIHelpers.js */
await hasStorageAccessInitially();
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
localStorage.foo = 42;
ok(true, "LocalStorage is allowed");

View File

@ -11,7 +11,11 @@ AntiTracking.runTest(
// non-blocking callback
async _ => {
/* import-globals-from storageAccessAPIHelpers.js */
await hasStorageAccessInitially();
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
/* import-globals-from storageAccessAPIHelpers.js */
let [threw, rejected] = await callRequestStorageAccess();
@ -36,8 +40,6 @@ AntiTracking.runTest(
// after-removal callback
async _ => {
/* import-globals-from storageAccessAPIHelpers.js */
// TODO: this is just a temporarily fixed, we should update the testcase
// in Bug 1649399
await hasStorageAccessInitially();
await noStorageAccessInitially();
}
);

View File

@ -11,7 +11,11 @@ AntiTracking.runTest(
// non-blocking callback
async _ => {
/* import-globals-from storageAccessAPIHelpers.js */
await hasStorageAccessInitially();
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
/* import-globals-from storageAccessAPIHelpers.js */
let [threw, rejected] = await callRequestStorageAccess();