Skip to content
This repository has been archived by the owner on Nov 15, 2017. It is now read-only.

Commit

Permalink
Fix #29
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Oct 25, 2013
1 parent 0225791 commit eec61b5
Showing 1 changed file with 45 additions and 35 deletions.
80 changes: 45 additions & 35 deletions js/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function restoreTemporaryLists() {

// Check whether something is white or blacklisted, direct or indirectly.
//
// Levels of evaluations (4 distinct algorithms):
// Levels of evaluations (3 distinct algorithms):
// while hostname !== empty:
// type/hostname
// */hostname
Expand Down Expand Up @@ -170,59 +170,69 @@ function evaluate(type, hostname) {
var whitelist = httpsb.whitelist;
var graylist = httpsb.graylist;
var blacklistReadonly = httpsb.blacklistReadonly;
var key, parent;
var typeKey;
var cellKey, parent;

// Pick proper entry point

if ( type !== '*' && hostname !== '*' ) {
// https://github.com/gorhill/httpswitchboard/issues/29
typeKey = type + '/*';

// direct: specific type, specific hostname
key = type + '/' + hostname;
if ( whitelist[key] ) {
return httpsb.ALLOWED_DIRECT;
}
if ( blacklist[key] ) {
cellKey = type + '/' + hostname;
if ( blacklist[cellKey] ) {
return httpsb.DISALLOWED_DIRECT;
}
// indirect: any type, specific hostname
key = '*/' + hostname;
if ( whitelist[key] ) {
return httpsb.ALLOWED_INDIRECT;
if ( whitelist[cellKey] ) {
return httpsb.ALLOWED_DIRECT;
}
if ( blacklist[key] || (!graylist[key] && blacklistReadonly[hostname]) ) {
// indirect: any type, specific hostname
cellKey = '*/' + hostname;
if ( blacklist[cellKey] || (!graylist[cellKey] && blacklistReadonly[hostname]) ) {
return httpsb.DISALLOWED_INDIRECT;
}
if ( whitelist[cellKey] ) {
// https://github.com/gorhill/httpswitchboard/issues/29
// The cell is indirectly whitelisted because of hostname, type
// must nOT be blacklisted.
return blacklist[typeKey] ? httpsb.DISALLOWED_INDIRECT : httpsb.ALLOWED_INDIRECT;
}

// indirect: parent hostname nodes
parent = hostname;
while ( true ) {
parent = getParentHostnameFromHostname(parent);
if ( !parent ) {
break;
}
key = type + '/' + parent;
cellKey = type + '/' + parent;
// specific type, specific parent
if ( whitelist[key] ) {
return httpsb.ALLOWED_INDIRECT;
}
if ( blacklist[key] ) {
if ( blacklist[cellKey] ) {
return httpsb.DISALLOWED_INDIRECT;
}
// any type, specific parent
key = '*/' + parent;
if ( whitelist[key] ) {
if ( whitelist[cellKey] ) {
return httpsb.ALLOWED_INDIRECT;
}
if ( blacklist[key] || (!graylist[key] && blacklistReadonly[parent]) ) {
// any type, specific parent
cellKey = '*/' + parent;
if ( blacklist[cellKey] || (!graylist[cellKey] && blacklistReadonly[parent]) ) {
return httpsb.DISALLOWED_INDIRECT;
}
if ( whitelist[cellKey] ) {
// https://github.com/gorhill/httpswitchboard/issues/29
// The cell is indirectly whitelisted because of hostname, type
// must nOT be blacklisted.
return blacklist[typeKey] ? httpsb.DISALLOWED_INDIRECT : httpsb.ALLOWED_INDIRECT;
}
}
// indirect: specific type, any hostname
key = type + '/*';
if ( whitelist[key] ) {
return httpsb.ALLOWED_INDIRECT;
}
if ( blacklist[key] ) {
if ( blacklist[typeKey] ) {
return httpsb.DISALLOWED_INDIRECT;
}
if ( whitelist[typeKey] ) {
return httpsb.ALLOWED_INDIRECT;
}
// indirect: any type, any hostname
if ( whitelist['*/*'] ) {
return httpsb.ALLOWED_INDIRECT;
Expand All @@ -231,11 +241,11 @@ function evaluate(type, hostname) {
}
if ( type === '*' && hostname !== '*' ) {
// direct: any type, specific hostname
key = '*/' + hostname;
if ( whitelist[key] ) {
cellKey = '*/' + hostname;
if ( whitelist[cellKey] ) {
return httpsb.ALLOWED_DIRECT;
}
if ( blacklist[key] || (!graylist[key] && blacklistReadonly[hostname]) ) {
if ( blacklist[cellKey] || (!graylist[cellKey] && blacklistReadonly[hostname]) ) {
return httpsb.DISALLOWED_DIRECT;
}
// indirect: parent hostname nodes
Expand All @@ -246,11 +256,11 @@ function evaluate(type, hostname) {
break;
}
// any type, specific hostname
key = '*/' + parent;
if ( whitelist[key] ) {
cellKey = '*/' + parent;
if ( whitelist[cellKey] ) {
return httpsb.ALLOWED_INDIRECT;
}
if ( blacklist[key] || (!graylist[key] && blacklistReadonly[parent]) ) {
if ( blacklist[cellKey] || (!graylist[cellKey] && blacklistReadonly[parent]) ) {
return httpsb.DISALLOWED_INDIRECT;
}
}
Expand All @@ -262,11 +272,11 @@ function evaluate(type, hostname) {
}
if ( type !== '*' && hostname === '*' ) {
// indirect: specific type, any hostname
key = type + '/*';
if ( whitelist[key] ) {
cellKey = type + '/*';
if ( whitelist[cellKey] ) {
return httpsb.ALLOWED_DIRECT;
}
if ( blacklist[key] ) {
if ( blacklist[cellKey] ) {
return httpsb.DISALLOWED_DIRECT;
}
// indirect: any type, any hostname
Expand Down

0 comments on commit eec61b5

Please sign in to comment.