From ad6bf3f0d5d4956617ea6f08c97c96490e995056 Mon Sep 17 00:00:00 2001 From: Krzysztof Modras Date: Thu, 8 Feb 2024 12:02:51 +0100 Subject: [PATCH 1/2] v8: trackerdb handles exceptions --- .../src/classes/EventHandlers.js | 51 ++++++++++--------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/extension-manifest-v2/src/classes/EventHandlers.js b/extension-manifest-v2/src/classes/EventHandlers.js index 26070a224..853d95033 100644 --- a/extension-manifest-v2/src/classes/EventHandlers.js +++ b/extension-manifest-v2/src/classes/EventHandlers.js @@ -308,7 +308,8 @@ class EventHandlers { const incognito = tabInfo.getTabInfo(tab_id, 'incognito'); const tab_host = tabInfo.getTabInfo(tab_id, 'host'); const fromRedirect = globals.REDIRECT_MAP.has(request_id); - const { block, reason } = EventHandlers._checkBlocking(app_id, cat_id, tab_id, tab_host, page_url, request_id); + // eslint-disable-next-line prefer-const + let { block, reason } = EventHandlers._checkBlocking(app_id, cat_id, tab_id, tab_host, page_url, request_id); if (!block && [BLOCK_REASON_SS_UNBLOCKED, BLOCK_REASON_GLOBAL_UNBLOCKED].indexOf(reason) > -1) { // The way to pass this flag to Common handlers eventMutable.ghosteryWhitelisted = true; @@ -328,24 +329,6 @@ class EventHandlers { }; } - // process the tracker asynchronously - // very important to block request processing as little as necessary - setTimeout(() => { - if (tabInfo.getTabInfo(tab_id, 'url') !== eventMutable.tabUrl) { - return; - } - this._processBug({ - bug_id, - app_id, - type: eventMutable.type, - url: eventMutable.url, - block: conf.enable_ad_block && block, - tab_id, - from_frame: eventMutable.parentFrameId !== -1, - request_id - }); - }, 1); - if (block && isFilterMatched && conf.show_redirect_tracking_dialogs && fromRedirect) { const url = buildRedirectC2P(globals.REDIRECT_MAP.get(request_id), app_id); setTimeout(() => { @@ -356,9 +339,10 @@ class EventHandlers { // This is here to let common/adblocker handle previously TrackerDB matched requests as // if it would do it with its own engine. + let adblockerOnBeforeRequest; if (conf.enable_ad_block && block && isFilterMatched) { // let the Tracker Db do the blocking according to ghostery-common/adblocker logic - const onBeforeRequest = common.modules.adblocker.background.adblocker.onBeforeRequest.bind({ + adblockerOnBeforeRequest = common.modules.adblocker.background.adblocker.onBeforeRequest.bind({ shouldProcessRequest(context, _response) { // Ignore background requests if (context.isBackgroundRequest()) { @@ -382,18 +366,37 @@ class EventHandlers { manager: { engine: { ...bugDb.engine, - match() { - return { match: true, redirect: shoudlRedirect }; + match(request) { + block = !this.exceptions.match(request); + return { match: block, redirect: shoudlRedirect && block }; }, } } }), stats: common.modules.adblocker.background.adblocker.stats, }); + } - if (!onBeforeRequest(eventMutable, response)) { - return {}; + // process the tracker asynchronously + // very important to block request processing as little as necessary + setTimeout(() => { + if (tabInfo.getTabInfo(tab_id, 'url') !== eventMutable.tabUrl) { + return; } + this._processBug({ + bug_id, + app_id, + type: eventMutable.type, + url: eventMutable.url, + block: conf.enable_ad_block && block, + tab_id, + from_frame: eventMutable.parentFrameId !== -1, + request_id + }); + }, 1); + + if (adblockerOnBeforeRequest && !adblockerOnBeforeRequest(eventMutable, response)) { + return {}; } return { cancel: false }; From b5b0c72536c371ff02155a88a339464aec49d513 Mon Sep 17 00:00:00 2001 From: Krzysztof Modras Date: Thu, 8 Feb 2024 13:41:42 +0100 Subject: [PATCH 2/2] Checking against ad-blocking exception list (not trackerdb) --- extension-manifest-v2/src/classes/EventHandlers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension-manifest-v2/src/classes/EventHandlers.js b/extension-manifest-v2/src/classes/EventHandlers.js index 853d95033..f7c78a581 100644 --- a/extension-manifest-v2/src/classes/EventHandlers.js +++ b/extension-manifest-v2/src/classes/EventHandlers.js @@ -367,7 +367,7 @@ class EventHandlers { engine: { ...bugDb.engine, match(request) { - block = !this.exceptions.match(request); + block = !common.modules.adblocker.background.adblocker.manager.engine.exceptions.match(request); return { match: block, redirect: shoudlRedirect && block }; }, }