[xss] Refactor for non-persistence.
This commit is contained in:
parent
f89578297d
commit
fd58217c59
|
@ -188,12 +188,6 @@ var Settings = {
|
||||||
|
|
||||||
if (xssUserChoices) await XSS.saveUserChoices(xssUserChoices);
|
if (xssUserChoices) await XSS.saveUserChoices(xssUserChoices);
|
||||||
|
|
||||||
if (ns.sync.xss) {
|
|
||||||
XSS.start();
|
|
||||||
} else {
|
|
||||||
XSS.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reloadOptionsUI) await this.reloadOptionsUI();
|
if (reloadOptionsUI) await this.reloadOptionsUI();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -89,12 +89,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
await RequestGuard.start();
|
await RequestGuard.start();
|
||||||
await XSS.start(); // we must start it anyway to initialize sub-objects
|
|
||||||
if (!ns.sync.xss) {
|
|
||||||
XSS.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Messages.send("started");
|
await Messages.send("started");
|
||||||
|
|
|
@ -24,13 +24,6 @@ XSS.Exceptions = (() => {
|
||||||
|
|
||||||
var Exceptions = {
|
var Exceptions = {
|
||||||
|
|
||||||
async getWhitelist() {
|
|
||||||
return (await Storage.get("sync", "xssWhitelist")).xssWhitelist;
|
|
||||||
},
|
|
||||||
async setWhitelist(xssWhitelist) {
|
|
||||||
await Storage.set("sync", {xssWhitelist});
|
|
||||||
},
|
|
||||||
|
|
||||||
async shouldIgnore(xssReq) {
|
async shouldIgnore(xssReq) {
|
||||||
function logEx(...args) {
|
function logEx(...args) {
|
||||||
debug("[XSS preprocessing] Ignoring %o", xssReq, ...args);
|
debug("[XSS preprocessing] Ignoring %o", xssReq, ...args);
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
|
|
||||||
var XSS = (() => {
|
var XSS = (() => {
|
||||||
|
|
||||||
|
let initializing;
|
||||||
|
|
||||||
const ABORT = {cancel: true}, ALLOW = {};
|
const ABORT = {cancel: true}, ALLOW = {};
|
||||||
|
|
||||||
let baseTTL = 20000; // timeout in milliseconds for each worker to perform
|
let baseTTL = 20000; // timeout in milliseconds for each worker to perform
|
||||||
|
@ -78,6 +80,8 @@ var XSS = (() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function requestListener(request) {
|
async function requestListener(request) {
|
||||||
|
await initializing; // depends also on ns.initializing
|
||||||
|
if (!ns.sync.xss) return;
|
||||||
|
|
||||||
{
|
{
|
||||||
let {type} = request;
|
let {type} = request;
|
||||||
|
@ -88,8 +92,10 @@ var XSS = (() => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let xssReq = XSS.parseRequest(request);
|
let xssReq = XSS.parseRequest(request);
|
||||||
if (!xssReq) return null;
|
if (!xssReq) return null;
|
||||||
|
|
||||||
let userResponse = await getUserResponse(xssReq);
|
let userResponse = await getUserResponse(xssReq);
|
||||||
if (userResponse) return userResponse;
|
if (userResponse) return userResponse;
|
||||||
|
|
||||||
|
@ -190,49 +196,31 @@ var XSS = (() => {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
if (UA.isMozilla) {
|
||||||
async start() {
|
// async webRequest is supported on Mozilla only
|
||||||
if (!UA.isMozilla) return; // async webRequest is supported on Mozilla only
|
const {onBeforeRequest, onCompleted, onErrorOccurred} = browser.webRequest;
|
||||||
|
const filter = {
|
||||||
let {onBeforeRequest, onCompleted, onErrorOccurred} = browser.webRequest;
|
urls: ["*://*/*"],
|
||||||
|
types: ["main_frame", "sub_frame", "object"]
|
||||||
if (onBeforeRequest.hasListener(requestListener)) return;
|
};
|
||||||
|
|
||||||
|
initializing = (async () => {
|
||||||
await include([
|
await include([
|
||||||
"/nscl/common/AsyncRegExp.js",
|
"/nscl/common/AsyncRegExp.js",
|
||||||
"/xss/Exceptions.js"
|
"/xss/Exceptions.js"
|
||||||
]);
|
]);
|
||||||
|
|
||||||
this._userChoices = (await Storage.get("sync", "xssUserChoices")).xssUserChoices || {};
|
XSS._userChoices = (await Storage.get("sync", "xssUserChoices")).xssUserChoices || {};
|
||||||
|
await ns.initializing;
|
||||||
|
})();
|
||||||
|
|
||||||
// convert old style whitelist if stored
|
|
||||||
let oldWhitelist = await XSS.Exceptions.getWhitelist();
|
|
||||||
if (oldWhitelist) {
|
|
||||||
for (let [destOrigin, sources] of Object.entries(oldWhitelist)) {
|
|
||||||
for (let srcOrigin of sources) {
|
|
||||||
this._userChoices[`${srcOrigin}>${destOrigin}`] = "allow";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
XSS.Exceptions.setWhitelist(null);
|
|
||||||
}
|
|
||||||
let filter = {
|
|
||||||
urls: ["*://*/*"],
|
|
||||||
types: ["main_frame", "sub_frame", "object"]
|
|
||||||
};
|
|
||||||
onBeforeRequest.addListener(requestListener, filter, ["blocking", "requestBody"]);
|
onBeforeRequest.addListener(requestListener, filter, ["blocking", "requestBody"]);
|
||||||
if (!onCompleted.hasListener(doneListener)) {
|
|
||||||
onCompleted.addListener(doneListener, filter);
|
onCompleted.addListener(doneListener, filter);
|
||||||
onErrorOccurred.addListener(doneListener, filter);
|
onErrorOccurred.addListener(doneListener, filter);
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
stop() {
|
|
||||||
let {onBeforeRequest} = browser.webRequest;
|
|
||||||
if (onBeforeRequest.hasListener(requestListener)) {
|
|
||||||
onBeforeRequest.removeListener(requestListener);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
|
return {
|
||||||
parseRequest(request) {
|
parseRequest(request) {
|
||||||
let {
|
let {
|
||||||
requestId,
|
requestId,
|
||||||
|
|
Loading…
Reference in New Issue