This commit is contained in:
gorhill 2016-03-22 10:19:41 -04:00
parent bd229db64e
commit 95d0ffafb7
4 changed files with 65 additions and 6 deletions

View file

@ -1,7 +1,7 @@
/*******************************************************************************
µBlock - a browser extension to block requests.
Copyright (C) 2014 The µBlock authors
uBlock Origin - a browser extension to block requests.
Copyright (C) 2014-2016 The uBlock Origin authors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -788,6 +788,11 @@ vAPI.net.registerListeners = function() {
var µb = µBlock;
var µburi = µb.URI;
// https://bugs.chromium.org/p/chromium/issues/detail?id=410382
// Between Chromium 38-48, plug-ins' network requests were reported as
// type "other" instead of "object".
var is_v38_48 = /\bChrom[a-z]+\/(?:3[89]|4[0-8])\.[\d.]+\b/.test(navigator.userAgent);
// Chromium-based browsers understand only these network request types.
var validTypes = {
'main_frame': true,
@ -836,6 +841,14 @@ vAPI.net.registerListeners = function() {
var normalizeRequestDetails = function(details) {
details.tabId = details.tabId.toString();
// https://github.com/gorhill/uBlock/issues/1493
// Chromium 49+ support a new request type: `ping`, which is fired as
// a result of using `navigator.sendBeacon`.
if ( details.type === 'ping' ) {
details.type = 'beacon';
return;
}
// The rest of the function code is to normalize type
if ( details.type !== 'other' ) {
return;
@ -885,7 +898,9 @@ vAPI.net.registerListeners = function() {
}
// https://code.google.com/p/chromium/issues/detail?id=410382
details.type = 'object';
if ( is_v38_48 ) {
details.type = 'object';
}
};
var onBeforeRequestClient = this.onBeforeRequest.callback;

View file

@ -807,6 +807,10 @@ vAPI.tabs.registerListeners();
return this.pageStores[tabId] || null;
};
µb.mustPageStoreFromTabId = function(tabId) {
return this.pageStores[tabId] || this.pageStores[vAPI.noTabId];
};
/******************************************************************************/
// Permanent page store for behind-the-scene requests. Must never be removed.

View file

@ -1,7 +1,7 @@
/*******************************************************************************
uBlock - a browser extension to block requests.
Copyright (C) 2014-2015 Raymond Hill
uBlock Origin - a browser extension to block requests.
Copyright (C) 2014-2016 Raymond Hill
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -47,6 +47,12 @@ var onBeforeRequest = function(details) {
return onBeforeRootFrameRequest(details);
}
// https://github.com/gorhill/uBlock/issues/870
// This work for Chromium 49+.
if ( requestType === 'beacon' ) {
return onBeforeBeacon(details);
}
// Special treatment: behind-the-scene requests
var tabId = details.tabId;
if ( vAPI.isBehindTheSceneTabId(tabId) ) {
@ -273,6 +279,40 @@ var toBlockDocResult = function(url, hostname, result) {
/******************************************************************************/
// https://github.com/gorhill/uBlock/issues/870
// Finally, Chromium 49+ gained the ability to report network request of type
// `beacon`, so now we can block them according to the state of the
// "Disable hyperlink auditing/beacon" setting.
var onBeforeBeacon = function(details) {
var µb = µBlock;
var tabId = details.tabId;
var pageStore = µb.mustPageStoreFromTabId(tabId);
var context = pageStore.createContextFromPage();
context.requestURL = details.url;
context.requestHostname = µb.URI.hostnameFromURI(details.url);
context.requestType = details.type;
// "g" in "gb:" stands for "global setting"
var result = µb.userSettings.hyperlinkAuditingDisabled ? 'gb:' : '';
pageStore.logRequest(context, result);
if ( µb.logger.isEnabled() ) {
µb.logger.writeOne(
tabId,
'net',
result,
details.type,
details.url,
context.rootHostname,
context.rootHostname
);
}
if ( result !== '' ) {
return { cancel: true };
}
};
/******************************************************************************/
// Intercept and filter behind-the-scene requests.
var onBeforeBehindTheSceneRequest = function(details) {

View file

@ -20,7 +20,7 @@
<li><input id="advanced-user-enabled" type="checkbox" data-setting-name="advancedUserEnabled" data-setting-type="bool"><label data-i18n="settingsAdvancedUserPrompt" for="advanced-user-enabled"></label>
<li class="subgroup"><span data-i18n="3pGroupPrivacy"></span><ul>
<li><input id="prefetching-disabled" type="checkbox" data-setting-name="prefetchingDisabled" data-setting-type="bool"><label data-i18n="settingsPrefetchingDisabledPrompt" for="prefetching-disabled"></label> <a class="fa info" href="https://wikipedia.org/wiki/Link_prefetching#Issues_and_criticisms" target="_blank">&#xf05a;</a>
<li><input id="hyperlink-auditing-disabled" type="checkbox" data-setting-name="hyperlinkAuditingDisabled" data-setting-type="bool"><label data-i18n="settingsHyperlinkAuditingDisabledPrompt" for="hyperlink-auditing-disabled"></label> <a class="fa info" href="http://www.wilderssecurity.com/threads/hyperlink-auditing-aka-a-ping-and-beacon-aka-navigator-sendbeacon.364904/" target="_blank">&#xf05a;</a>
<li><input id="hyperlink-auditing-disabled" type="checkbox" data-setting-name="hyperlinkAuditingDisabled" data-setting-type="bool"><label data-i18n="settingsHyperlinkAuditingDisabledPrompt" for="hyperlink-auditing-disabled"></label> <a class="fa info important" href="https://github.com/gorhill/uBlock/wiki/Disable-hyperlink-auditing-beacon" target="_blank">&#xf05a;</a>
<li><input id="webrtc-ipaddress-hidden" type="checkbox" data-setting-name="webrtcIPAddressHidden" data-setting-type="bool"><label data-i18n="settingsWebRTCIPAddressHiddenPrompt" for="webrtc-ipaddress-hidden"></label> <a class="fa info important" href="https://github.com/gorhill/uBlock/wiki/Prevent-WebRTC-from-leaking-local-IP-address" target="_blank">&#xf05a;</a>
</ul>
<li class="subgroup"><span data-i18n="settingPerSiteSwitchGroup"></span><ul>