[TabGuard] Load with credentials when reloading from NoScript's UI.

This commit is contained in:
hackademix 2023-06-15 00:33:15 +02:00
parent de872964e9
commit 1d330739ec
No known key found for this signature in database
GPG Key ID: 231A83AFDA9C2434
3 changed files with 33 additions and 8 deletions

View File

@ -36,6 +36,18 @@ var TabGuard = (() => {
};
forget();
function mergeGroups(groups, {tabDomain, otherDomains} /* anonymizedTabInfo */) {
if (!(tabDomain in groups)) groups[tabDomain] = new Set();
let currentGroup = groups[tabDomain];
for (let d of otherDomains) {
if (!(d in groups)) groups[d] = new Set();
// add this domain to the allow/block group of the other tied ones...
groups[d].add(tabDomain);
// ... and vice-versa
currentGroup.add(d);
}
}
const AUTH_HEADERS_RX = /^(?:authorization|cookie)/i;
function getDomain(u) {
@ -193,10 +205,9 @@ var TabGuard = (() => {
if (ret.button !== 0) {
return {cancel: true};
}
let list = ret.option === 0 ? filteredGroups : allowedGroups;
otherDomains.add(tabDomain);
for (let d of otherDomains) list[d] = otherDomains;
return list === filteredGroups ? filterAuth() : null;
const groups = ret.option === 0 ? filteredGroups : allowedGroups;
mergeGroups(groups, {tabDomain, otherDomains});
return groups === filteredGroups ? filterAuth() : null;
})();
}
}
@ -237,9 +248,14 @@ var TabGuard = (() => {
// return a deep copy
return JSON.parse(JSON.stringify(anonymizedTabs.get(tabId)));
},
reloadNormally(tabId) {
async reloadNormally(tabId) {
TabTies.cut(tabId);
browser.tabs.reload(tabId);
await browser.tabs.reload(tabId);
},
allow(tabId) {
if (!TabGuard.isAnonymizedTab(tabId)) return;
const info = this.getAnonymizedTabInfo(tabId);
mergeGroups(allowedGroups, info);
}
}
})();

View File

@ -165,6 +165,7 @@
let policy = ns.policy.dry(true);
let seen = tabId !== -1 ? await ns.collectSeen(tabId) : null;
let xssUserChoices = await XSS.getUserChoices();
let anonymyzedTabInfo =
await Messages.send("settings", {
policy,
seen,
@ -174,6 +175,7 @@
unrestrictedTab: ns.unrestrictedTabs.has(tabId),
tabId,
xssBlockedInTab: XSS.getBlockedInTab(tabId),
anonymyzedTabInfo: TabGuard.isAnonymizedTab(tabId) && TabGuard.getAnonymizedTabInfo(tabId),
});
},
@ -236,6 +238,13 @@
matchAboutBlank: true,
allFrames: true,
});
},
async reloadWithCredentials({tabId, remember}) {
if (remember) {
TabGuard.allow(tabId);
}
await TabGuard.reloadNormally(tabId);
}
};

View File

@ -389,9 +389,9 @@ addEventListener("unload", e => {
window.scrollTo(0, 0);
}
function reload() {
async function reload() {
if (sitesUI) sitesUI.clear();
browser.tabs.reload(tabId);
await Messages.send("reloadWithCredentials", {tabId});
pendingReload(false);
}