| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 "use strict"; | 18 "use strict"; |
| 19 | 19 |
| 20 const {defaultMatcher} = require("matcher"); | 20 const {defaultMatcher} = require("matcher"); |
| 21 const {BlockingFilter, | 21 const {RegExpFilter, WhitelistFilter} = require("filterClasses"); |
| 22 RegExpFilter, | 22 const {extractHostFromFrame, getDecodedHostname, |
| 23 WhitelistFilter} = require("filterClasses"); | 23 isThirdParty, stringifyURL} = require("url"); |
| 24 const {getDecodedHostname, stringifyURL} = require("url"); | |
| 25 const {checkWhitelisted} = require("whitelisting"); | 24 const {checkWhitelisted} = require("whitelisting"); |
| 26 const {FilterNotifier} = require("filterNotifier"); | 25 const {FilterNotifier} = require("filterNotifier"); |
| 27 const devtools = require("devtools"); | 26 const devtools = require("devtools"); |
| 28 | 27 |
| 29 const {typeMap} = RegExpFilter; | 28 const {typeMap} = RegExpFilter; |
| 30 | 29 |
| 31 browser.webRequest.onHeadersReceived.addListener(details => | 30 browser.webRequest.onHeadersReceived.addListener(details => |
| 32 { | 31 { |
| 33 let url = new URL(details.url); | 32 let url = new URL(details.url); |
| 34 let hostname = getDecodedHostname(url); | 33 let urlString = stringifyURL(url); |
| 35 let cspMatch = defaultMatcher.matchesAny(details.url, typeMap.CSP, hostname, | 34 let parentFrame = ext.getFrame(details.tabId, details.parentFrameId); |
|
Sebastian Noack
2018/03/13 22:28:30
It seems, we use stringifyURL(new URL(...)) everyw
kzar
2018/03/14 10:46:43
Done.
Sebastian Noack
2018/03/14 15:57:27
ESLint doesn't catch it because it considers the s
kzar
2018/03/14 17:16:07
OK
| |
| 36 false, null, false); | 35 let hostname = extractHostFromFrame(parentFrame) || getDecodedHostname(url); |
| 36 let thirdParty = isThirdParty(url, hostname); | |
| 37 | |
| 38 let cspMatch = defaultMatcher.matchesAny(urlString, typeMap.CSP, hostname, | |
| 39 thirdParty, null, false); | |
| 37 if (cspMatch) | 40 if (cspMatch) |
| 38 { | 41 { |
| 39 let page = new ext.Page({id: details.tabId, url: details.url}); | 42 let page = new ext.Page({id: details.tabId, url: details.url}); |
| 40 let frame = ext.getFrame(details.tabId, details.frameId); | 43 let frame = ext.getFrame(details.tabId, details.frameId); |
| 41 if (checkWhitelisted(page, frame, typeMap.DOCUMENT | typeMap.CSP)) | 44 |
|
Sebastian Noack
2018/03/13 22:28:30
Are filters like @@||example.com$csp even supposed
kzar
2018/03/14 10:46:43
Yea, the devtools interface adds a filter like tha
Sebastian Noack
2018/03/14 15:57:27
This should work regardless of checking for CSP, h
kzar
2018/03/14 17:16:07
I think we need to check for CSP here as well sinc
Sebastian Noack
2018/03/14 20:19:42
I don't understand how this is related. Let's say
kzar
2018/03/15 13:10:13
Sebastian Noack wrote:
Sebastian Noack
2018/03/15 17:14:24
Good point, as far as Acceptable Ads is concerned,
kzar
2018/03/15 18:18:43
OK, I've sent him a message.
kzar
2018/03/16 12:54:59
He voted for non-recursively.
Sebastian Noack
2018/03/16 23:52:38
This behavior seems expected/correct to me.
$cs
kzar
2018/03/19 14:41:30
Thanks for the explanation, Done.
| |
| 45 if (checkWhitelisted(page, frame)) | |
| 42 return; | 46 return; |
| 43 | 47 |
| 44 // To avoid an extra matchesAny for the common case we assumed no | 48 // To avoid an extra matchesAny for the common case we assumed no |
| 45 // $genericblock filters applied when searching for a matching $csp filter. | 49 // $genericblock filters applied when searching for a matching $csp filter. |
| 46 // We must now pay the price by first checking for a $genericblock filter | 50 // We must now pay the price by first checking for a $genericblock filter |
| 47 // and if necessary that our $csp filter is specific. | 51 // and if necessary that our $csp filter is specific. |
| 48 let specificOnly = checkWhitelisted(page, frame, typeMap.GENERICBLOCK); | 52 let specificOnly = !!checkWhitelisted(page, frame, typeMap.GENERICBLOCK); |
| 49 if (specificOnly) | 53 if (specificOnly) |
| 50 { | 54 { |
| 51 cspMatch = defaultMatcher.matchesAny(details.url, typeMap.CSP, hostname, | 55 cspMatch = defaultMatcher.matchesAny(urlString, typeMap.CSP, hostname, |
| 52 false, null, specificOnly); | 56 thirdParty, null, specificOnly); |
| 53 if (!(cspMatch instanceof BlockingFilter)) | 57 if (!cspMatch) |
| 54 return; | 58 return; |
| 55 } | 59 } |
| 56 | 60 |
| 61 devtools.logRequest(page, urlString, "CSP", hostname, thirdParty, null, | |
| 62 specificOnly, cspMatch); | |
| 57 FilterNotifier.emit("filter.hitCount", cspMatch, 0, 0, page); | 63 FilterNotifier.emit("filter.hitCount", cspMatch, 0, 0, page); |
| 58 devtools.logRequest(page, details.url, "CSP", hostname, false, null, | 64 |
| 59 specificOnly, cspMatch); | 65 if (cspMatch instanceof WhitelistFilter) |
| 66 return; | |
| 60 | 67 |
| 61 details.responseHeaders.push({ | 68 details.responseHeaders.push({ |
| 62 name: "Content-Security-Policy", | 69 name: "Content-Security-Policy", |
| 63 value: cspMatch.csp | 70 value: cspMatch.csp |
| 64 }); | 71 }); |
| 65 | 72 |
| 66 return {responseHeaders: details.responseHeaders}; | 73 return {responseHeaders: details.responseHeaders}; |
| 67 } | 74 } |
| 68 }, { | 75 }, { |
| 69 urls: ["http://*/*", "https://*/*"], | 76 urls: ["http://*/*", "https://*/*"], |
| 70 types: ["main_frame", "sub_frame"] | 77 types: ["main_frame", "sub_frame"] |
| 71 }, ["blocking", "responseHeaders"]); | 78 }, ["blocking", "responseHeaders"]); |
| LEFT | RIGHT |