| OLD | NEW |
| 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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 /** @module whitelisting */ | 18 /** @module whitelisting */ |
| 19 | 19 |
| 20 "use strict"; | 20 "use strict"; |
| 21 | 21 |
| 22 let {defaultMatcher} = require("matcher"); | 22 let {defaultMatcher} = require("matcher"); |
| 23 let {RegExpFilter} = require("filterClasses"); | 23 let {RegExpFilter} = require("filterClasses"); |
| 24 let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = req
uire("url"); | 24 let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = req
uire("url"); |
| 25 let {port} = require("messaging"); |
| 25 let devtools = require("devtools"); | 26 let devtools = require("devtools"); |
| 26 | 27 |
| 27 let pagesWithKey = new ext.PageMap(); | 28 let pagesWithKey = new ext.PageMap(); |
| 28 | 29 |
| 29 function match(page, url, typeMask, docDomain, sitekey) | 30 function match(page, url, typeMask, docDomain, sitekey) |
| 30 { | 31 { |
| 31 let thirdParty = !!docDomain && isThirdParty(url, docDomain); | 32 let thirdParty = !!docDomain && isThirdParty(url, docDomain); |
| 32 let urlString = stringifyURL(url); | 33 let urlString = stringifyURL(url); |
| 33 | 34 |
| 34 if (!docDomain) | 35 if (!docDomain) |
| 35 docDomain = getDecodedHostname(url); | 36 docDomain = getDecodedHostname(url); |
| 36 | 37 |
| 37 let filter = defaultMatcher.whitelist.matchesAny( | 38 let filter = defaultMatcher.whitelist.matchesAny( |
| 38 urlString, typeMask, docDomain, thirdParty, sitekey | 39 urlString, typeMask, docDomain, thirdParty, sitekey |
| 39 ); | 40 ); |
| 40 | 41 |
| 41 if (filter && devtools) | 42 if (filter && devtools) |
| 42 devtools.logWhitelistedDocument( | 43 devtools.logWhitelistedDocument( |
| 43 page, urlString, typeMask, docDomain, filter | 44 page, urlString, typeMask, docDomain, filter |
| 44 ); | 45 ); |
| 45 | 46 |
| 46 return filter; | 47 return filter; |
| 47 } | 48 } |
| 48 | 49 |
| 50 let checkWhitelisted = |
| 49 /** | 51 /** |
| 50 * Gets the active whitelisting filter for the document associated | 52 * Gets the active whitelisting filter for the document associated |
| 51 * with the given page/frame, or null if it's not whitelisted. | 53 * with the given page/frame, or null if it's not whitelisted. |
| 52 * | 54 * |
| 53 * @param {Page} page | 55 * @param {Page} page |
| 54 * @param {Frame} [frame] | 56 * @param {Frame} [frame] |
| 55 * @param {number} [typeMask=RegExpFilter.typeMap.DOCUMENT] | 57 * @param {number} [typeMask=RegExpFilter.typeMap.DOCUMENT] |
| 56 * @return {?WhitelistFilter} | 58 * @return {?WhitelistFilter} |
| 57 */ | 59 */ |
| 58 exports.checkWhitelisted = function(page, frame, typeMask) | 60 exports.checkWhitelisted = function(page, frame, typeMask) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 | 124 |
| 123 if (!urlsWithKey) | 125 if (!urlsWithKey) |
| 124 { | 126 { |
| 125 urlsWithKey = Object.create(null); | 127 urlsWithKey = Object.create(null); |
| 126 pagesWithKey.set(page, urlsWithKey); | 128 pagesWithKey.set(page, urlsWithKey); |
| 127 } | 129 } |
| 128 | 130 |
| 129 urlsWithKey[stringifyURL(url)] = key; | 131 urlsWithKey[stringifyURL(url)] = key; |
| 130 } | 132 } |
| 131 | 133 |
| 134 let processKey = |
| 132 /** | 135 /** |
| 133 * Validates signatures given by the "X-Adblock-Key" response | 136 * Validates signatures given by the "X-Adblock-Key" response |
| 134 * header or the "data-adblockkey" attribute of the document | 137 * header or the "data-adblockkey" attribute of the document |
| 135 * element. If the signature is valid, the public key will be | 138 * element. If the signature is valid, the public key will be |
| 136 * recorded and considered for the $sitekey filter option. | 139 * recorded and considered for the $sitekey filter option. |
| 137 * | 140 * |
| 138 * @param {string} token The base64-encoded public key and | 141 * @param {string} token The base64-encoded public key and |
| 139 * signature separated by an underscrore. | 142 * signature separated by an underscrore. |
| 140 * @param {Page} page | 143 * @param {Page} page |
| 141 * @param {Frame} frame | 144 * @param {Frame} frame |
| 142 */ | 145 */ |
| 143 exports.processKey = function(token, page, frame) | 146 exports.processKey = function(token, page, frame) |
| 144 { | 147 { |
| 145 if (token.indexOf("_") < 0) | 148 if (token.indexOf("_") < 0) |
| 146 return; | 149 return; |
| 147 | 150 |
| 148 let [key, signature] = token.split("_", 2); | 151 let [key, signature] = token.split("_", 2); |
| 149 key = key.replace(/=/g, ""); | 152 key = key.replace(/=/g, ""); |
| 150 | 153 |
| 151 if (verifyKey(key, signature, frame.url)) | 154 if (verifyKey(key, signature, frame.url)) |
| 152 recordKey(page, frame.url, key); | 155 recordKey(page, frame.url, key); |
| 153 }; | 156 }; |
| 157 |
| 158 port.on("filters.addKey", (message, sender) => |
| 159 { |
| 160 processKey(message.token, sender.page, sender.frame); |
| 161 }); |
| 162 |
| 163 port.on("filters.isPageWhitelisted", (message, sender) => |
| 164 { |
| 165 return !!checkWhitelisted(sender.page); |
| 166 }); |
| OLD | NEW |