Bug 1577298 - Do not stop at the current document when computing the top-level principal for storage partitioning; r=baku

Differential Revision: https://phabricator.services.mozilla.com/D47339

--HG--
rename : toolkit/components/antitracking/test/browser/browser_subResources.js => toolkit/components/antitracking/test/browser/browser_subResourcesPartitioned.js
extra : moz-landing-system : lando
This commit is contained in:
Ehsan Akhgari 2019-09-27 14:05:13 +00:00
Родитель cbc414a27d
Коммит 7ddd78221e
17 изменённых файлов: 328 добавлений и 10 удалений

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

@ -65,15 +65,17 @@ void OriginAttributes::SetFirstPartyDomain(const bool aIsTopLevelDocument,
// Saving isInsufficientDomainLevels before rv is overwritten.
bool isInsufficientDomainLevels = (rv == NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS);
nsAutoCString scheme;
if (aURI) {
rv = aURI->GetScheme(scheme);
NS_ENSURE_SUCCESS_VOID(rv);
if (scheme.EqualsLiteral("about")) {
mFirstPartyDomain.AssignLiteral(ABOUT_URI_FIRST_PARTY_DOMAIN);
return;
}
}
nsCOMPtr<nsIPrincipal> blobPrincipal;
if (dom::BlobURLProtocolHandler::GetBlobURLPrincipal(
if (aURI && dom::BlobURLProtocolHandler::GetBlobURLPrincipal(
aURI, getter_AddRefs(blobPrincipal))) {
MOZ_ASSERT(blobPrincipal);
mFirstPartyDomain = blobPrincipal->OriginAttributesRef().mFirstPartyDomain;

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

@ -271,6 +271,15 @@ nsScriptSecurityManager::GetChannelResultPrincipals(
return rv;
}
if (!(*aPrincipal)->GetIsContentPrincipal()) {
// If for some reason we don't have a content principal here, just reuse our
// principal for the storage principal too, since attempting to create a
// storage principal would fail anyway.
nsCOMPtr<nsIPrincipal> copy = *aPrincipal;
copy.forget(aStoragePrincipal);
return NS_OK;
}
return StoragePrincipalHelper::Create(aChannel, *aPrincipal,
aStoragePrincipal);
}

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

@ -46,6 +46,7 @@
# include "mozilla/dom/WindowOrientationObserver.h"
#endif
#include "nsDOMOfflineResourceList.h"
#include "nsICookieService.h"
#include "nsError.h"
#include "nsISizeOfEventTarget.h"
#include "nsDOMJSUtils.h"
@ -5605,7 +5606,10 @@ nsIPrincipal* nsGlobalWindowInner::GetTopLevelPrincipal() {
return nullptr;
}
if (topLevelOuterWindow == outerWindow) {
bool stopAtOurLevel = mDoc && mDoc->CookieSettings()->GetCookieBehavior() ==
nsICookieService::BEHAVIOR_REJECT_TRACKER;
if (stopAtOurLevel && topLevelOuterWindow == outerWindow) {
return nullptr;
}

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

@ -8,6 +8,8 @@
"use strict";
var gFeatures = undefined;
var gTestTrackersCleanedUp = false;
var gTestTrackersCleanupRegistered = false;
/**
* Force garbage collection.
@ -372,6 +374,16 @@ this.AntiTracking = {
}
await UrlClassifierTestUtils.addTestTrackers();
if (!gTestTrackersCleanupRegistered) {
registerCleanupFunction(_ => {
if (gTestTrackersCleanedUp) {
return;
}
UrlClassifierTestUtils.cleanupTestTrackers();
gTestTrackersCleanedUp = true;
});
gTestTrackersCleanupRegistered = true;
}
},
_createTask(options) {

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

@ -88,6 +88,9 @@ skip-if = fission
[browser_subResources.js]
skip-if = fission || serviceworker_e10s
support-files = subResources.sjs
[browser_subResourcesPartitioned.js]
skip-if = fission || serviceworker_e10s
support-files = subResources.sjs
[browser_script.js]
skip-if = fission
support-files = tracker.js

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

@ -117,6 +117,8 @@ add_task(async function() {
info("Removing the tab");
BrowserTestUtils.removeTab(tab);
UrlClassifierTestUtils.cleanupTestTrackers();
});
add_task(async function() {

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

@ -167,6 +167,8 @@ add_task(async function testBlockedLocalStorageEventPropagation() {
info("Removing the tab");
BrowserTestUtils.removeTab(tab);
UrlClassifierTestUtils.cleanupTestTrackers();
info("Cleaning up.");
await new Promise(resolve => {
Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value =>

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

@ -191,6 +191,8 @@ add_task(async function() {
info("Removing the tab");
BrowserTestUtils.removeTab(tab);
UrlClassifierTestUtils.cleanupTestTrackers();
});
add_task(async function() {

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

@ -176,6 +176,8 @@ function runAllTests(withStoragePrincipalEnabled, prefValue) {
BrowserTestUtils.removeTab(trackerTab);
BrowserTestUtils.removeTab(normalTab);
UrlClassifierTestUtils.cleanupTestTrackers();
});
// Two ePartitionOrDeny iframes in the same tab in the same origin don't see
@ -296,6 +298,8 @@ function runAllTests(withStoragePrincipalEnabled, prefValue) {
);
BrowserTestUtils.removeTab(normalTab);
UrlClassifierTestUtils.cleanupTestTrackers();
});
// Same as the previous test but with a cookie behavior of BEHAVIOR_ACCEPT
@ -404,6 +408,8 @@ function runAllTests(withStoragePrincipalEnabled, prefValue) {
);
BrowserTestUtils.removeTab(normalTab);
UrlClassifierTestUtils.cleanupTestTrackers();
});
// An ePartitionOrDeny iframe navigated between two distinct pages on the same
@ -498,6 +504,8 @@ function runAllTests(withStoragePrincipalEnabled, prefValue) {
);
BrowserTestUtils.removeTab(normalTab);
UrlClassifierTestUtils.cleanupTestTrackers();
});
// Like the previous test, but accepting trackers
@ -586,6 +594,8 @@ function runAllTests(withStoragePrincipalEnabled, prefValue) {
);
BrowserTestUtils.removeTab(normalTab);
UrlClassifierTestUtils.cleanupTestTrackers();
});
// An ePartitionOrDeny iframe on the same origin that is navigated to itself
@ -681,6 +691,8 @@ function runAllTests(withStoragePrincipalEnabled, prefValue) {
);
BrowserTestUtils.removeTab(normalTab);
UrlClassifierTestUtils.cleanupTestTrackers();
});
// Like the previous test, but accepting trackers
@ -769,6 +781,8 @@ function runAllTests(withStoragePrincipalEnabled, prefValue) {
);
BrowserTestUtils.removeTab(normalTab);
UrlClassifierTestUtils.cleanupTestTrackers();
});
// Cleanup data.

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

@ -410,8 +410,6 @@ add_task(async function() {
],
});
await UrlClassifierTestUtils.addTestTrackers();
// no-referrer-when-downgrade
await SpecialPowers.pushPrefEnv({
set: [["network.http.referer.defaultPolicy.trackers", 3]],
@ -523,7 +521,11 @@ add_task(async function() {
});
add_task(async function() {
await UrlClassifierTestUtils.addTestTrackers();
await executeTests();
UrlClassifierTestUtils.cleanupTestTrackers();
});
add_task(async function() {

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

@ -204,6 +204,8 @@ add_task(async function() {
info("Removing the tab");
BrowserTestUtils.removeTab(tab);
UrlClassifierTestUtils.cleanupTestTrackers();
});
add_task(async function() {

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

@ -71,6 +71,8 @@ function runTest(obj) {
);
BrowserTestUtils.removeTab(tab);
UrlClassifierTestUtils.cleanupTestTrackers();
});
}

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

@ -310,6 +310,8 @@ add_task(async function testUserInteractionHeuristic() {
info("Removing the tab");
BrowserTestUtils.removeTab(tab);
UrlClassifierTestUtils.cleanupTestTrackers();
});
add_task(async function() {

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

@ -253,6 +253,8 @@ add_task(async function() {
info("Removing the tab");
BrowserTestUtils.removeTab(tab);
UrlClassifierTestUtils.cleanupTestTrackers();
});
add_task(async function() {

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

@ -0,0 +1,254 @@
async function runTests(topPage) {
info("Creating a new tab");
let tab = BrowserTestUtils.addTab(gBrowser, topPage);
gBrowser.selectedTab = tab;
let browser = gBrowser.getBrowserForTab(tab);
await BrowserTestUtils.browserLoaded(browser);
info("Loading scripts and images");
await ContentTask.spawn(browser, null, async function() {
// Let's load the script twice here.
{
let src = content.document.createElement("script");
let p = new content.Promise(resolve => {
src.onload = resolve;
});
content.document.body.appendChild(src);
src.src =
"https://example.org/browser/toolkit/components/antitracking/test/browser/subResources.sjs?what=script";
await p;
}
{
let src = content.document.createElement("script");
let p = new content.Promise(resolve => {
src.onload = resolve;
});
content.document.body.appendChild(src);
src.src =
"https://example.org/browser/toolkit/components/antitracking/test/browser/subResources.sjs?what=script";
await p;
}
// Let's load an image twice here.
{
let img = content.document.createElement("img");
let p = new content.Promise(resolve => {
img.onload = resolve;
});
content.document.body.appendChild(img);
img.src =
"https://example.org/browser/toolkit/components/antitracking/test/browser/subResources.sjs?what=image";
await p;
}
{
let img = content.document.createElement("img");
let p = new content.Promise(resolve => {
img.onload = resolve;
});
content.document.body.appendChild(img);
img.src =
"https://example.org/browser/toolkit/components/antitracking/test/browser/subResources.sjs?what=image";
await p;
}
});
await fetch(
"https://example.org/browser/toolkit/components/antitracking/test/browser/subResources.sjs?result&what=image"
)
.then(r => r.text())
.then(text => {
is(text, 1, "One cookie received for images.");
});
await fetch(
"https://example.org/browser/toolkit/components/antitracking/test/browser/subResources.sjs?result&what=script"
)
.then(r => r.text())
.then(text => {
is(text, 1, "One cookie received received for scripts.");
});
info("Creating a 3rd party content");
await ContentTask.spawn(
browser,
{
page: TEST_3RD_PARTY_PAGE_WO,
blockingCallback: (async _ => {}).toString(),
nonBlockingCallback: (async _ => {}).toString(),
},
async function(obj) {
await new content.Promise(resolve => {
let ifr = content.document.createElement("iframe");
ifr.onload = function() {
info("Sending code to the 3rd party content");
ifr.contentWindow.postMessage(obj, "*");
};
content.addEventListener("message", function msg(event) {
if (event.data.type == "finish") {
content.removeEventListener("message", msg);
resolve();
return;
}
if (event.data.type == "ok") {
ok(event.data.what, event.data.msg);
return;
}
if (event.data.type == "info") {
info(event.data.msg);
return;
}
ok(false, "Unknown message");
});
content.document.body.appendChild(ifr);
ifr.src = obj.page;
});
}
);
info("Loading scripts and images again");
await ContentTask.spawn(browser, null, async function() {
// Let's load the script twice here.
{
let src = content.document.createElement("script");
let p = new content.Promise(resolve => {
src.onload = resolve;
});
content.document.body.appendChild(src);
src.src =
"https://example.com/browser/toolkit/components/antitracking/test/browser/subResources.sjs?what=script";
await p;
}
{
let src = content.document.createElement("script");
let p = new content.Promise(resolve => {
src.onload = resolve;
});
content.document.body.appendChild(src);
src.src =
"https://example.com/browser/toolkit/components/antitracking/test/browser/subResources.sjs?what=script";
await p;
}
// Let's load an image twice here.
{
let img = content.document.createElement("img");
let p = new content.Promise(resolve => {
img.onload = resolve;
});
content.document.body.appendChild(img);
img.src =
"https://example.com/browser/toolkit/components/antitracking/test/browser/subResources.sjs?what=image";
await p;
}
{
let img = content.document.createElement("img");
let p = new content.Promise(resolve => {
img.onload = resolve;
});
content.document.body.appendChild(img);
img.src =
"https://example.com/browser/toolkit/components/antitracking/test/browser/subResources.sjs?what=image";
await p;
}
});
await fetch(
"https://example.com/browser/toolkit/components/antitracking/test/browser/subResources.sjs?result&what=image"
)
.then(r => r.text())
.then(text => {
is(text, 1, "One cookie received for images.");
});
await fetch(
"https://example.com/browser/toolkit/components/antitracking/test/browser/subResources.sjs?result&what=script"
)
.then(r => r.text())
.then(text => {
is(text, 1, "One cookie received received for scripts.");
});
let expectTrackerBlocked = (item, blocked) => {
is(
item[0],
Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER,
"Correct blocking type reported"
);
is(item[1], blocked, "Correct blocking status reported");
ok(item[2] >= 1, "Correct repeat count reported");
};
let expectCookiesLoaded = item => {
is(
item[0],
Ci.nsIWebProgressListener.STATE_COOKIES_LOADED,
"Correct blocking type reported"
);
is(item[1], true, "Correct blocking status reported");
ok(item[2] >= 1, "Correct repeat count reported");
};
let log = JSON.parse(await browser.getContentBlockingLog());
for (let trackerOrigin in log) {
let originLog = log[trackerOrigin];
info(trackerOrigin);
switch (trackerOrigin) {
case "https://example.org":
case "https://example.com":
is(
originLog.length,
1,
"We should have 1 entries in the compressed log"
);
expectCookiesLoaded(originLog[0]);
break;
case "https://tracking.example.org":
is(
originLog.length,
1,
"We should have 1 entries in the compressed log"
);
expectTrackerBlocked(originLog[0], false);
break;
}
}
info("Removing the tab");
BrowserTestUtils.removeTab(tab);
}
add_task(async function() {
info("Starting subResources test");
await SpecialPowers.flushPrefEnv();
await SpecialPowers.pushPrefEnv({
set: [
[
"network.cookie.cookieBehavior",
Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN,
],
["privacy.trackingprotection.enabled", false],
["privacy.trackingprotection.pbmode.enabled", false],
["privacy.trackingprotection.annotate_channels", true],
],
});
for (let page of [TEST_TOP_PAGE, TEST_TOP_PAGE_2, TEST_TOP_PAGE_3]) {
await runTests(page);
}
});
add_task(async function() {
info("Cleaning up.");
await new Promise(resolve => {
Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value =>
resolve()
);
});
});

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

@ -106,6 +106,8 @@ add_task(async function() {
info("Removing the tab");
BrowserTestUtils.removeTab(tab);
UrlClassifierTestUtils.cleanupTestTrackers();
});
add_task(async function() {

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

@ -69,6 +69,8 @@ add_task(async function() {
info("Removing the tab");
BrowserTestUtils.removeTab(tab);
UrlClassifierTestUtils.cleanupTestTrackers();
});
add_task(async function() {