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

Commit

Permalink
Revive formerly removed <noscript> tag spoofing code
Browse files Browse the repository at this point in the history
Also:
- a new per-scope switch has been added to control <noscript> spoofing on
  a per site basis
- a global setting to be used as the default state of the <noscript>
  spoofing switch
- Privacy pane has been merged into Setting pane
  • Loading branch information
gorhill committed Dec 1, 2017
1 parent b5d94c7 commit 9d43f92
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 336 deletions.
8 changes: 8 additions & 0 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@
"message": "Referrer spoofing",
"description": "A menu entry in the matrix popup"
},
"matrixSwitchNoscriptSpoof" : {
"message": "<code><noscript></code> tags spoofing",
"description": "A menu entry in the matrix popup"
},
"matrixRevertAllEntry" : {
"message": "Revert all temporary changes",
"description": "A menu entry in the matrix popup"
Expand Down Expand Up @@ -338,6 +342,10 @@
"message": "Collapse placeholder of blocked elements",
"description": "English: Collapse placeholder of blocked elements"
},
"settingsNoscriptTagsSpoofed" : {
"message": "Spoof <code><noscript></code> tags when 1st-party scripts are blocked",
"description": "This appears in the Settings pane in the dashboard"
},
"settingsCloudStorageEnabled" : {
"message": "Enable cloud storage support",
"description": ""
Expand Down
3 changes: 3 additions & 0 deletions src/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,6 @@ button.custom[disabled] {
opacity: 0.6;
pointer-events: none;
}
code {
font-size: 90%;
}
1 change: 0 additions & 1 deletion src/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
<div id="dashboard-nav-widgets">
<span>uMatrix</span>
<a class="tabButton" id="settings" href="#settings" data-dashboard-panel-url="settings.html" data-i18n="settingsPageName"></a>
<a class="tabButton" id="privacy" href="#privacy" data-dashboard-panel-url="privacy.html" data-i18n="privacyPageName"></a>
<a class="tabButton" id="user-rules" href="#user-rules" data-dashboard-panel-url="user-rules.html" data-i18n="userRulesPageName"></a>
<a class="tabButton" id="hosts-files" href="#hosts-files" data-dashboard-panel-url="hosts-files.html" data-i18n="ubiquitousRulesPageName"></a>
<a class="tabButton" id="about" href="#about" data-dashboard-panel-url="about.html" data-i18n="aboutPageName"></a>
Expand Down
25 changes: 25 additions & 0 deletions src/js/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,31 @@ var nodeListsAddedHandler = function(nodeLists) {
/******************************************************************************/
/******************************************************************************/

// Executed only once.

(function() {
var noscripts = document.querySelectorAll('noscript');
if ( noscripts.length === 0 ) { return; }

var renderNoscriptTags = function(response) {
if ( response !== true ) { return; }

var parent, span;
for ( var noscript of noscripts ) {
parent = noscript.parentNode;
if ( parent === null ) { continue; }
span = document.createElement('span');
span.innerHTML = noscript.textContent;
parent.replaceChild(span, noscript);
}
};

localMessager.send({ what: 'mustRenderNoscriptTags?' }, renderNoscriptTags);
})();

/******************************************************************************/
/******************************************************************************/

localMessager.send({ what: 'shutdown?' }, function(response) {
if ( response === true ) {
vAPI.shutdown.exec();
Expand Down
3 changes: 2 additions & 1 deletion src/js/matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ var switchBitOffsets = new Map([
[ 'matrix-off', 0 ],
[ 'https-strict', 2 ],
/* 4 is now unused, formerly assigned to UA spoofing */
[ 'referrer-spoof', 6 ]
[ 'referrer-spoof', 6 ],
[ 'noscript-spoof', 8 ]
]);

var switchStateToNameMap = new Map([
Expand Down
105 changes: 24 additions & 81 deletions src/js/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,14 @@ function onMessage(request, sender, callback) {
break;

case 'getUserSettings':
response = µm.userSettings;
response = {
userSettings: µm.userSettings,
matrixSwitches: {
'https-strict': µm.pMatrix.evaluateSwitch('https-strict', '*') === 1,
'referrer-spoof': µm.pMatrix.evaluateSwitch('referrer-spoof', '*') === 1,
'noscript-spoof': µm.pMatrix.evaluateSwitch('noscript-spoof', '*') === 1
}
};
break;

case 'gotoExtensionURL':
Expand All @@ -86,6 +93,13 @@ function onMessage(request, sender, callback) {
µm.reloadHostsFiles();
break;

case 'setMatrixSwitch':
µm.tMatrix.setSwitch(request.switchName, '*', request.state);
if ( µm.pMatrix.setSwitch(request.switchName, '*', request.state) ) {
µm.saveMatrix();
}
break;

case 'userSettings':
if ( request.hasOwnProperty('value') === false ) {
request.value = undefined;
Expand Down Expand Up @@ -519,6 +533,7 @@ var onMessage = function(request, sender, callback) {
}

var tabId = sender && sender.tab ? sender.tab.id || 0 : 0;
var tabContext = µm.tabContextManager.lookup(tabId);

// Sync
var response;
Expand All @@ -536,8 +551,15 @@ var onMessage = function(request, sender, callback) {
response = evaluateURLs(tabId, request.requests);
break;

case 'mustRenderNoscriptTags?':
if ( tabContext !== null ) {
response =
µm.tMatrix.mustBlock(tabContext.rootHostname, tabContext.rootHostname, 'script') &&
µm.tMatrix.evaluateSwitchZ('noscript-spoof', tabContext.rootHostname);
}
break;

case 'shutdown?':
var tabContext = µm.tabContextManager.lookup(tabId);
if ( tabContext !== null ) {
response = µm.tMatrix.evaluateSwitchZ('matrix-off', tabContext.rootHostname);
}
Expand Down Expand Up @@ -619,85 +641,6 @@ vAPI.messaging.listen('cloud-ui.js', onMessage);
/******************************************************************************/
/******************************************************************************/

// settings.js

(function() {

var onMessage = function(request, sender, callback) {
var µm = µMatrix;

// Async
switch ( request.what ) {
default:
break;
}

// Sync
var response;

switch ( request.what ) {
default:
return vAPI.messaging.UNHANDLED;
}

callback(response);
};

vAPI.messaging.listen('settings.js', onMessage);

})();

/******************************************************************************/
/******************************************************************************/

// privacy.js

(function() {

var onMessage = function(request, sender, callback) {
var µm = µMatrix;

// Async
switch ( request.what ) {
default:
break;
}

// Sync
var response;

switch ( request.what ) {
case 'getPrivacySettings':
response = {
userSettings: µm.userSettings,
matrixSwitches: {
'https-strict': µm.pMatrix.evaluateSwitch('https-strict', '*') === 1,
'referrer-spoof': µm.pMatrix.evaluateSwitch('referrer-spoof', '*') === 1
}
};
break;

case 'setMatrixSwitch':
µm.tMatrix.setSwitch(request.switchName, '*', request.state);
if ( µm.pMatrix.setSwitch(request.switchName, '*', request.state) ) {
µm.saveMatrix();
}
break;

default:
return vAPI.messaging.UNHANDLED;
}

callback(response);
};

vAPI.messaging.listen('privacy.js', onMessage);

})();

/******************************************************************************/
/******************************************************************************/

// user-rules.js

(function() {
Expand Down
142 changes: 0 additions & 142 deletions src/js/privacy.js

This file was deleted.

Loading

0 comments on commit 9d43f92

Please sign in to comment.