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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« include.preload.js ('K') | « include.preload.js ('k') | webrequest.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/whitelisting.js
===================================================================
--- a/lib/whitelisting.js
+++ b/lib/whitelisting.js
@@ -18,15 +18,16 @@
let {defaultMatcher} = require("matcher");
let {WhitelistFilter} = require("filterClasses");
-let pagesWithKeyException = new ext.PageMap();
+let pagesWithKey = new ext.PageMap();
-let isWhitelisted = exports.isWhitelisted = function(url, parentUrl, type)
+let isWhitelisted = exports.isWhitelisted = function(url, parentUrl, type, key)
{
let filter = defaultMatcher.matchesAny(
stripFragmentFromURL(url),
type || "DOCUMENT",
extractHostFromURL(parentUrl || url),
- false
+ false,
+ key
);
return (filter instanceof WhitelistFilter ? filter : null);
@@ -34,29 +35,36 @@
let isFrameWhitelisted = exports.isFrameWhitelisted = function(page, frame, type)
{
- let urlsWithKeyException = pagesWithKeyException.get(page);
-
for (; frame != null; frame = frame.parent)
{
- if (urlsWithKeyException && stripFragmentFromURL(frame.url) in urlsWithKeyException)
- return true;
- if (isWhitelisted(frame.url, (frame.parent || {}).url, type))
+ let key = getKey(page, frame);
+ if (isWhitelisted(frame.url, (frame.parent || {}).url, type, key))
return true;
}
return false;
};
-let verifyKeyException = function(token, url, docDomain)
+let getKey = exports.getKey = function(page, frame)
{
- let match = token.match(/((.*?)=*)_(.*)/);
- if (!match)
- return false; // invalid format
+ let urlsWithKey = pagesWithKey.get(page);
+ if (!urlsWithKey)
+ return null;
- let strippedKey = match[2];
- if (!defaultMatcher.matchesByKey(url, strippedKey, docDomain))
- return false; // unknown key
+ while (true)
+ {
+ if (urlsWithKey[frame.url])
+ return urlsWithKey[frame.url];
+ 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.
+ return null;
+
+ frame = frame.parent;
+ }
+}
+
+let verifyKey = function(key, signature, url, docDomain)
+{
let uri = new URI(url);
let params = [
uri.path, // REQUEST_URI
@@ -64,29 +72,33 @@
window.navigator.userAgent // HTTP_USER_AGENT
];
- let key = match[1];
- let signature = match[3];
return verifySignature(key, signature, params.join("\0"));
};
-let recordKeyException = function(page, url)
+let recordKey = function(page, url, key)
{
- let urlsWithKeyException = pagesWithKeyException.get(page);
+ let urlsWithKey = pagesWithKey.get(page);
- if (!urlsWithKeyException)
+ if (!urlsWithKey)
{
- urlsWithKeyException = {__proto__: null};
- pagesWithKeyException.set(page, urlsWithKeyException);
+ urlsWithKey = {__proto__: null};
+ pagesWithKey.set(page, urlsWithKey);
}
- urlsWithKeyException[url] = null;
+ urlsWithKey[url] = key;
};
-let processKeyException = exports.processKeyException = function(token, page, frame)
+let processKey = exports.processKey = function(sitekey, page, frame)
{
let url = stripFragmentFromURL(frame.url);
let docDomain = extractHostFromURL((frame.parent || frame).url);
- if (verifyKeyException(token, url, docDomain))
- recordKeyException(page, url);
+ let keydata = sitekey.match(/((.*?)=*)_(.*)/);
+ if (!keydata)
+ return;
+
+ let key = keydata[1].replace(/=/g, "");
+ 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.
+ if (verifyKey(key, signature, url, docDomain))
+ recordKey(page, url, key);
};
« include.preload.js ('K') | « include.preload.js ('k') | webrequest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld