1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-06 19:02:30 +01:00

hopefully fix #1782: treat data: URI as 1st-party resources

This commit is contained in:
gorhill 2016-07-25 08:18:17 -04:00
parent eaaf043a64
commit 4da4709ed5
3 changed files with 17 additions and 4 deletions

View File

@ -803,6 +803,11 @@ var domCollapser = (function() {
return; return;
} }
} }
// Some data: URI can be quite large: no point in taking into account
// the whole URI.
if ( src.lastIndexOf('data:', 0) === 0 ) {
src = src.slice(0, 255);
}
var req = new PendingRequest(target, tagName, prop); var req = new PendingRequest(target, tagName, prop);
newRequests.push(new BouncingRequest(req.id, tagName, src)); newRequests.push(new BouncingRequest(req.id, tagName, src));
}; };

View File

@ -471,7 +471,10 @@ var tagNameToRequestTypeMap = {
/******************************************************************************/ /******************************************************************************/
// Evaluate many requests // Evaluate many requests.
// https://github.com/gorhill/uBlock/issues/1782
// Treat `data:` URIs as 1st-party resources.
var filterRequests = function(pageStore, details) { var filterRequests = function(pageStore, details) {
var requests = details.requests; var requests = details.requests;
@ -492,9 +495,14 @@ var filterRequests = function(pageStore, details) {
var i = requests.length; var i = requests.length;
while ( i-- ) { while ( i-- ) {
request = requests[i]; request = requests[i];
context.requestURL = punycodeURL(request.url); if ( request.url.startsWith('data:') ) {
context.requestURL = request.url;
context.requestHostname = context.pageHostname;
} else {
context.requestURL = punycodeURL(request.url);
context.requestHostname = hostnameFromURI(context.requestURL);
}
context.requestType = tagNameToRequestTypeMap[request.tagName]; context.requestType = tagNameToRequestTypeMap[request.tagName];
context.requestHostname = hostnameFromURI(request.url);
r = pageStore.filterRequest(context); r = pageStore.filterRequest(context);
if ( typeof r !== 'string' || r.charAt(1) !== 'b' ) { if ( typeof r !== 'string' || r.charAt(1) !== 'b' ) {
continue; continue;

View File

@ -172,8 +172,8 @@ var atoi = function(s) {
return cachedParseInt(s, 10); return cachedParseInt(s, 10);
}; };
// Be sure to not confuse 'example.com' with 'anotherexample.com'
var isFirstParty = function(domain, hostname) { var isFirstParty = function(domain, hostname) {
// Be sure to not confuse 'example.com' with 'anotherexample.com'
return hostname.endsWith(domain) && return hostname.endsWith(domain) &&
(hostname.length === domain.length || (hostname.length === domain.length ||
hostname.charAt(hostname.length - domain.length - 1) === '.'); hostname.charAt(hostname.length - domain.length - 1) === '.');