Left: | ||
Right: |
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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 let {defaultMatcher} = require("matcher"); | 18 let {defaultMatcher} = require("matcher"); |
19 let {WhitelistFilter} = require("filterClasses"); | 19 let {WhitelistFilter} = require("filterClasses"); |
20 let {stringifyURL, getDecodedHostname, isThirdParty} = require("url"); | |
Wladimir Palant
2015/02/09 12:54:29
Shouldn't this import extractHostFromFrame as well
Sebastian Noack
2015/02/11 10:55:51
You are right. It works though, since extractHostF
| |
20 | 21 |
21 let pagesWithKey = new ext.PageMap(); | 22 let pagesWithKey = new ext.PageMap(); |
22 | 23 |
23 function isWhitelisted(url, parentUrl, type, key) | 24 function isPageWhitelisted(page) |
24 { | 25 { |
26 let url = page.url; | |
25 let filter = defaultMatcher.matchesAny( | 27 let filter = defaultMatcher.matchesAny( |
26 stripFragmentFromURL(url), | 28 stringifyURL(url), "DOCUMENT", |
27 type || "DOCUMENT", | 29 getDecodedHostname(url), false |
Wladimir Palant
2015/02/09 12:54:29
Please provide a sitekey parameter (null).
Sebastian Noack
2015/02/11 10:55:51
Done.
| |
28 extractHostFromURL(parentUrl || url), | |
29 false, | |
30 key | |
31 ); | 30 ); |
32 | 31 |
33 return (filter instanceof WhitelistFilter ? filter : null); | 32 return (filter instanceof WhitelistFilter ? filter : null); |
34 } | 33 } |
35 exports.isWhitelisted = isWhitelisted; | 34 exports.isPageWhitelisted = isPageWhitelisted; |
36 | 35 |
37 function isFrameWhitelisted(page, frame, type) | 36 function isFrameWhitelisted(page, frame, type) |
38 { | 37 { |
39 for (; frame != null; frame = frame.parent) | 38 while (frame) |
40 { | 39 { |
41 let key = getKey(page, frame); | 40 let parent = frame.parent; |
42 if (isWhitelisted(frame.url, (frame.parent || {}).url, type, key)) | 41 let url = frame.url; |
42 let documentHost = extractHostFromFrame(parent) || getDecodedHostname(url); | |
43 | |
44 let filter = defaultMatcher.matchesAny( | |
45 stringifyURL(url), type || "DOCUMENT", | |
46 documentHost, isThirdParty(url, documentHost), | |
47 getKey(page, frame) | |
48 ); | |
49 | |
50 if (filter instanceof WhitelistFilter) | |
43 return true; | 51 return true; |
52 | |
53 frame = parent; | |
44 } | 54 } |
45 | 55 |
46 return false; | 56 return false; |
47 } | 57 } |
48 exports.isFrameWhitelisted = isFrameWhitelisted; | 58 exports.isFrameWhitelisted = isFrameWhitelisted; |
49 | 59 |
50 function getKey(page, frame) | 60 function getKey(page, frame) |
51 { | 61 { |
52 let urlsWithKey = pagesWithKey.get(page); | 62 let urlsWithKey = pagesWithKey.get(page); |
53 if (!urlsWithKey) | 63 if (!urlsWithKey) |
54 return null; | 64 return null; |
55 | 65 |
56 for (; frame != null; frame = frame.parent) | 66 for (; frame != null; frame = frame.parent) |
57 { | 67 { |
58 if (urlsWithKey[frame.url]) | 68 let key = urlsWithKey[stringifyURL(frame.url)]; |
59 return urlsWithKey[frame.url]; | 69 if (key) |
70 return key; | |
60 } | 71 } |
61 | 72 |
62 return null; | 73 return null; |
63 } | 74 } |
64 exports.getKey = getKey; | 75 exports.getKey = getKey; |
65 | 76 |
66 function verifyKey(key, signature, url) | 77 function verifyKey(key, signature, url) |
67 { | 78 { |
68 url = new URL(url); | |
69 let params = [ | 79 let params = [ |
70 url.pathname + url.search, // REQUEST_URI | 80 url.pathname + url.search, // REQUEST_URI |
71 url.host, // HTTP_HOST | 81 url.host, // HTTP_HOST |
72 window.navigator.userAgent // HTTP_USER_AGENT | 82 window.navigator.userAgent // HTTP_USER_AGENT |
73 ]; | 83 ]; |
74 | 84 |
75 return verifySignature(key, signature, params.join("\0")); | 85 return verifySignature(key, signature, params.join("\0")); |
76 } | 86 } |
77 | 87 |
78 function recordKey(page, url, key) | 88 function recordKey(page, url, key) |
79 { | 89 { |
80 let urlsWithKey = pagesWithKey.get(page); | 90 let urlsWithKey = pagesWithKey.get(page); |
81 | 91 |
82 if (!urlsWithKey) | 92 if (!urlsWithKey) |
83 { | 93 { |
84 urlsWithKey = {__proto__: null}; | 94 urlsWithKey = {__proto__: null}; |
85 pagesWithKey.set(page, urlsWithKey); | 95 pagesWithKey.set(page, urlsWithKey); |
86 } | 96 } |
87 | 97 |
88 urlsWithKey[url] = key; | 98 urlsWithKey[stringifyURL(url)] = key; |
89 } | 99 } |
90 | 100 |
91 function processKey(token, page, frame) | 101 function processKey(token, page, frame) |
92 { | 102 { |
93 let url = stripFragmentFromURL(frame.url); | |
94 | |
95 if (token.indexOf("_") < 0) | 103 if (token.indexOf("_") < 0) |
96 return; | 104 return; |
97 | 105 |
98 let [key, signature] = token.split("_", 2); | 106 let [key, signature] = token.split("_", 2); |
99 key = key.replace(/=/g, ""); | 107 key = key.replace(/=/g, ""); |
100 | 108 |
101 if (verifyKey(key, signature, url)) | 109 if (verifyKey(key, signature, frame.url)) |
102 recordKey(page, url, key); | 110 recordKey(page, frame.url, key); |
103 } | 111 } |
104 exports.processKey = processKey; | 112 exports.processKey = processKey; |
OLD | NEW |