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. 15, 2014, 9:22 a.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
« no previous file with comments | « 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,33 @@
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
+ for (; frame != null; frame = frame.parent)
+ {
+ if (urlsWithKey[frame.url])
+ return urlsWithKey[frame.url];
+ }
+ return null;
+}
+
+let verifyKey = function(key, signature, url, docDomain)
+{
let uri = new URI(url);
let params = [
uri.path, // REQUEST_URI
@@ -64,29 +69,32 @@
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(token, page, frame)
{
let url = stripFragmentFromURL(frame.url);
let docDomain = extractHostFromURL((frame.parent || frame).url);
- if (verifyKeyException(token, url, docDomain))
- recordKeyException(page, url);
+ if (token.indexOf("_") < 0)
+ return;
+
+ let [key, signature] = token.split("_", 2);
+ key = key.replace(/=/g, "");
+ if (verifyKey(key, signature, url, docDomain))
+ recordKey(page, url, key);
};
« no previous file with comments | « include.preload.js ('k') | webrequest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld