Skip to content

Commit fd58217

Browse files
committed
[xss] Refactor for non-persistence.
1 parent f895782 commit fd58217

File tree

4 files changed

+22
-53
lines changed

4 files changed

+22
-53
lines changed

src/bg/Settings.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,6 @@ var Settings = {
188188

189189
if (xssUserChoices) await XSS.saveUserChoices(xssUserChoices);
190190

191-
if (ns.sync.xss) {
192-
XSS.start();
193-
} else {
194-
XSS.stop();
195-
}
196-
197191
if (reloadOptionsUI) await this.reloadOptionsUI();
198192
},
199193

src/bg/main.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,6 @@
8989
}
9090

9191
await RequestGuard.start();
92-
await XSS.start(); // we must start it anyway to initialize sub-objects
93-
if (!ns.sync.xss) {
94-
XSS.stop();
95-
}
96-
97-
9892

9993
try {
10094
await Messages.send("started");

src/xss/Exceptions.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ XSS.Exceptions = (() => {
2424

2525
var Exceptions = {
2626

27-
async getWhitelist() {
28-
return (await Storage.get("sync", "xssWhitelist")).xssWhitelist;
29-
},
30-
async setWhitelist(xssWhitelist) {
31-
await Storage.set("sync", {xssWhitelist});
32-
},
33-
3427
async shouldIgnore(xssReq) {
3528
function logEx(...args) {
3629
debug("[XSS preprocessing] Ignoring %o", xssReq, ...args);

src/xss/XSS.js

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
var XSS = (() => {
2424

25+
let initializing;
26+
2527
const ABORT = {cancel: true}, ALLOW = {};
2628

2729
let baseTTL = 20000; // timeout in milliseconds for each worker to perform
@@ -78,6 +80,8 @@ var XSS = (() => {
7880
}
7981

8082
async function requestListener(request) {
83+
await initializing; // depends also on ns.initializing
84+
if (!ns.sync.xss) return;
8185

8286
{
8387
let {type} = request;
@@ -88,8 +92,10 @@ var XSS = (() => {
8892
}
8993
}
9094
}
95+
9196
let xssReq = XSS.parseRequest(request);
9297
if (!xssReq) return null;
98+
9399
let userResponse = await getUserResponse(xssReq);
94100
if (userResponse) return userResponse;
95101

@@ -190,49 +196,31 @@ var XSS = (() => {
190196
};
191197
}
192198

193-
return {
194-
async start() {
195-
if (!UA.isMozilla) return; // async webRequest is supported on Mozilla only
196-
197-
let {onBeforeRequest, onCompleted, onErrorOccurred} = browser.webRequest;
198-
199-
if (onBeforeRequest.hasListener(requestListener)) return;
199+
if (UA.isMozilla) {
200+
// async webRequest is supported on Mozilla only
201+
const {onBeforeRequest, onCompleted, onErrorOccurred} = browser.webRequest;
202+
const filter = {
203+
urls: ["*://*/*"],
204+
types: ["main_frame", "sub_frame", "object"]
205+
};
200206

207+
initializing = (async () => {
201208
await include([
202209
"/nscl/common/AsyncRegExp.js",
203210
"/xss/Exceptions.js"
204211
]);
205212

206-
this._userChoices = (await Storage.get("sync", "xssUserChoices")).xssUserChoices || {};
213+
XSS._userChoices = (await Storage.get("sync", "xssUserChoices")).xssUserChoices || {};
214+
await ns.initializing;
215+
})();
207216

208-
// convert old style whitelist if stored
209-
let oldWhitelist = await XSS.Exceptions.getWhitelist();
210-
if (oldWhitelist) {
211-
for (let [destOrigin, sources] of Object.entries(oldWhitelist)) {
212-
for (let srcOrigin of sources) {
213-
this._userChoices[`${srcOrigin}>${destOrigin}`] = "allow";
214-
}
215-
}
216-
XSS.Exceptions.setWhitelist(null);
217-
}
218-
let filter = {
219-
urls: ["*://*/*"],
220-
types: ["main_frame", "sub_frame", "object"]
221-
};
222-
onBeforeRequest.addListener(requestListener, filter, ["blocking", "requestBody"]);
223-
if (!onCompleted.hasListener(doneListener)) {
224-
onCompleted.addListener(doneListener, filter);
225-
onErrorOccurred.addListener(doneListener, filter);
226-
}
227-
},
217+
onBeforeRequest.addListener(requestListener, filter, ["blocking", "requestBody"]);
218+
onCompleted.addListener(doneListener, filter);
219+
onErrorOccurred.addListener(doneListener, filter);
220+
}
228221

229-
stop() {
230-
let {onBeforeRequest} = browser.webRequest;
231-
if (onBeforeRequest.hasListener(requestListener)) {
232-
onBeforeRequest.removeListener(requestListener);
233-
}
234-
},
235222

223+
return {
236224
parseRequest(request) {
237225
let {
238226
requestId,

0 commit comments

Comments
 (0)