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

Commit a03f071

Browse files
committed
this fixes #100
1 parent 4c74d81 commit a03f071

File tree

9 files changed

+179
-6
lines changed

9 files changed

+179
-6
lines changed

_locales/de/messages.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,18 @@
359359
"message": "<p>Aus Wikipedia: &ldquo;Ein Referrer ist die Internetadresse der Webseite, von der der Benutzer durch Anklicken eines Links zu der aktuellen Seite gekommen ist. ... <b>(Die Übertragung eines Referrers zu verhindern) ...ist unter anderem aus Datenschutzerwägungen interessant, da andernfalls die Möglichkeit besteht, die Referrer mit den Nutzer-IP-Adressen in Verbindung zu bringen.</b>&rdquo;</p><p>Wenn dieser Schalter aktiviert ist, wird <i>HTTP Switchboard</i> den HTTP Referrer entfernen, wenn <b>beide</b> folgenden Bedingungen erfüllt sind:<ul style='padding-left:1em;list-style-type:disc;'><li>Der Domänenname des HTTP Referrer stimmt nicht mit dem Domänenname der anfragenden URL überein (das heißt, der Referrer stammt von einer Drittseite);<li>Der anfragende Hostname ist nicht auf der Whitelist.</ul></p>",
360360
"description": "..."
361361
},
362+
"settingsSpoofUserAgentPrompt1" : {
363+
"message": "Spoof <a href='https://en.wikipedia.org/wiki/User_agent'>User-Agent</a> string by randomly picking a new one below every",
364+
"description": "Spoof <a href='https://en.wikipedia.org/wiki/User_agent'>User-Agent</a> string by picking one randomly below every"
365+
},
366+
"settingsSpoofUserAgentPrompt2" : {
367+
"message": "minutes.",
368+
"description": "minutes."
369+
},
370+
"settingsSpoofUserAgentHelp" : {
371+
"message": "<a href='https://www.eff.org/deeplinks/2010/01/tracking-by-user-agent'>According to the <i>Electronic Frontier Foundation</i></a>: &ldquo;[...] your browser sends a &lsquo;User Agent&rsquo; header to the website saying precisely which operating system and web browser you are using. This information could help distinguish Internet users from one another because these versions differ, often considerably, from person to person. [...] <b>the User Agent string becomes a real privacy problem</b>.&rdquo;<p>This option allows you to address the problem raised by the EFF.</p><p>You can supply your own list of user agent strings. One string per line. Blank lines and lines prefixed with &lsquo;#&rsquo; will be ignored.</p>",
372+
"description": "..."
373+
},
362374
"settingsBehindTheSceneHeader" : {
363375
"message": "Chromium: Hintergrundanfragen",
364376
"description": "header of Chromium: behind-the-scene requests section"

_locales/en/messages.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,18 @@
359359
"message": "<p>From Wikipedia: &ldquo;HTTP referer is an HTTP header field that identifies the address of the webpage that linked to the resource being requested. ... <b>Because referer information can violate privacy, some web browsers allow the user to disable the sending of referer information.</b>&rdquo;</p><p>If this setting is checked, <i>HTTP Switchboard</i> will remove the HTTP referer information if <b>both</b> of the following conditions are true:<ul style='padding-left:1em;list-style-type:disc;'><li>The domain name of the HTTP referer does not match the domain name of the URL of the request (that is, the referer is third-party to the web page);<li>The hostname of the request is not whitelisted.</ul></p>",
360360
"description": "..."
361361
},
362+
"settingsSpoofUserAgentPrompt1" : {
363+
"message": "Spoof <a href='https://en.wikipedia.org/wiki/User_agent'>User-Agent</a> string by randomly picking a new one below every",
364+
"description": "Spoof <a href='https://en.wikipedia.org/wiki/User_agent'>User-Agent</a> string by picking one randomly below every"
365+
},
366+
"settingsSpoofUserAgentPrompt2" : {
367+
"message": "minutes.",
368+
"description": "minutes."
369+
},
370+
"settingsSpoofUserAgentHelp" : {
371+
"message": "<a href='https://www.eff.org/deeplinks/2010/01/tracking-by-user-agent'>According to the <i>Electronic Frontier Foundation</i></a>: &ldquo;[...] your browser sends a &lsquo;User Agent&rsquo; header to the website saying precisely which operating system and web browser you are using. This information could help distinguish Internet users from one another because these versions differ, often considerably, from person to person. [...] <b>the User Agent string becomes a real privacy problem</b>.&rdquo;<p>This option allows you to address the problem raised by the EFF.</p><p>You can supply your own list of user agent strings. One string per line. Blank lines and lines prefixed with &lsquo;#&rsquo; will be ignored.</p>",
372+
"description": "..."
373+
},
362374
"settingsBehindTheSceneHeader" : {
363375
"message": "Chromium: behind-the-scene requests",
364376
"description": "header of Chromium: behind-the-scene requests section"

_locales/fr/messages.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,18 @@
359359
"message": "<p>D'après Wikipedia : Un référant est une information transmise à un serveur HTTP lorsqu'un visiteur suit un lien pour accéder à l'une de ses ressources, lui indiquant l'URL de la page où se situe ce lien qu'il a suivi [...] <b>Les référants peuvent poser des problèmes d'atteinte à la vie privée, puisque le webmestre peut connaître les pages que ses visiteurs ont consulté avant d'accéder aux siennes.</b></p><p>Si ce paramètre est coché, <i>HTTP Switchboard</i> supprimera le référant HTTP si les <b>DEUX</b> conditions suivantes sont vérifiées :<ul style='padding-left:1em;list-style-type:disc;'><li>Le nom de domaine du référant HTTP ne correspond pas à l'URL de la requête (c'est-à-dire que le référant est un tiers par-rapport à la page);<li>Le nom d'hôte de la requête n'est pas sur liste blanche.</ul></p>",
360360
"description": "..."
361361
},
362+
"settingsSpoofUserAgentPrompt1" : {
363+
"message": "Modifier <a href='https://fr.wikipedia.org/wiki/User-Agent'>l'agent utilisateur</a> identifiant votre navigateur à chaque",
364+
"description": "Spoof <a href='https://en.wikipedia.org/wiki/User_agent'>User-Agent</a> string by picking one randomly below every"
365+
},
366+
"settingsSpoofUserAgentPrompt2" : {
367+
"message": "minutes en choisissant au hasard une des chaînes de caractères ci-dessous.",
368+
"description": "minutes."
369+
},
370+
"settingsSpoofUserAgentHelp" : {
371+
"message": "<a href='https://www.eff.org/deeplinks/2010/01/tracking-by-user-agent'>Selon la <i>Electronic Frontier Foundation</i></a>: &ldquo;[...] your browser sends a &lsquo;User Agent&rsquo; header to the website saying precisely which operating system and web browser you are using. This information could help distinguish Internet users from one another because these versions differ, often considerably, from person to person. [...] <b>the User Agent string becomes a real privacy problem</b>.&rdquo;<p>Cette option vous permet d'améliorer la protection de votre vie privée.</p><p>Vous pouvez fournir votre propre liste d'agents utilisateurs. Un seul agent utilisateur par ligne. Les lignes vides et les lignes débutant par &lsquo;#&rsquo; seront ignorées.</p>",
372+
"description": "..."
373+
},
362374
"settingsBehindTheSceneHeader" : {
363375
"message": "Requêtes en coulisses du navigateur",
364376
"description": "header of Chromium: behind-the-scene requests section"

background.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<script src="js/tab.js"></script>
2626
<script src="js/traffic.js"></script>
2727
<script src="js/uritools.js"></script>
28+
<script src="js/useragent.js"></script>
2829
<script src="js/contentscripthandlers.js"></script>
2930
<script src="js/start.js"></script>
3031
<script src="js/install.js"></script>

js/background.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ var HTTPSB = {
4343
popupCollapseSpecificDomains: {},
4444
processBehindTheSceneRequests: false,
4545
processReferer: false,
46+
spoofUserAgent: false,
47+
spoofUserAgentEvery: 5,
48+
spoofUserAgentWith: 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36\nMozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36\nMozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0\nMozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36\nMozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36\n',
4649
subframeOpacity: 1,
4750
smartAutoReload: 'all',
4851
statsFilters: {},
@@ -143,6 +146,8 @@ var HTTPSB = {
143146
storageQuota: chrome.storage.local.QUOTA_BYTES,
144147
storageUsed: 0,
145148
abpBlockCount: 0,
149+
userAgentReplaceStr: '',
150+
userAgentReplaceStrBirth: 0,
146151

147152
// internal state
148153
webRequestHandler: false,

js/settings.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ function onChangeValueHandler(elem, setting, min, max) {
7373

7474
/******************************************************************************/
7575

76+
function prepareToDie() {
77+
onChangeValueHandler($('#delete-unused-session-cookies-after'), 'deleteUnusedSessionCookiesAfter', 15, 1440);
78+
onChangeValueHandler($('#clear-browser-cache-after'), 'clearBrowserCacheAfter', 15, 1440);
79+
onChangeValueHandler($('#spoof-user-agent-every'), 'spoofUserAgentEvery', 2, 999);
80+
}
81+
82+
/******************************************************************************/
83+
7684
$(function() {
7785
var httpsb = gethttpsb();
7886
var userSettings = httpsb.userSettings;
@@ -92,6 +100,9 @@ $(function() {
92100
$('#clear-browser-cache').attr('checked', userSettings.clearBrowserCache === true);
93101
$('#clear-browser-cache-after').val(userSettings.clearBrowserCacheAfter);
94102
$('#process-referer').attr('checked', userSettings.processReferer);
103+
$('#spoof-user-agent').attr('checked', userSettings.spoofUserAgent);
104+
$('#spoof-user-agent-every').val(userSettings.spoofUserAgentEvery);
105+
$('#spoof-user-agent-with').val(userSettings.spoofUserAgentWith);
95106

96107
// Handle user interaction
97108
$('input[name="displayTextSize"]').on('change', function(){
@@ -133,12 +144,18 @@ $(function() {
133144
$('#process-referer').on('change', function(){
134145
changeUserSettings('processReferer', $(this).is(':checked'));
135146
});
136-
137-
$('#bye').on('click', function() {
138-
onChangeValueHandler($('#delete-unused-session-cookies-after'), 'deleteUnusedSessionCookiesAfter', 15, 1440);
139-
onChangeValueHandler($('#clear-browser-cache-after'), 'clearBrowserCacheAfter', 15, 1440);
140-
window.open('','_self').close();
147+
$('#spoof-user-agent').on('change', function(){
148+
changeUserSettings('spoofUserAgent', $(this).is(':checked'));
149+
});
150+
$('#spoof-user-agent-every').on('change', function(){
151+
onChangeValueHandler($(this), 'spoofUserAgentEvery', 2, 999);
141152
});
153+
$('#spoof-user-agent-with').on('change', function(){
154+
changeUserSettings('spoofUserAgentWith', $(this).val());
155+
});
156+
157+
// https://github.com/gorhill/httpswitchboard/issues/197
158+
$(window).one('beforeunload', prepareToDie);
142159
});
143160

144161
/******************************************************************************/

js/traffic.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,13 @@ var onBeforeSendHeadersHandler = function(details) {
398398
changed = foilRefererHeaders(httpsb, reqHostname, details) || changed;
399399
}
400400

401+
if ( httpsb.userSettings.spoofUserAgent ) {
402+
changed = foilUserAgent(httpsb, details) || changed;
403+
}
404+
401405
if ( changed ) {
402406
// console.debug('onBeforeSendHeadersHandler()> CHANGED "%s": %o', details.url, details);
403-
return { requestHeaders: details.headers };
407+
return { requestHeaders: details.requestHeaders };
404408
}
405409
};
406410

@@ -454,6 +458,23 @@ var foilRefererHeaders = function(httpsb, toHostname, details) {
454458

455459
/******************************************************************************/
456460

461+
var foilUserAgent = function(httpsb, details) {
462+
var changed = false;
463+
var headers = details.requestHeaders;
464+
var header;
465+
var i = 0;
466+
while ( header = headers[i] ) {
467+
if ( header.name.toLowerCase() === 'user-agent' ) {
468+
header.value = httpsb.userAgentReplaceStr;
469+
return true; // Assuming only one `user-agent` entry
470+
}
471+
i += 1;
472+
}
473+
return false;
474+
};
475+
476+
/******************************************************************************/
477+
457478
// To prevent inline javascript from being executed.
458479

459480
// Prevent inline scripting using `Content-Security-Policy`:

js/useragent.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*******************************************************************************
2+
3+
httpswitchboard - a Chromium browser extension to black/white list requests.
4+
Copyright (C) 2013 Raymond Hill
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see {http://www.gnu.org/licenses/}.
18+
19+
Home: https://github.com/gorhill/httpswitchboard
20+
*/
21+
22+
/******************************************************************************/
23+
24+
(function() {
25+
26+
/******************************************************************************/
27+
28+
var userAgentRandomPicker = function() {
29+
var httpsb = HTTPSB;
30+
var userAgents = httpsb.userSettings.spoofUserAgentWith.split(/[\n\r]+/);
31+
var i, s, pos;
32+
while ( userAgents.length ) {
33+
i = Math.floor(userAgents.length * Math.random());
34+
s = userAgents[i];
35+
if ( s.charAt(0) === '#' ) {
36+
s = '';
37+
} else {
38+
s = s.trim();
39+
}
40+
if ( s !== '' ) {
41+
return s;
42+
}
43+
userAgents.splice(i, 1);
44+
}
45+
return '';
46+
};
47+
48+
/******************************************************************************/
49+
50+
var userAgentSpoofer = function() {
51+
var httpsb = HTTPSB;
52+
if ( httpsb.userSettings.spoofUserAgent !== true ) {
53+
return;
54+
}
55+
var uaStr = httpsb.userAgentReplaceStr;
56+
var now = Date.now() / 60000;
57+
if ( (now - httpsb.userAgentReplaceStrBirth) >= httpsb.userSettings.spoofUserAgentEvery ) {
58+
uaStr = '';
59+
}
60+
if ( uaStr === '' ) {
61+
httpsb.userAgentReplaceStr = userAgentRandomPicker();
62+
httpsb.userAgentReplaceStrBirth = now;
63+
}
64+
};
65+
66+
userAgentSpoofer();
67+
68+
/******************************************************************************/
69+
70+
HTTPSB.asyncJobs.add('userAgentSwitcher', null, userAgentSpoofer, 120 * 1000, true);
71+
72+
/******************************************************************************/
73+
74+
})();
75+
76+
/******************************************************************************/
77+

settings.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@
2323
font-weight: 100;
2424
color: #888;
2525
}
26+
#spoof-user-agent-with {
27+
margin-left: 1.25em;
28+
display: block;
29+
font-size: 11px;
30+
width: 50em;
31+
height: 8em;
32+
white-space: pre;
33+
word-wrap: normal;
34+
overflow-x: scroll;
35+
}
2636
</style>
2737
</head>
2838

@@ -88,6 +98,12 @@ <h2 data-i18n="settingsPrivacyHeader"></h2>
8898
<input id="process-referer" type="checkbox" value=""><span data-i18n="settingsProcessRefererPrompt"></span>
8999
<button class="whatisthis"></button>
90100
<div class="whatisthis-expandable para" data-i18n="settingsProcessRefererHelp"></div>
101+
<li>&nbsp;
102+
<li>
103+
<input id="spoof-user-agent" type="checkbox" value=""><span data-i18n="settingsSpoofUserAgentPrompt1"></span> <input id="spoof-user-agent-every" type="text" value="5" size="3"> <span data-i18n="settingsSpoofUserAgentPrompt2"></span>
104+
<button class="whatisthis"></button>
105+
<div class="whatisthis-expandable para" data-i18n="settingsSpoofUserAgentHelp"></div>
106+
<textarea id="spoof-user-agent-with"></textarea>
91107
</ul>
92108

93109
<h2 data-i18n="settingsBehindTheSceneHeader"></h2>

0 commit comments

Comments
 (0)