Index: lib/whitelisting.js |
=================================================================== |
--- a/lib/whitelisting.js |
+++ b/lib/whitelisting.js |
@@ -17,30 +17,40 @@ |
let {defaultMatcher} = require("matcher"); |
let {WhitelistFilter} = require("filterClasses"); |
+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
|
let pagesWithKey = new ext.PageMap(); |
-function isWhitelisted(url, parentUrl, type, key) |
+function isPageWhitelisted(page) |
{ |
+ let url = page.url; |
let filter = defaultMatcher.matchesAny( |
- stripFragmentFromURL(url), |
- type || "DOCUMENT", |
- extractHostFromURL(parentUrl || url), |
- false, |
- key |
+ stringifyURL(url), "DOCUMENT", |
+ 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.
|
); |
return (filter instanceof WhitelistFilter ? filter : null); |
} |
-exports.isWhitelisted = isWhitelisted; |
+exports.isPageWhitelisted = isPageWhitelisted; |
function isFrameWhitelisted(page, frame, type) |
{ |
- for (; frame != null; frame = frame.parent) |
+ while (frame) |
{ |
- let key = getKey(page, frame); |
- if (isWhitelisted(frame.url, (frame.parent || {}).url, type, key)) |
+ let parent = frame.parent; |
+ let url = frame.url; |
+ let documentHost = extractHostFromFrame(parent) || getDecodedHostname(url); |
+ |
+ let filter = defaultMatcher.matchesAny( |
+ stringifyURL(url), type || "DOCUMENT", |
+ documentHost, isThirdParty(url, documentHost), |
+ getKey(page, frame) |
+ ); |
+ |
+ if (filter instanceof WhitelistFilter) |
return true; |
+ |
+ frame = parent; |
} |
return false; |
@@ -55,8 +65,9 @@ |
for (; frame != null; frame = frame.parent) |
{ |
- if (urlsWithKey[frame.url]) |
- return urlsWithKey[frame.url]; |
+ let key = urlsWithKey[stringifyURL(frame.url)]; |
+ if (key) |
+ return key; |
} |
return null; |
@@ -65,7 +76,6 @@ |
function verifyKey(key, signature, url) |
{ |
- url = new URL(url); |
let params = [ |
url.pathname + url.search, // REQUEST_URI |
url.host, // HTTP_HOST |
@@ -85,20 +95,18 @@ |
pagesWithKey.set(page, urlsWithKey); |
} |
- urlsWithKey[url] = key; |
+ urlsWithKey[stringifyURL(url)] = key; |
} |
function processKey(token, page, frame) |
{ |
- let url = stripFragmentFromURL(frame.url); |
- |
if (token.indexOf("_") < 0) |
return; |
let [key, signature] = token.split("_", 2); |
key = key.replace(/=/g, ""); |
- if (verifyKey(key, signature, url)) |
- recordKey(page, url, key); |
+ if (verifyKey(key, signature, frame.url)) |
+ recordKey(page, frame.url, key); |
} |
exports.processKey = processKey; |