mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-07 03:12:33 +01:00
code review: first-party determination must be based on root domain in dyna-filtering
This commit is contained in:
parent
fe486b7cb7
commit
500660bf18
@ -202,6 +202,8 @@ var tagNameToRequestTypeMap = {
|
|||||||
|
|
||||||
var filterRequests = function(pageStore, details) {
|
var filterRequests = function(pageStore, details) {
|
||||||
details.pageDomain = µb.URI.domainFromHostname(details.pageHostname);
|
details.pageDomain = µb.URI.domainFromHostname(details.pageHostname);
|
||||||
|
details.rootHostname = pageStore.rootHostname;
|
||||||
|
details.rootDomain = pageStore.rootDomain;
|
||||||
|
|
||||||
var inRequests = details.requests;
|
var inRequests = details.requests;
|
||||||
var outRequests = [];
|
var outRequests = [];
|
||||||
@ -236,6 +238,8 @@ var filterRequest = function(pageStore, details) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
details.pageDomain = µb.URI.domainFromHostname(details.pageHostname);
|
details.pageDomain = µb.URI.domainFromHostname(details.pageHostname);
|
||||||
|
details.rootHostname = pageStore.rootHostname;
|
||||||
|
details.rootDomain = pageStore.rootDomain;
|
||||||
var result = pageStore.filterRequest(
|
var result = pageStore.filterRequest(
|
||||||
details,
|
details,
|
||||||
tagNameToRequestTypeMap[details.tagName],
|
tagNameToRequestTypeMap[details.tagName],
|
||||||
|
@ -140,6 +140,15 @@ var atoi = function(s) {
|
|||||||
return cachedParseInt(s, 10);
|
return cachedParseInt(s, 10);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var isFirstParty = function(firstPartyDomain, hostname) {
|
||||||
|
if ( hostname.slice(0 - firstPartyDomain.length) !== firstPartyDomain ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Be sure to not confuse 'example.com' with 'anotherexample.com'
|
||||||
|
var c = hostname.charAt(hostname.length - firstPartyDomain.length - 1);
|
||||||
|
return c === '.' || c === '';
|
||||||
|
};
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
Filters family tree:
|
Filters family tree:
|
||||||
@ -1945,19 +1954,21 @@ FilterContainer.prototype.match3rdPartyHostname = function(requestHostname) {
|
|||||||
|
|
||||||
FilterContainer.prototype.matchStringExactType = function(pageDetails, requestURL, requestType) {
|
FilterContainer.prototype.matchStringExactType = function(pageDetails, requestURL, requestType) {
|
||||||
var url = requestURL.toLowerCase();
|
var url = requestURL.toLowerCase();
|
||||||
var pageDomain = pageDetails.pageDomain || '';
|
|
||||||
var requestHostname = µb.URI.hostnameFromURI(requestURL);
|
var requestHostname = µb.URI.hostnameFromURI(requestURL);
|
||||||
var party = requestHostname.slice(-pageDomain.length) === pageDomain ?
|
|
||||||
FirstParty :
|
|
||||||
ThirdParty;
|
|
||||||
|
|
||||||
// Evaluate dynamic filters first. "Block" dynamic filters are always
|
// Evaluate dynamic filters first. "Block" dynamic filters are always
|
||||||
// "important", they override everything else.
|
// "important", they override everything else.
|
||||||
var bf = this.matchDynamicFilters(pageDetails.rootHostname, requestType, party === FirstParty);
|
var bf = this.matchDynamicFilters(
|
||||||
|
pageDetails.rootHostname,
|
||||||
|
requestType,
|
||||||
|
isFirstParty(pageDetails.rootDomain, requestHostname)
|
||||||
|
);
|
||||||
if ( bf !== '' && bf.slice(0, 2) !== '@@' ) {
|
if ( bf !== '' && bf.slice(0, 2) !== '@@' ) {
|
||||||
return bf;
|
return bf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var party = isFirstParty(pageDetails.pageDomain, requestHostname) ? FirstParty : ThirdParty;
|
||||||
|
|
||||||
// This will be used by hostname-based filters
|
// This will be used by hostname-based filters
|
||||||
pageHostname = pageDetails.pageHostname || '';
|
pageHostname = pageDetails.pageHostname || '';
|
||||||
|
|
||||||
@ -2030,26 +2041,21 @@ FilterContainer.prototype.matchString = function(pageDetails, requestURL, reques
|
|||||||
// filters are tested *only* if there is a (unlikely) hit on a block
|
// filters are tested *only* if there is a (unlikely) hit on a block
|
||||||
// filter.
|
// filter.
|
||||||
|
|
||||||
var pageDomain = pageDetails.pageDomain || '';
|
|
||||||
var requestHostname = µb.URI.hostnameFromURI(requestURL);
|
var requestHostname = µb.URI.hostnameFromURI(requestURL);
|
||||||
|
|
||||||
// Find out the relation between the page and request
|
|
||||||
var party = ThirdParty;
|
|
||||||
if ( requestHostname.slice(0 - pageDomain.length) === pageDomain ) {
|
|
||||||
// Be sure to not confuse 'example.com' with 'anotherexample.com'
|
|
||||||
var c = requestHostname.charAt(requestHostname.length - pageDomain.length - 1);
|
|
||||||
if ( c === '' || c === '.' ) {
|
|
||||||
party = FirstParty;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Evaluate dynamic filters first. "Block" dynamic filters are always
|
// Evaluate dynamic filters first. "Block" dynamic filters are always
|
||||||
// "important", they override everything else.
|
// "important", they override everything else.
|
||||||
var bf = this.matchDynamicFilters(pageDetails.rootHostname, requestType, party === FirstParty);
|
var bf = this.matchDynamicFilters(
|
||||||
|
pageDetails.rootHostname,
|
||||||
|
requestType,
|
||||||
|
isFirstParty(pageDetails.rootDomain, requestHostname)
|
||||||
|
);
|
||||||
if ( bf !== '' && bf.slice(0, 2) !== '@@' ) {
|
if ( bf !== '' && bf.slice(0, 2) !== '@@' ) {
|
||||||
return bf;
|
return bf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var party = isFirstParty(pageDetails.pageDomain, requestHostname) ? FirstParty : ThirdParty ;
|
||||||
|
|
||||||
// This will be used by hostname-based filters
|
// This will be used by hostname-based filters
|
||||||
pageHostname = pageDetails.pageHostname || '';
|
pageHostname = pageDetails.pageHostname || '';
|
||||||
|
|
||||||
|
@ -240,15 +240,17 @@ FrameStore.factory = function(rootHostname, frameURL) {
|
|||||||
FrameStore.prototype.init = function(rootHostname, frameURL) {
|
FrameStore.prototype.init = function(rootHostname, frameURL) {
|
||||||
var µburi = µb.URI;
|
var µburi = µb.URI;
|
||||||
this.pageHostname = µburi.hostnameFromURI(frameURL);
|
this.pageHostname = µburi.hostnameFromURI(frameURL);
|
||||||
this.pageDomain = µburi.domainFromHostname(this.pageHostname);
|
this.pageDomain = µburi.domainFromHostname(this.pageHostname) || this.pageHostname;
|
||||||
this.rootHostname = rootHostname;
|
this.rootHostname = rootHostname;
|
||||||
|
this.rootDomain = µburi.domainFromHostname(rootHostname) || rootHostname;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
FrameStore.prototype.dispose = function() {
|
FrameStore.prototype.dispose = function() {
|
||||||
this.pageHostname = this.pageDomain = this.rootHostname = '';
|
this.pageHostname = this.pageDomain =
|
||||||
|
this.rootHostname = this.rootDomain = '';
|
||||||
if ( frameStoreJunkyard.length < frameStoreJunkyardMax ) {
|
if ( frameStoreJunkyard.length < frameStoreJunkyardMax ) {
|
||||||
frameStoreJunkyard.push(this);
|
frameStoreJunkyard.push(this);
|
||||||
}
|
}
|
||||||
@ -298,6 +300,7 @@ PageStore.prototype.init = function(tabId, pageURL) {
|
|||||||
// Use hostname if no domain can be extracted
|
// Use hostname if no domain can be extracted
|
||||||
this.pageDomain = µb.URI.domainFromHostname(this.pageHostname) || this.pageHostname;
|
this.pageDomain = µb.URI.domainFromHostname(this.pageHostname) || this.pageHostname;
|
||||||
this.rootHostname = this.pageHostname;
|
this.rootHostname = this.pageHostname;
|
||||||
|
this.rootDomain = this.pageDomain;
|
||||||
|
|
||||||
this.frames = {};
|
this.frames = {};
|
||||||
this.netFiltering = true;
|
this.netFiltering = true;
|
||||||
@ -327,6 +330,7 @@ PageStore.prototype.reuse = function(pageURL, context) {
|
|||||||
this.pageHostname = µb.URI.hostnameFromURI(pageURL);
|
this.pageHostname = µb.URI.hostnameFromURI(pageURL);
|
||||||
this.pageDomain = µb.URI.domainFromHostname(this.pageHostname) || this.pageHostname;
|
this.pageDomain = µb.URI.domainFromHostname(this.pageHostname) || this.pageHostname;
|
||||||
this.rootHostname = this.pageHostname;
|
this.rootHostname = this.pageHostname;
|
||||||
|
this.rootDomain = this.pageDomain;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
// A new page is completely reloaded from scratch, reset all.
|
// A new page is completely reloaded from scratch, reset all.
|
||||||
@ -347,11 +351,9 @@ PageStore.prototype.dispose = function() {
|
|||||||
// need to release the memory taken by these, which can amount to
|
// need to release the memory taken by these, which can amount to
|
||||||
// sizeable enough chunks (especially requests, through the request URL
|
// sizeable enough chunks (especially requests, through the request URL
|
||||||
// used as a key).
|
// used as a key).
|
||||||
this.pageURL = '';
|
this.pageURL = this.previousPageURL =
|
||||||
this.previousPageURL = '';
|
this.pageHostname = this.pageDomain =
|
||||||
this.pageHostname = '';
|
this.rootHostname = this.rootDomain = '';
|
||||||
this.pageDomain = '';
|
|
||||||
this.rootHostname = '';
|
|
||||||
this.disposeFrameStores();
|
this.disposeFrameStores();
|
||||||
this.netFilteringCache = this.netFilteringCache.dispose();
|
this.netFilteringCache = this.netFilteringCache.dispose();
|
||||||
if ( pageStoreJunkyard.length < pageStoreJunkyardMax ) {
|
if ( pageStoreJunkyard.length < pageStoreJunkyardMax ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user