Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/whitelisting.js

Issue 5644946291818496: Issue 433 - Made adjustments for $sitekey-related changes to the Matcher API (Closed)
Patch Set: Created Sept. 10, 2014, 3:38 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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 20
21 let pagesWithKeyException = new ext.PageMap(); 21 let pagesWithKey = new ext.PageMap();
22 22
23 let isWhitelisted = exports.isWhitelisted = function(url, parentUrl, type) 23 let isWhitelisted = exports.isWhitelisted = function(url, parentUrl, type, key)
24 { 24 {
25 let filter = defaultMatcher.matchesAny( 25 let filter = defaultMatcher.matchesAny(
26 stripFragmentFromURL(url), 26 stripFragmentFromURL(url),
27 type || "DOCUMENT", 27 type || "DOCUMENT",
28 extractHostFromURL(parentUrl || url), 28 extractHostFromURL(parentUrl || url),
29 false 29 false,
30 key
30 ); 31 );
31 32
32 return (filter instanceof WhitelistFilter ? filter : null); 33 return (filter instanceof WhitelistFilter ? filter : null);
33 }; 34 };
34 35
35 let isFrameWhitelisted = exports.isFrameWhitelisted = function(page, frame, type ) 36 let isFrameWhitelisted = exports.isFrameWhitelisted = function(page, frame, type )
36 { 37 {
37 let urlsWithKeyException = pagesWithKeyException.get(page);
38
39 for (; frame != null; frame = frame.parent) 38 for (; frame != null; frame = frame.parent)
40 { 39 {
41 if (urlsWithKeyException && stripFragmentFromURL(frame.url) in urlsWithKeyEx ception) 40 let key = getKey(page, frame);
42 return true; 41 if (isWhitelisted(frame.url, (frame.parent || {}).url, type, key))
43 if (isWhitelisted(frame.url, (frame.parent || {}).url, type))
44 return true; 42 return true;
45 } 43 }
46 44
47 return false; 45 return false;
48 }; 46 };
49 47
50 let verifyKeyException = function(token, url, docDomain) 48 let getKey = exports.getKey = function(page, frame)
51 { 49 {
52 let match = token.match(/((.*?)=*)_(.*)/); 50 let urlsWithKey = pagesWithKey.get(page);
53 if (!match) 51 if (!urlsWithKey)
54 return false; // invalid format 52 return null;
55 53
56 let strippedKey = match[2]; 54 while (true)
57 if (!defaultMatcher.matchesByKey(url, strippedKey, docDomain)) 55 {
58 return false; // unknown key 56 if (urlsWithKey[frame.url])
57 return urlsWithKey[frame.url];
59 58
59 if (frame === frame.parent)
Wladimir Palant 2014/09/10 18:27:04 This isn't the DOM, it's our own structure - frame
Thomas Greiner 2014/09/15 09:24:59 Done.
60 return null;
61
62 frame = frame.parent;
63 }
64 }
65
66 let verifyKey = function(key, signature, url, docDomain)
67 {
60 let uri = new URI(url); 68 let uri = new URI(url);
61 let params = [ 69 let params = [
62 uri.path, // REQUEST_URI 70 uri.path, // REQUEST_URI
63 uri.asciiHost + (uri.port != -1 ? ":" + uri.port : ""), // HTTP_HOST 71 uri.asciiHost + (uri.port != -1 ? ":" + uri.port : ""), // HTTP_HOST
64 window.navigator.userAgent // HTTP_USER_AGENT 72 window.navigator.userAgent // HTTP_USER_AGENT
65 ]; 73 ];
66 74
67 let key = match[1];
68 let signature = match[3];
69 return verifySignature(key, signature, params.join("\0")); 75 return verifySignature(key, signature, params.join("\0"));
70 }; 76 };
71 77
72 let recordKeyException = function(page, url) 78 let recordKey = function(page, url, key)
73 { 79 {
74 let urlsWithKeyException = pagesWithKeyException.get(page); 80 let urlsWithKey = pagesWithKey.get(page);
75 81
76 if (!urlsWithKeyException) 82 if (!urlsWithKey)
77 { 83 {
78 urlsWithKeyException = {__proto__: null}; 84 urlsWithKey = {__proto__: null};
79 pagesWithKeyException.set(page, urlsWithKeyException); 85 pagesWithKey.set(page, urlsWithKey);
80 } 86 }
81 87
82 urlsWithKeyException[url] = null; 88 urlsWithKey[url] = key;
83 }; 89 };
84 90
85 let processKeyException = exports.processKeyException = function(token, page, fr ame) 91 let processKey = exports.processKey = function(sitekey, page, frame)
86 { 92 {
87 let url = stripFragmentFromURL(frame.url); 93 let url = stripFragmentFromURL(frame.url);
88 let docDomain = extractHostFromURL((frame.parent || frame).url); 94 let docDomain = extractHostFromURL((frame.parent || frame).url);
89 95
90 if (verifyKeyException(token, url, docDomain)) 96 let keydata = sitekey.match(/((.*?)=*)_(.*)/);
91 recordKeyException(page, url); 97 if (!keydata)
98 return;
99
100 let key = keydata[1].replace(/=/g, "");
101 let signature = keydata[3];
Wladimir Palant 2014/09/10 18:27:04 Why not use the same approach as in Firefox? if
Thomas Greiner 2014/09/15 09:24:59 Done.
102 if (verifyKey(key, signature, url, docDomain))
103 recordKey(page, url, key);
92 }; 104 };
OLDNEW
« include.preload.js ('K') | « include.preload.js ('k') | webrequest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld