Index: lib/csp.js |
=================================================================== |
--- a/lib/csp.js |
+++ b/lib/csp.js |
@@ -15,17 +15,18 @@ |
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
*/ |
"use strict"; |
const {defaultMatcher} = require("../adblockpluscore/lib/matcher"); |
const {RegExpFilter, WhitelistFilter} = |
require("../adblockpluscore/lib/filterClasses"); |
-const {extractHostFromFrame, isThirdParty} = require("./url"); |
+const {isThirdParty} = require("../adblockpluscore/lib/domain"); |
+const {extractHostFromFrame} = require("./url"); |
const {checkWhitelisted} = require("./whitelisting"); |
const {filterNotifier} = require("filterNotifier"); |
const {logRequest} = require("./hitLogger"); |
const {typeMap} = RegExpFilter; |
browser.webRequest.onHeadersReceived.addListener(details => |
{ |
@@ -53,28 +54,41 @@ |
if (specificOnly && !(cspMatch instanceof WhitelistFilter)) |
{ |
cspMatch = defaultMatcher.matchesAny(details.url, typeMap.CSP, hostname, |
thirdParty, null, specificOnly); |
if (!cspMatch) |
return; |
} |
- logRequest([details.tabId], { |
- url: details.url, type: "CSP", docDomain: hostname, |
- thirdParty, specificOnly |
- }, cspMatch); |
- filterNotifier.emit("filter.hitCount", cspMatch, 0, 0, [details.tabId]); |
+ if (cspMatch instanceof WhitelistFilter) |
+ { |
+ logRequest([details.tabId], { |
+ url: details.url, type: "CSP", docDomain: hostname, |
+ thirdParty, specificOnly |
+ }, cspMatch); |
+ filterNotifier.emit("filter.hitCount", cspMatch, 0, 0, [details.tabId]); |
+ return; |
+ } |
- if (cspMatch instanceof WhitelistFilter) |
- return; |
+ let {blocking} = defaultMatcher.search(details.url, typeMap.CSP, hostname, |
+ thirdParty, null, specificOnly, |
+ "blocking"); |
+ for (cspMatch of blocking) |
+ { |
+ logRequest([details.tabId], { |
+ url: details.url, type: "CSP", docDomain: hostname, |
+ thirdParty, specificOnly |
+ }, cspMatch); |
+ filterNotifier.emit("filter.hitCount", cspMatch, 0, 0, [details.tabId]); |
- details.responseHeaders.push({ |
- name: "Content-Security-Policy", |
- value: cspMatch.csp |
- }); |
+ details.responseHeaders.push({ |
+ name: "Content-Security-Policy", |
+ value: cspMatch.csp |
+ }); |
+ } |
return {responseHeaders: details.responseHeaders}; |
} |
}, { |
urls: ["http://*/*", "https://*/*"], |
types: ["main_frame", "sub_frame"] |
}, ["blocking", "responseHeaders"]); |