2016-02-13 12:28:36 +01: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;
|
2017-06-25 22:22:17 +02:00
|
|
|
if ((typeof exports) !== "undefined"){
|
|
|
|
scope = exports;
|
|
|
|
}
|
|
|
|
else {
|
2019-03-12 22:24:23 +01:00
|
|
|
scope = require.register("./check", {});
|
2017-06-25 22:22:17 +02:00
|
|
|
}
|
|
|
|
|
2017-11-07 00:36:44 +01:00
|
|
|
const settings = require("./settings");
|
2016-02-13 12:28:36 +01:00
|
|
|
const lists = require("./lists");
|
|
|
|
const {parseErrorStack} = require("./callingStack");
|
2017-07-27 19:14:04 +02:00
|
|
|
const logging = require("./logging");
|
2016-02-13 12:28:36 +01:00
|
|
|
|
2017-06-25 22:22:17 +02:00
|
|
|
scope.check = function check({url, errorStack}){
|
2017-12-03 23:47:49 +01:00
|
|
|
url = new URL(url || "about:blank");
|
2019-11-28 01:26:35 +01:00
|
|
|
const match = checkBoth(errorStack, url, settings.get("blockMode", url)).match(
|
2018-10-23 08:26:23 +02:00
|
|
|
/^(block|allow|fake|ask)(|Everything|Internal)$/
|
2017-10-05 19:00:00 +02:00
|
|
|
);
|
2016-02-13 12:28:36 +01:00
|
|
|
if (match){
|
|
|
|
return {
|
2018-09-06 17:24:05 +02:00
|
|
|
url: url,
|
2018-10-23 08:26:23 +02:00
|
|
|
internal: match[2] === "Internal",
|
2016-02-13 12:28:36 +01:00
|
|
|
mode: match[1]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return {
|
2018-09-06 17:24:05 +02:00
|
|
|
url: url,
|
2018-10-23 08:26:23 +02:00
|
|
|
internal: false,
|
2016-02-13 12:28:36 +01:00
|
|
|
mode: "block"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-11-13 14:51:58 +01:00
|
|
|
function checkBoth(errorStack, url, blockMode){
|
2017-10-06 16:06:31 +02:00
|
|
|
if (settings.enableStackList && errorStack && checkStack(errorStack)){
|
2016-02-13 12:28:36 +01:00
|
|
|
return "allow";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return checkURL(url, blockMode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkURL(url, blockMode){
|
2017-07-27 19:14:04 +02:00
|
|
|
logging.message("check url %s for block mode %s", url, blockMode);
|
2016-02-13 12:28:36 +01:00
|
|
|
switch (url.protocol){
|
|
|
|
case "about:":
|
2023-04-19 14:34:37 +02:00
|
|
|
if (url.pathname === "blank"){
|
2017-07-27 19:14:04 +02:00
|
|
|
logging.message("use regular mode on about:blank");
|
2016-02-13 12:28:36 +01:00
|
|
|
break;
|
|
|
|
}
|
2017-07-27 19:14:04 +02:00
|
|
|
logging.message("allow internal URLs");
|
2016-11-13 14:51:58 +01:00
|
|
|
return "allowInternal";
|
2016-02-13 12:28:36 +01:00
|
|
|
case "chrome:":
|
2017-07-27 19:14:04 +02:00
|
|
|
logging.message("allow internal URLs");
|
2016-11-13 14:51:58 +01:00
|
|
|
return "allowInternal";
|
2016-02-13 12:28:36 +01:00
|
|
|
}
|
|
|
|
|
2019-11-28 01:26:35 +01:00
|
|
|
let mode = "block";
|
2016-02-13 12:28:36 +01:00
|
|
|
switch (blockMode){
|
|
|
|
case "blockEverything":
|
|
|
|
mode = "block";
|
|
|
|
break;
|
|
|
|
case "block":
|
|
|
|
case "ask":
|
|
|
|
case "fake":
|
|
|
|
case "allow":
|
|
|
|
if (url && lists.get("white").match(url)){
|
|
|
|
mode = "allow";
|
|
|
|
}
|
|
|
|
else if (url && lists.get("black").match(url)){
|
|
|
|
mode = "block";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mode = blockMode;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "allowEverything":
|
|
|
|
mode = "allow";
|
|
|
|
break;
|
|
|
|
default:
|
2017-07-27 19:14:04 +02:00
|
|
|
logging.warning("Unknown blocking mode (" + blockMode + "). Default to block everything.");
|
2016-02-13 12:28:36 +01:00
|
|
|
}
|
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
|
2016-11-13 14:51:58 +01:00
|
|
|
function checkStack(errorStack){
|
2019-05-10 00:29:53 +02:00
|
|
|
if (settings.enableStackList){
|
|
|
|
const stackList = lists.get("stack");
|
|
|
|
if (stackList.length){
|
|
|
|
const callingStack = parseErrorStack(errorStack);
|
|
|
|
return stackList.match(callingStack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2016-02-13 12:28:36 +01:00
|
|
|
}
|
2017-06-25 22:22:17 +02:00
|
|
|
scope.checkStack = checkStack;
|
2016-02-13 12:28:36 +01:00
|
|
|
}());
|