[TabGuard] Keep track of anonymized requests.

This commit is contained in:
hackademix 2023-06-09 15:09:17 +02:00
parent 3cf268e9df
commit 728f9ee9c0
No known key found for this signature in database
GPG Key ID: 231A83AFDA9C2434
2 changed files with 15 additions and 6 deletions

View File

@ -589,7 +589,7 @@ var RequestGuard = (() => {
if (pending && pending.redirected && pending.redirected.url === request.url) {
return lanRes; // don't go on stripping cookies if we're in a redirection loop
}
let chainNext = r => r === ABORT ? r : TabGuard.check(request);
let chainNext = r => r === ABORT ? r : TabGuard.onSend(request);
return lanRes instanceof Promise ? lanRes.then(chainNext) : chainNext(lanRes);
},
@ -688,7 +688,7 @@ var RequestGuard = (() => {
let {requestId, url, tabId, frameId, type} = request;
if (type === "main_frame") {
TabStatus.initTab(tabId);
TabGuard.postCheck(request);
TabGuard.onCleanup(request);
}
let scriptBlocked = request.responseHeaders.some(
h => csp.isMine(h) && csp.blocks(h.value, "script")
@ -721,11 +721,11 @@ var RequestGuard = (() => {
}
}
}
TabGuard.postCheck(request);
TabGuard.onCleanup(request);
},
onErrorOccurred(request) {
pendingRequests.delete(request.requestId);
TabGuard.postCheck(request);
TabGuard.onCleanup(request);
}
};
function fakeRequestFromCSP(report, request) {

View File

@ -27,6 +27,8 @@ var TabGuard = (() => {
anonymizedTabs.delete(tab.id);
});
const anonymizedRequests = new Set();
let allowedGroups, filteredGroups;
let forget = () => {
allowedGroups = {};
@ -53,10 +55,12 @@ var TabGuard = (() => {
return {
forget,
check(request) {
onSend(request) {
const mode = ns.sync.TabGuardMode;
if (mode === "off" || !request.incognito && mode!== "global") return;
anonymizedRequests.delete(request.id);
const {tabId, type, url, originUrl} = request;
if (tabId < 0) return; // no tab, no party
@ -160,6 +164,7 @@ var TabGuard = (() => {
requestHeaders = requestHeaders.filter(h => !AUTH_HEADERS_RX.test(h.name));
debug("[TabGuard] Removing auth headers from %o (%o)", request, requestHeaders);
anonymizedTabs.set(tabId, {tabDomain, otherDomains: [...otherDomains]});
anonymizedRequests.add(request.id);
return {requestHeaders};
};
@ -195,12 +200,16 @@ var TabGuard = (() => {
return mustFilter ? filterAuth() : null;
})();
},
postCheck(request) {
onCleanup(request) {
let {requestId, tabId} = request;
if (scheduledCuts.has(requestId)) {
scheduledCuts.delete(requestId);
TabTies.cut(tabId);
}
anonymizedRequests.delete(request.id);
},
isAnonymizedRequest(requestId) {
return anonymizedRequests.has(requestId);
},
isAnonymizedTab(tabId) {
return anonymizedTabs.has(tabId);