Browse Source
Fix #118, #271, #649, #771: removing flawed-at-the-core UA spoofer
Fix #118, #271, #649, #771: removing flawed-at-the-core UA spoofer
The end result of the flawed UA spoofer was to accomplish the OPPOSITE of the intended goal. UA spoofing for privacy purpose turns out to be a whole complicated task on its own, and is best undertaken as a separate dedicated extension -- assuming it is possible at all. In any case, this had no place in a "Privacy" section in uMatrix, this was a bad idea to create this feature in the first place. It's never too late to correct a bad idea, and this is the purpose of this commit.pull/2/head
gorhill
7 years ago
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
66 changed files with 16 additions and 1368 deletions
-
8platform/chromium/manifest.json
-
8platform/webext/manifest.json
-
20src/_locales/am/messages.json
-
20src/_locales/ar/messages.json
-
20src/_locales/bg/messages.json
-
20src/_locales/bn/messages.json
-
20src/_locales/ca/messages.json
-
20src/_locales/cs/messages.json
-
20src/_locales/da/messages.json
-
20src/_locales/de/messages.json
-
20src/_locales/el/messages.json
-
20src/_locales/en/messages.json
-
20src/_locales/eo/messages.json
-
20src/_locales/es/messages.json
-
20src/_locales/et/messages.json
-
20src/_locales/fa/messages.json
-
20src/_locales/fi/messages.json
-
20src/_locales/fil/messages.json
-
20src/_locales/fr/messages.json
-
20src/_locales/gu/messages.json
-
20src/_locales/he/messages.json
-
20src/_locales/hi/messages.json
-
20src/_locales/hr/messages.json
-
20src/_locales/hu/messages.json
-
20src/_locales/id/messages.json
-
20src/_locales/it/messages.json
-
20src/_locales/ja/messages.json
-
20src/_locales/kn/messages.json
-
20src/_locales/ko/messages.json
-
20src/_locales/lt/messages.json
-
20src/_locales/lv/messages.json
-
20src/_locales/ml/messages.json
-
20src/_locales/mr/messages.json
-
20src/_locales/ms/messages.json
-
20src/_locales/nb/messages.json
-
20src/_locales/nl/messages.json
-
20src/_locales/pl/messages.json
-
20src/_locales/pt_BR/messages.json
-
20src/_locales/pt_PT/messages.json
-
20src/_locales/ro/messages.json
-
20src/_locales/ru/messages.json
-
20src/_locales/sk/messages.json
-
20src/_locales/sl/messages.json
-
20src/_locales/sr/messages.json
-
20src/_locales/sv/messages.json
-
20src/_locales/sw/messages.json
-
20src/_locales/ta/messages.json
-
20src/_locales/te/messages.json
-
20src/_locales/th/messages.json
-
20src/_locales/tr/messages.json
-
20src/_locales/uk/messages.json
-
20src/_locales/vi/messages.json
-
20src/_locales/zh_CN/messages.json
-
20src/_locales/zh_TW/messages.json
-
1src/background.html
-
24src/js/background.js
-
150src/js/contentscript-start.js
-
10src/js/contentscript.js
-
6src/js/messaging.js
-
17src/js/privacy.js
-
3src/js/storage.js
-
4src/js/traffic.js
-
83src/js/useragent.js
-
11src/js/usersettings.js
-
1src/popup.html
-
18src/privacy.html
@ -1,150 +0,0 @@ |
|||
/******************************************************************************* |
|||
|
|||
µMatrix - a Chromium browser extension to black/white list requests. |
|||
Copyright (C) 2014 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 |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
This program is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with this program. If not, see {http://www.gnu.org/licenses/}.
|
|||
|
|||
Home: https://github.com/gorhill/uMatrix
|
|||
*/ |
|||
|
|||
/* global vAPI */ |
|||
/* jshint multistr: true */ |
|||
|
|||
// Injected into content pages
|
|||
|
|||
/******************************************************************************/ |
|||
|
|||
(function() { |
|||
|
|||
'use strict'; |
|||
|
|||
/******************************************************************************/ |
|||
|
|||
// https://github.com/chrisaljoudi/uBlock/issues/464
|
|||
if ( document instanceof HTMLDocument === false ) { |
|||
//console.debug('contentscript-start.js > not a HTLMDocument');
|
|||
return; |
|||
} |
|||
|
|||
// This can also happen (for example if script injected into a `data:` URI doc)
|
|||
if ( !window.location ) { |
|||
return; |
|||
} |
|||
|
|||
// This can happen
|
|||
if ( typeof vAPI !== 'object' ) { |
|||
//console.debug('contentscript-start.js > vAPI not found');
|
|||
return; |
|||
} |
|||
|
|||
// https://github.com/chrisaljoudi/uBlock/issues/456
|
|||
// Already injected?
|
|||
if ( vAPI.contentscriptStartInjected ) { |
|||
//console.debug('contentscript-end.js > content script already injected');
|
|||
return; |
|||
} |
|||
vAPI.contentscriptStartInjected = true; |
|||
|
|||
/******************************************************************************/ |
|||
|
|||
var localMessager = vAPI.messaging.channel('contentscript-start.js'); |
|||
|
|||
/******************************************************************************/ |
|||
|
|||
// If you play with this code, mind:
|
|||
// https://github.com/gorhill/httpswitchboard/issues/261
|
|||
// https://github.com/gorhill/httpswitchboard/issues/252
|
|||
|
|||
var navigatorSpoofer = " \ |
|||
;(function() { \n \ |
|||
try { \n \ |
|||
/* https://github.com/gorhill/uMatrix/issues/61#issuecomment-63814351 */ \n \ |
|||
var navigator = window.navigator; \n \ |
|||
var spoofedUserAgent = {{ua-json}}; \n \ |
|||
if ( spoofedUserAgent === navigator.userAgent ) { \n \ |
|||
return; \n \ |
|||
} \n \ |
|||
var pos = spoofedUserAgent.indexOf('/'); \n \ |
|||
var appName = pos === -1 ? '' : spoofedUserAgent.slice(0, pos); \n \ |
|||
var appVersion = pos === -1 ? spoofedUserAgent : spoofedUserAgent.slice(pos + 1); \n \ |
|||
Object.defineProperty(navigator, 'userAgent', { value: spoofedUserAgent }); \n \ |
|||
Object.defineProperty(navigator, 'appName', { value: appName }); \n \ |
|||
Object.defineProperty(navigator, 'appVersion', { value: appVersion }); \n \ |
|||
var c = document.currentScript, \n \ |
|||
p = c && c.parentNode; \n \ |
|||
if ( p ) { p.removeChild(c); } \n \ |
|||
} catch (e) { \n \ |
|||
} \n \ |
|||
})();"; |
|||
|
|||
/******************************************************************************/ |
|||
|
|||
// Because window.userAgent is read-only, we need to create a fake Navigator
|
|||
// object to contain our fake user-agent string.
|
|||
// Because objects created by a content script are local to the content script
|
|||
// and not visible to the web page itself (and vice versa), we need the context
|
|||
// of the web page to create the fake Navigator object directly, and the only
|
|||
// way to do this is to inject appropriate javascript code into the web page.
|
|||
|
|||
var injectNavigatorSpoofer = function(spoofedUserAgent) { |
|||
if ( typeof spoofedUserAgent !== 'string' ) { |
|||
return; |
|||
} |
|||
if ( spoofedUserAgent === navigator.userAgent ) { |
|||
return; |
|||
} |
|||
var parent = document.head || document.documentElement, |
|||
scriptText = navigatorSpoofer.replace('{{ua-json}}', JSON.stringify(spoofedUserAgent)), |
|||
script = document.createElement('script'); |
|||
script.setAttribute('type', 'text/javascript'); |
|||
script.appendChild(document.createTextNode(scriptText)); |
|||
try { |
|||
parent.appendChild(script); |
|||
} |
|||
catch (ex) { |
|||
} |
|||
|
|||
// https://github.com/gorhill/uMatrix/issues/771
|
|||
if ( script.parentNode !== null ) { |
|||
script.parentNode.removeChild(script); |
|||
script = document.createElement('script'); |
|||
script.setAttribute('type', 'text/javascript'); |
|||
script.setAttribute('src', 'data:application/javascript;base64,' + window.btoa(scriptText)); |
|||
try { |
|||
parent.appendChild(script); |
|||
} |
|||
catch (ex) { |
|||
} |
|||
if ( script.parentNode !== null ) { |
|||
script.parentNode.removeChild(script); |
|||
} |
|||
} |
|||
|
|||
// The port will never be used again at this point, disconnecting allows
|
|||
// to browser to flush this script from memory.
|
|||
localMessager.close(); |
|||
}; |
|||
|
|||
localMessager.send({ |
|||
what: 'getUserAgentReplaceStr', |
|||
hostname: window.location.hostname |
|||
}, injectNavigatorSpoofer); |
|||
|
|||
/******************************************************************************/ |
|||
/******************************************************************************/ |
|||
|
|||
})(); |
|||
|
|||
/******************************************************************************/ |
@ -1,83 +0,0 @@ |
|||
/******************************************************************************* |
|||
|
|||
uMatrix - a Chromium browser extension to black/white list 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 |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
This program is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with this program. If not, see {http://www.gnu.org/licenses/}.
|
|||
|
|||
Home: https://github.com/gorhill/uMatrix
|
|||
*/ |
|||
|
|||
/******************************************************************************/ |
|||
|
|||
µMatrix.userAgentSpoofer = (function() { |
|||
|
|||
"use strict"; |
|||
|
|||
/******************************************************************************/ |
|||
|
|||
var userAgentRandomPicker = function() { |
|||
var µm = µMatrix; |
|||
var userAgents = µm.userSettings.spoofUserAgentWith.split(/[\n\r]+/); |
|||
var i, s, pos; |
|||
while ( userAgents.length ) { |
|||
i = Math.floor(userAgents.length * Math.random()); |
|||
s = userAgents[i]; |
|||
if ( s.charAt(0) === '#' ) { |
|||
s = ''; |
|||
} else { |
|||
s = s.trim(); |
|||
} |
|||
if ( s !== '' ) { |
|||
return s; |
|||
} |
|||
userAgents.splice(i, 1); |
|||
} |
|||
return ''; |
|||
}; |
|||
|
|||
/******************************************************************************/ |
|||
|
|||
var userAgentSpoofer = function(force) { |
|||
var µm = µMatrix; |
|||
var uaStr = µm.userAgentReplaceStr; |
|||
var obsolete = Date.now(); |
|||
if ( !force ) { |
|||
obsolete -= µm.userSettings.spoofUserAgentEvery * 60 * 1000; |
|||
} |
|||
if ( µm.userAgentReplaceStrBirth < obsolete ) { |
|||
uaStr = ''; |
|||
} |
|||
if ( uaStr === '' ) { |
|||
µm.userAgentReplaceStr = userAgentRandomPicker(); |
|||
µm.userAgentReplaceStrBirth = Date.now(); |
|||
} |
|||
|
|||
vAPI.setTimeout(userAgentSpoofer, 120 * 1000); |
|||
}; |
|||
|
|||
userAgentSpoofer(); |
|||
|
|||
/******************************************************************************/ |
|||
|
|||
return { |
|||
shuffle: function() { |
|||
userAgentSpoofer(true); |
|||
} |
|||
}; |
|||
|
|||
})(); |
|||
|
|||
/******************************************************************************/ |
|||
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue