2018-10-09 08:14:50 +02:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
(function(){
|
|
|
|
"use strict";
|
|
|
|
|
2019-11-28 01:26:35 +01:00
|
|
|
let scope;
|
2018-10-09 08:14:50 +02:00
|
|
|
if ((typeof exports) !== "undefined"){
|
|
|
|
scope = exports;
|
|
|
|
}
|
|
|
|
else {
|
2019-03-12 22:24:23 +01:00
|
|
|
scope = require.register("./sanitationRules", {});
|
2018-10-09 08:14:50 +02:00
|
|
|
}
|
|
|
|
|
2019-04-09 08:29:52 +02:00
|
|
|
const extension = require("../lib/extension");
|
2019-04-08 00:02:29 +02:00
|
|
|
const settings = require("../lib/settings");
|
2018-10-09 08:14:50 +02:00
|
|
|
|
|
|
|
scope.ruleset = [
|
|
|
|
{
|
|
|
|
name: "unnecessaryURLValue",
|
|
|
|
check: function(errorCallback){
|
|
|
|
const {url: urlContainer} = settings.getContainers();
|
|
|
|
const containerValue = urlContainer.get();
|
2019-04-09 08:29:52 +02:00
|
|
|
const errorMessage = extension.getTranslation("sanitation_error.unnecessaryURLValue");
|
2018-10-09 08:14:50 +02:00
|
|
|
function createErrorMessage(setting, urlValue){
|
|
|
|
return errorMessage
|
|
|
|
.replace(/{setting-technical}/g, setting.name)
|
2019-04-09 08:29:52 +02:00
|
|
|
.replace(/{setting-title}/g, extension.getTranslation(setting.name + "_title"))
|
2018-10-09 08:14:50 +02:00
|
|
|
.replace(/{url}/g, urlValue.url);
|
|
|
|
}
|
|
|
|
containerValue.forEach(function(urlValues){
|
|
|
|
Object.keys(urlValues).filter(function(key){
|
|
|
|
return key !== "url";
|
|
|
|
}).forEach(function(key){
|
|
|
|
const setting = settings.getDefinition(key);
|
|
|
|
if (setting && setting.urlSpecific){
|
|
|
|
const globalValue = setting.get();
|
|
|
|
if (urlValues[key] === globalValue){
|
|
|
|
errorCallback({
|
|
|
|
message: createErrorMessage(setting, urlValues),
|
|
|
|
severity: "low",
|
|
|
|
resolutions: [{
|
2019-04-09 08:29:52 +02:00
|
|
|
label: extension.getTranslation("sanitation_resolution.removeURLValue"),
|
2018-10-09 08:14:50 +02:00
|
|
|
callback: function(){
|
|
|
|
setting.reset(urlValues.url);
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "disabledFeatures",
|
|
|
|
check: function(errorCallback){
|
2019-04-09 08:29:52 +02:00
|
|
|
const errorMessage = extension.getTranslation("sanitation_error.disabledFeatures");
|
2018-10-09 08:14:50 +02:00
|
|
|
function createErrorMessage(api){
|
2019-04-09 08:29:52 +02:00
|
|
|
return errorMessage.replace(/{api}/g, extension.getTranslation("section_" + api.section));
|
2018-10-09 08:14:50 +02:00
|
|
|
}
|
|
|
|
const protectedFeatures = settings.getDefinition("protectedAPIFeatures");
|
|
|
|
const protectedFeaturesValue = protectedFeatures.get();
|
|
|
|
function getSectionKeys(section){
|
|
|
|
let inSection = false;
|
|
|
|
return protectedFeatures.keys.filter(function(key){
|
|
|
|
if (typeof key === "string"){
|
|
|
|
return inSection;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (key.level === 1){
|
|
|
|
inSection = key.name === section;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
[
|
2019-11-08 08:44:20 +01:00
|
|
|
{mainFlag: "protectedCanvasPart", mainFlagDisabledValue: "nothing", section: "Canvas-API"},
|
2018-10-09 08:14:50 +02:00
|
|
|
{mainFlag: "protectAudio", section: "Audio-API"},
|
|
|
|
{mainFlag: "protectWindow", section: "Window-API"},
|
|
|
|
{mainFlag: "protectDOMRect", section: "DOMRect-API"},
|
2019-11-08 08:44:20 +01:00
|
|
|
{mainFlag: "protectNavigator", section: "Navigator-API"},
|
2019-11-11 23:00:39 +01:00
|
|
|
{mainFlag: "protectScreen", section: "Screen-API"},
|
2018-10-09 08:14:50 +02:00
|
|
|
].forEach(function(api){
|
2019-11-08 08:44:20 +01:00
|
|
|
if (settings.get(api.mainFlag) !== (api.mainFlagDisabledValue || false)){
|
2018-10-09 08:14:50 +02:00
|
|
|
if (getSectionKeys(api.section).every(function(key){
|
|
|
|
return protectedFeaturesValue.hasOwnProperty(key) &&
|
|
|
|
!protectedFeaturesValue[key];
|
|
|
|
})){
|
|
|
|
errorCallback({
|
|
|
|
message: createErrorMessage(api),
|
|
|
|
severity: "high",
|
|
|
|
resolutions: [
|
|
|
|
{
|
2019-04-09 08:29:52 +02:00
|
|
|
label: extension.getTranslation("sanitation_resolution.enableFeatures"),
|
2018-10-09 08:14:50 +02:00
|
|
|
callback: function(){
|
|
|
|
const protectedFeaturesValue = protectedFeatures.get();
|
|
|
|
getSectionKeys(api.section).forEach(function(key){
|
|
|
|
protectedFeaturesValue[key] = true;
|
|
|
|
});
|
|
|
|
protectedFeatures.set(protectedFeaturesValue);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2019-04-09 08:29:52 +02:00
|
|
|
label: extension.getTranslation("sanitation_resolution.disableMainFlag"),
|
2018-10-09 08:14:50 +02:00
|
|
|
callback: function(){
|
2019-11-08 08:44:20 +01:00
|
|
|
settings.set(api.mainFlag, api.mainFlagDisabledValue || false);
|
2018-10-09 08:14:50 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "blockMode",
|
|
|
|
check: function(errorCallback){
|
|
|
|
const blockMode = settings.blockMode;
|
2018-10-23 08:26:23 +02:00
|
|
|
const protectedCanvasPart = settings.protectedCanvasPart;
|
2018-10-09 08:14:50 +02:00
|
|
|
if (!blockMode.match("^fake|^ask")){
|
|
|
|
errorCallback({
|
2019-04-09 08:29:52 +02:00
|
|
|
message: extension.getTranslation("sanitation_error.badBlockMode"),
|
2018-10-09 08:14:50 +02:00
|
|
|
severity: "medium",
|
2018-10-23 08:26:23 +02:00
|
|
|
resolutions: [{
|
2019-04-09 08:29:52 +02:00
|
|
|
label: extension.getTranslation("sanitation_resolution.switchToFake"),
|
2018-10-23 08:26:23 +02:00
|
|
|
callback: function(){
|
|
|
|
settings.blockMode = "fake";
|
|
|
|
}
|
|
|
|
}]
|
2018-10-09 08:14:50 +02:00
|
|
|
});
|
|
|
|
}
|
2018-10-23 08:26:23 +02:00
|
|
|
if (blockMode === "fake" && protectedCanvasPart === "input" && settings.rng === "white"){
|
2018-10-09 08:14:50 +02:00
|
|
|
errorCallback({
|
2019-04-09 08:29:52 +02:00
|
|
|
message: extension.getTranslation("sanitation_error.fakeInputWithWhiteRng")
|
|
|
|
.replace(/{blockMode}/g, extension.getTranslation("blockMode_options." + blockMode))
|
2018-10-23 08:26:23 +02:00
|
|
|
.replace(
|
|
|
|
/{protectedCanvasPart}/g,
|
2019-04-09 08:29:52 +02:00
|
|
|
extension.getTranslation("protectedCanvasPart_options." + settings.protectedCanvasPart)
|
2018-10-23 08:26:23 +02:00
|
|
|
),
|
2018-10-09 08:14:50 +02:00
|
|
|
severity: "low",
|
2018-10-23 08:26:23 +02:00
|
|
|
resolutions: [
|
|
|
|
{
|
2019-04-09 08:29:52 +02:00
|
|
|
label: extension.getTranslation("sanitation_resolution.switchToProtectReadout"),
|
2018-10-23 08:26:23 +02:00
|
|
|
callback: function(){
|
|
|
|
settings.protectedCanvasPart = "readout";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2019-04-09 08:29:52 +02:00
|
|
|
label: extension.getTranslation("sanitation_resolution.switchToNonPersistentRng"),
|
2018-10-23 08:26:23 +02:00
|
|
|
callback: function(){
|
|
|
|
settings.rng = "nonPersistent";
|
|
|
|
}
|
2018-10-09 08:14:50 +02:00
|
|
|
}
|
2018-10-23 08:26:23 +02:00
|
|
|
]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (blockMode === "fake" && protectedCanvasPart === "everything"){
|
|
|
|
errorCallback({
|
2019-04-09 08:29:52 +02:00
|
|
|
message: extension.getTranslation("sanitation_error.fakeEverythingInCanvas")
|
|
|
|
.replace(/{blockMode}/g, extension.getTranslation("blockMode_options." + blockMode))
|
2018-10-23 08:26:23 +02:00
|
|
|
.replace(
|
|
|
|
/{protectedCanvasPart}/g,
|
2019-04-09 08:29:52 +02:00
|
|
|
extension.getTranslation("protectedCanvasPart_options." + settings.protectedCanvasPart)
|
2018-10-23 08:26:23 +02:00
|
|
|
),
|
|
|
|
severity: "low",
|
|
|
|
resolutions: [
|
|
|
|
{
|
2019-04-09 08:29:52 +02:00
|
|
|
label: extension.getTranslation("sanitation_resolution.switchToProtectReadout"),
|
2018-10-23 08:26:23 +02:00
|
|
|
callback: function(){
|
|
|
|
settings.protectedCanvasPart = "readout";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2019-04-09 08:29:52 +02:00
|
|
|
label: extension.getTranslation("sanitation_resolution.switchToProtectInput"),
|
2018-10-23 08:26:23 +02:00
|
|
|
callback: function(){
|
|
|
|
settings.protectedCanvasPart = "input";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2018-10-09 08:14:50 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "thresholds",
|
|
|
|
check: function(errorCallback){
|
2019-04-09 08:29:52 +02:00
|
|
|
const setToLabel = extension.getTranslation("sanitation_resolution.setTo");
|
|
|
|
const tooLowLabel = extension.getTranslation("sanitation_error.valueTooLow");
|
|
|
|
const tooHighLabel = extension.getTranslation("sanitation_error.valueTooHigh");
|
2018-10-09 08:14:50 +02:00
|
|
|
if (settings.minFakeSize > 1e2){
|
|
|
|
errorCallback({
|
|
|
|
message: tooHighLabel
|
2019-04-09 08:29:52 +02:00
|
|
|
.replace(/{setting}/g, extension.getTranslation("minFakeSize_title"))
|
2018-10-09 08:14:50 +02:00
|
|
|
.replace(/{value}/g, "100"),
|
|
|
|
severity: "high",
|
|
|
|
resolutions: [{
|
|
|
|
label: setToLabel.replace(/{value}/g, "100"),
|
|
|
|
callback: function(){
|
|
|
|
settings.minFakeSize = 1e2;
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (settings.maxFakeSize !== 0 && settings.maxFakeSize < 1e6){
|
|
|
|
errorCallback({
|
|
|
|
message: tooLowLabel
|
2019-04-09 08:29:52 +02:00
|
|
|
.replace(/{setting}/g, extension.getTranslation("maxFakeSize_title"))
|
2018-10-09 08:14:50 +02:00
|
|
|
.replace(/{value}/g, "1 000 000"),
|
|
|
|
severity: "high",
|
|
|
|
resolutions: [{
|
|
|
|
label: setToLabel.replace(/{value}/g, "1 000 000"),
|
|
|
|
callback: function(){
|
|
|
|
settings.maxFakeSize = 1e6;
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (settings.ignoreFrequentColors > 3){
|
|
|
|
errorCallback({
|
|
|
|
message: tooHighLabel
|
2019-04-09 08:29:52 +02:00
|
|
|
.replace(/{setting}/g, extension.getTranslation("ignoreFrequentColors_title"))
|
2018-10-09 08:14:50 +02:00
|
|
|
.replace(/{value}/g, "3"),
|
|
|
|
severity: "high",
|
|
|
|
resolutions: [{
|
|
|
|
label: setToLabel.replace(/{value}/g, "3"),
|
|
|
|
callback: function(){
|
|
|
|
settings.ignoreFrequentColors = 3;
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (settings.minColors > 10){
|
|
|
|
errorCallback({
|
|
|
|
message: tooHighLabel
|
2019-04-09 08:29:52 +02:00
|
|
|
.replace(/{setting}/g, extension.getTranslation("minColors_title"))
|
2018-10-09 08:14:50 +02:00
|
|
|
.replace(/{value}/g, "10"),
|
|
|
|
severity: "high",
|
|
|
|
resolutions: [{
|
|
|
|
label: setToLabel.replace(/{value}/g, "10"),
|
|
|
|
callback: function(){
|
2018-10-09 13:06:55 +02:00
|
|
|
settings.minColors = 10;
|
2018-10-09 08:14:50 +02:00
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "performance",
|
|
|
|
check: function(errorCallback){
|
2019-04-09 08:29:52 +02:00
|
|
|
const disableLabel = extension.getTranslation("sanitation_resolution.disableFlag");
|
2018-10-09 08:14:50 +02:00
|
|
|
if (settings.storeNotificationData){
|
|
|
|
errorCallback({
|
2019-04-09 08:29:52 +02:00
|
|
|
message: extension.getTranslation("sanitation_error.storeNotificationData"),
|
2018-10-09 08:14:50 +02:00
|
|
|
severity: "low",
|
|
|
|
resolutions: [{
|
|
|
|
label: disableLabel
|
2019-04-09 08:29:52 +02:00
|
|
|
.replace(/{flag}/g, extension.getTranslation("storeNotificationData_title")),
|
2018-10-09 08:14:50 +02:00
|
|
|
callback: function(){
|
|
|
|
settings.storeNotificationData = false;
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
if (settings.storeImageForInspection){
|
|
|
|
errorCallback({
|
2019-04-09 08:29:52 +02:00
|
|
|
message: extension.getTranslation("sanitation_error.storeImage"),
|
2018-10-09 08:14:50 +02:00
|
|
|
severity: "low",
|
|
|
|
resolutions: [{
|
|
|
|
label: disableLabel
|
2019-04-09 08:29:52 +02:00
|
|
|
.replace(/{flag}/g, extension.getTranslation("storeImageForInspection_title")),
|
2018-10-09 08:14:50 +02:00
|
|
|
callback: function(){
|
|
|
|
settings.storeImageForInspection = false;
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2018-10-25 13:42:18 +02:00
|
|
|
{
|
|
|
|
name: "privacy",
|
|
|
|
check: function(errorCallback){
|
|
|
|
if (settings.sharePersistentRndBetweenDomains){
|
|
|
|
errorCallback({
|
2019-04-09 08:29:52 +02:00
|
|
|
message: extension.getTranslation("sanitation_error.doNotSharePersistentRndBetweenDomains"),
|
2018-10-25 13:42:18 +02:00
|
|
|
severity: "high",
|
|
|
|
resolutions: [{
|
2019-04-09 08:29:52 +02:00
|
|
|
label: extension.getTranslation("sanitation_resolution.disableFlag")
|
|
|
|
.replace(/{flag}/g, extension.getTranslation("sharePersistentRndBetweenDomains_title")),
|
2018-10-25 13:42:18 +02:00
|
|
|
callback: function(){
|
|
|
|
settings.sharePersistentRndBetweenDomains = false;
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
}
|
2019-11-11 23:00:39 +01:00
|
|
|
if (settings.protectScreen && settings.screenSize){
|
|
|
|
errorCallback({
|
|
|
|
message: extension.getTranslation("sanitation_error.customScreenSize"),
|
|
|
|
severity: "medium",
|
|
|
|
resolutions: [{
|
|
|
|
label: extension.getTranslation("sanitation_resolution.setTo")
|
|
|
|
.replace(/{value}/g, "\"\""),
|
|
|
|
callback: function(){
|
|
|
|
settings.screenSize = "";
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
}
|
2018-10-25 13:42:18 +02:00
|
|
|
}
|
|
|
|
},
|
2018-10-09 08:14:50 +02:00
|
|
|
];
|
|
|
|
}());
|