Browse Source

this fixes #59

pull/2/head
Raymond Hill 10 years ago
parent
commit
5d8bae3da2
  1. 7
      src/js/matrix.js
  2. 1
      src/js/messaging-handlers.js
  3. 15
      src/js/storage.js
  4. 43
      src/js/traffic.js
  5. 1
      src/popup.html
  6. 2
      src/privacy.html
  7. 6
      tools/_locales/en/messages.json

7
src/js/matrix.js

@ -82,9 +82,10 @@ var nameToStateMap = {
};
var switchBitOffsets = {
'matrix-off': 0,
'https-strict': 2,
'ua-spoof': 4
'matrix-off': 0,
'https-strict': 2,
'ua-spoof': 4,
'referrer-spoof': 6
};
var switchStateToNameMap = {

1
src/js/messaging-handlers.js

@ -462,6 +462,7 @@ var onMessage = function(request, sender, callback) {
matrixSwitches: {
'https-strict': µm.pMatrix.evaluateSwitch('https-strict', '*') === 1,
'ua-spoof': µm.pMatrix.evaluateSwitch('ua-spoof', '*') === 1,
'referrer-spoof': µm.pMatrix.evaluateSwitch('referrer-spoof', '*') === 1
}
};
break;

15
src/js/storage.js

@ -404,19 +404,26 @@
var matrixReady = false;
// TODO: to remove when everybody (and their backup file) has their
// ua-spoof setting converted into a matrix switch.
// ua-spoof/referrer-spoof setting converted into a matrix switch.
var onSettingsAndMatrixReady = function() {
if ( !settingsReady || !matrixReady ) {
return;
}
if ( µm.userSettings.hasOwnProperty('spoofUserAgent') === false ) {
return;
}
var saveMatrix = false;
if ( µm.userSettings.spoofUserAgent ) {
µm.tMatrix.setSwitch('ua-spoof', '*', 1);
µm.pMatrix.setSwitch('ua-spoof', '*', 1);
saveMatrix = true;
}
if ( µm.userSettings.processReferer ) {
µm.tMatrix.setSwitch('referrer-spoof', '*', 1);
µm.pMatrix.setSwitch('referrer-spoof', '*', 1);
saveMatrix = true;
}
if ( saveMatrix ) {
µm.saveMatrix();
}
delete µm.userSettings.processReferer;
delete µm.userSettings.spoofUserAgent;
µm.saveUserSettings();
};

43
src/js/traffic.js

@ -467,13 +467,10 @@ var onBeforeSendHeadersHandler = function(details) {
changed = foilCookieHeaders(µm, details) || changed;
}
// TODO: use cookie cell to determine whether the referrer info must be
// foiled.
if ( µm.userSettings.processReferer && µm.mustBlock(pageStore.pageHostname, reqHostname, '*') ) {
if ( µm.tMatrix.evaluateSwitchZ('referrer-spoof', pageStore.pageHostname) ) {
changed = foilRefererHeaders(µm, reqHostname, details) || changed;
}
// TODO: move the master ua-spoofing switch into the matrix.
if ( µm.tMatrix.evaluateSwitchZ('ua-spoof', pageStore.pageHostname) ) {
changed = foilUserAgent(µm, details) || changed;
// https://github.com/gorhill/httpswitchboard/issues/252
@ -559,29 +556,29 @@ var foilCookieHeaders = function(µm, details) {
var foilRefererHeaders = function(µm, toHostname, details) {
var headers = details.requestHeaders;
var header;
var fromDomain, toDomain;
var i = headers.length;
var i = headers.length, header;
while ( i-- ) {
header = headers[i];
if ( header.name.toLowerCase() !== 'referer' ) {
continue;
}
fromDomain = µm.URI.domainFromURI(header.value);
if ( !toDomain ) {
toDomain = µm.URI.domainFromHostname(toHostname);
}
if ( toDomain === fromDomain ) {
continue;
if ( header.name.toLowerCase() === 'referer' ) {
break;
}
// console.debug('foilRefererHeaders()> foiled referer "%s" for "%s"', fromDomain, toDomain);
// https://github.com/gorhill/httpswitchboard/issues/222#issuecomment-44828402
// Splicing instead of blanking: not sure how much it helps
headers.splice(i, 1);
µm.refererHeaderFoiledCounter++;
return true;
}
return false;
if ( i === -1 ) {
return false;
}
var µmuri = µm.URI;
var fromDomain = µmuri.domainFromURI(header.value);
var toDomain = µmuri.domainFromHostname(toHostname);
if ( toDomain === fromDomain ) {
return false;
}
//console.debug('foilRefererHeaders()> foiled referer for "%s"', details.url);
//console.debug('\treferrer "%s"', header.value);
// https://github.com/gorhill/httpswitchboard/issues/222#issuecomment-44828402
header.value = µmuri.schemeFromURI(details.url) + '://' + toHostname + '/';
//console.debug('\treplaced with "%s"', header.value);
µm.refererHeaderFoiledCounter++;
return true;
};
/******************************************************************************/

1
src/popup.html

@ -35,6 +35,7 @@
<ul id="mtxSwitches">
<li id="mtxSwitch_https-strict" class="dropdown-menu-entry"><span data-i18n="matrixSwitchNoMixedContent"></span>
<li id="mtxSwitch_ua-spoof" class="dropdown-menu-entry"><span data-i18n="matrixSwitchUASpoof"></span>
<li id="mtxSwitch_referrer-spoof" class="dropdown-menu-entry"><span data-i18n="matrixSwitchReferrerSpoof"></span>
</ul>
</div>
<div class="dropdown-menu-capture"></div>

2
src/privacy.html

@ -80,7 +80,7 @@ html.rtl #spoof-user-agent-with {
<button class="whatisthis"></button>
<div class="whatisthis-expandable para" data-i18n="privacyClearCacheHelp"></div>
<li>
<input id="process-referer" type="checkbox" data-setting-bool="processReferer"><label data-i18n="privacyProcessRefererPrompt" for="process-referer"></label>
<input id="process-referer" type="checkbox" data-matrix-switch="referrer-spoof"><label data-i18n="privacyProcessRefererPrompt" for="process-referer"></label>
<button class="whatisthis"></button>
<div class="whatisthis-expandable para" data-i18n="privacyProcessRefererHelp"></div>
<li>

6
tools/_locales/en/messages.json

@ -115,6 +115,10 @@
"message": "User agent spoofing",
"description": ""
},
"matrixSwitchReferrerSpoof" : {
"message": "Referrer spoofing",
"description": ""
},
"statsPageTitle" : {
@ -342,7 +346,7 @@
"description": ""
},
"privacyProcessRefererPrompt" : {
"message": "Remove third-party <a href='https://en.wikipedia.org/wiki/HTTP_referer'>HTTP referer</a> information from requests to non-whitelisted hostnames.",
"message": "Spoof <a href='https://en.wikipedia.org/wiki/HTTP_referer'>HTTP referrer</a> string of third-party requests.",
"description": ""
},
"privacyProcessRefererHelp" : {

Loading…
Cancel
Save