Skip to content
This repository has been archived by the owner on Jul 21, 2021. It is now read-only.

Commit

Permalink
this fixes #59
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Nov 20, 2014
1 parent 82642f1 commit 5d8bae3
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 32 deletions.
7 changes: 4 additions & 3 deletions src/js/matrix.js
Expand Up @@ -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 = {
Expand Down
1 change: 1 addition & 0 deletions src/js/messaging-handlers.js
Expand Up @@ -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;
Expand Down
15 changes: 11 additions & 4 deletions src/js/storage.js
Expand Up @@ -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();
};
Expand Down
43 changes: 20 additions & 23 deletions src/js/traffic.js
Expand Up @@ -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
Expand Down Expand Up @@ -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;
};

/******************************************************************************/
Expand Down
1 change: 1 addition & 0 deletions src/popup.html
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion src/privacy.html
Expand Up @@ -80,7 +80,7 @@
<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>
Expand Down
6 changes: 5 additions & 1 deletion tools/_locales/en/messages.json
Expand Up @@ -115,6 +115,10 @@
"message": "User agent spoofing",
"description": ""
},
"matrixSwitchReferrerSpoof" : {
"message": "Referrer spoofing",
"description": ""
},


"statsPageTitle" : {
Expand Down Expand Up @@ -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" : {
Expand Down

0 comments on commit 5d8bae3

Please sign in to comment.