Bug 1771024 - Cleaning per principal when sanitizer is run on startup. r=pbz

Differential Revision: https://phabricator.services.mozilla.com/D147622
This commit is contained in:
Hannah Peuckmann 2022-06-01 07:54:54 +00:00
Родитель 5d7edc0d2e
Коммит 3a8bae7549
2 изменённых файлов: 78 добавлений и 3 удалений

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

@ -120,3 +120,73 @@ add_task(async function sanitizeNoExceptionsInTimeRange() {
"We should not have cookies for " + originDENY
);
});
add_task(async function sanitizeWithExceptionsOnStartup() {
info(
"Test that cookies that are marked as allowed from the user do not get \
cleared when cleaning on startup is done, for example after a crash"
);
await SpecialPowers.pushPrefEnv({
set: [
["browser.sanitizer.loglevel", "All"],
["privacy.sanitize.sanitizeOnShutdown", true],
],
});
// Clean up before start
await new Promise(resolve => {
Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, resolve);
});
let originALLOW = "https://mozilla.org";
PermissionTestUtils.add(
originALLOW,
"cookie",
Ci.nsICookiePermission.ACCESS_ALLOW
);
let originDENY = "https://example123.com";
PermissionTestUtils.add(
originDENY,
"cookie",
Ci.nsICookiePermission.ACCESS_DENY
);
SiteDataTestUtils.addToCookies({ origin: originALLOW });
ok(
SiteDataTestUtils.hasCookies(originALLOW),
"We have cookies for " + originALLOW
);
SiteDataTestUtils.addToCookies({ origin: originDENY });
ok(
SiteDataTestUtils.hasCookies(originDENY),
"We have cookies for " + originDENY
);
let pendingSanitizations = [
{
id: "shutdown",
itemsToClear: ["cookies"],
options: {},
},
];
Services.prefs.setBoolPref(Sanitizer.PREF_SANITIZE_ON_SHUTDOWN, true);
Services.prefs.setStringPref(
Sanitizer.PREF_PENDING_SANITIZATIONS,
JSON.stringify(pendingSanitizations)
);
await Sanitizer.onStartup();
ok(
SiteDataTestUtils.hasCookies(originALLOW),
"We should have cookies for " + originALLOW
);
ok(
!SiteDataTestUtils.hasCookies(originDENY),
"We should not have cookies for " + originDENY
);
});

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

@ -164,7 +164,7 @@ var Sanitizer = {
// will be updated during sanitization and reported with the crash in case of
// a shutdown timeout.
// We use the `options` argument to pass the `progress` object to sanitize().
let progress = { isShutdown: true };
let progress = { isShutdown: true, clearHonoringExceptions: true };
shutdownClient.addBlocker(
"sanitize.js: Sanitize on shutdown",
() => sanitizeOnShutdown(progress),
@ -189,6 +189,8 @@ var Sanitizer = {
// before completing them.
for (let { itemsToClear, options } of pendingSanitizations) {
try {
// We need to set this flag to watch out for the users exceptions like we do on shutdown
options.progress = { clearHonoringExceptions: true };
await this.sanitize(itemsToClear, options);
} catch (ex) {
Cu.reportError(
@ -346,7 +348,10 @@ var Sanitizer = {
// This method is meant to be used by tests.
async runSanitizeOnShutdown() {
return sanitizeOnShutdown({ isShutdown: true });
return sanitizeOnShutdown({
isShutdown: true,
clearHonoringExceptions: true,
});
},
// When making any changes to the sanitize implementations here,
@ -746,7 +751,7 @@ async function sanitizeInternal(items, aItemsToClear, progress, options = {}) {
};
// When clearing on shutdown we clear by principal for certain cleaning categories, to consider the users exceptions
if (progress.isShutdown) {
if (progress.clearHonoringExceptions) {
let principalsCollector = new PrincipalsCollector();
let principals = await principalsCollector.getAllPrincipals(progress);
options.principalsForShutdownClearing = principals;