2012-07-28 10:25:11 +04: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/. */
|
|
|
|
|
2012-10-31 20:13:28 +04:00
|
|
|
var EXPORTED_SYMBOLS = ["SafeBrowsing"];
|
2012-07-28 10:25:11 +04:00
|
|
|
|
2019-01-17 21:18:31 +03:00
|
|
|
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
2012-07-28 10:25:11 +04:00
|
|
|
|
2017-07-04 11:36:31 +03:00
|
|
|
const PREF_DEBUG_ENABLED = "browser.safebrowsing.debug";
|
|
|
|
let loggingEnabled = false;
|
|
|
|
|
2015-09-17 10:59:26 +03:00
|
|
|
// Log only if browser.safebrowsing.debug is true
|
|
|
|
function log(...stuff) {
|
2017-07-04 11:36:31 +03:00
|
|
|
if (!loggingEnabled) {
|
2015-09-17 10:59:26 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var d = new Date();
|
|
|
|
let msg = "SafeBrowsing: " + d.toTimeString() + ": " + stuff.join(" ");
|
2016-04-29 08:53:31 +03:00
|
|
|
dump(Services.urlFormatter.trimSensitiveURLs(msg) + "\n");
|
2015-09-17 10:59:26 +03:00
|
|
|
}
|
|
|
|
|
2014-04-17 21:57:08 +04:00
|
|
|
function getLists(prefName) {
|
2015-09-08 09:22:10 +03:00
|
|
|
log("getLists: " + prefName);
|
2017-03-07 17:29:48 +03:00
|
|
|
let pref = Services.prefs.getCharPref(prefName, "");
|
|
|
|
|
2014-04-22 17:11:53 +04:00
|
|
|
// Splitting an empty string returns [''], we really want an empty array.
|
|
|
|
if (!pref) {
|
|
|
|
return [];
|
|
|
|
}
|
2017-03-07 17:29:48 +03:00
|
|
|
|
|
|
|
return pref.split(",").map(value => value.trim());
|
2014-04-17 21:57:08 +04:00
|
|
|
}
|
|
|
|
|
2019-01-15 23:04:40 +03:00
|
|
|
const FEATURES = [
|
|
|
|
{
|
|
|
|
name: "phishing",
|
|
|
|
list: ["urlclassifier.phishTable"],
|
|
|
|
enabled() {
|
|
|
|
return Services.prefs.getBoolPref(
|
|
|
|
"browser.safebrowsing.phishing.enabled"
|
|
|
|
);
|
|
|
|
},
|
2019-01-22 19:13:41 +03:00
|
|
|
update() {
|
|
|
|
return Services.prefs.getBoolPref(
|
|
|
|
"browser.safebrowsing.features.phishing.update",
|
|
|
|
this.enabled()
|
|
|
|
);
|
|
|
|
},
|
2019-01-15 23:04:40 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "malware",
|
|
|
|
list: ["urlclassifier.malwareTable"],
|
|
|
|
enabled() {
|
|
|
|
return Services.prefs.getBoolPref("browser.safebrowsing.malware.enabled");
|
|
|
|
},
|
2019-01-22 19:13:41 +03:00
|
|
|
update() {
|
|
|
|
return Services.prefs.getBoolPref(
|
|
|
|
"browser.safebrowsing.features.malware.update",
|
|
|
|
this.enabled()
|
|
|
|
);
|
|
|
|
},
|
2019-01-15 23:04:40 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "blockedURIs",
|
|
|
|
list: ["urlclassifier.blockedTable"],
|
|
|
|
enabled() {
|
|
|
|
return Services.prefs.getBoolPref(
|
|
|
|
"browser.safebrowsing.blockedURIs.enabled"
|
|
|
|
);
|
|
|
|
},
|
2019-01-22 19:13:41 +03:00
|
|
|
update() {
|
|
|
|
return Services.prefs.getBoolPref(
|
|
|
|
"browser.safebrowsing.features.blockedURIs.update",
|
|
|
|
this.enabled()
|
|
|
|
);
|
|
|
|
},
|
2019-01-15 23:04:40 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "passwords",
|
|
|
|
list: ["urlclassifier.passwordAllowTable"],
|
|
|
|
enabled() {
|
|
|
|
return Services.prefs.getBoolPref(
|
|
|
|
"browser.safebrowsing.passwords.enabled"
|
|
|
|
);
|
|
|
|
},
|
2019-01-22 19:13:41 +03:00
|
|
|
update() {
|
|
|
|
return Services.prefs.getBoolPref(
|
|
|
|
"browser.safebrowsing.features.passwords.update",
|
|
|
|
this.enabled()
|
|
|
|
);
|
|
|
|
},
|
2019-01-15 23:04:40 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "downloads",
|
|
|
|
list: [
|
|
|
|
"urlclassifier.downloadBlockTable",
|
|
|
|
"urlclassifier.downloadAllowTable",
|
|
|
|
],
|
|
|
|
enabled() {
|
|
|
|
return (
|
|
|
|
Services.prefs.getBoolPref("browser.safebrowsing.downloads.enabled") &&
|
|
|
|
Services.prefs.getBoolPref("browser.safebrowsing.malware.enabled")
|
|
|
|
);
|
|
|
|
},
|
2019-01-22 19:13:41 +03:00
|
|
|
update() {
|
|
|
|
return Services.prefs.getBoolPref(
|
|
|
|
"browser.safebrowsing.features.downloads.update",
|
|
|
|
this.enabled()
|
|
|
|
);
|
|
|
|
},
|
2019-01-15 23:04:40 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "trackingAnnotation",
|
|
|
|
list: [
|
|
|
|
"urlclassifier.trackingAnnotationTable",
|
|
|
|
"urlclassifier.trackingAnnotationWhitelistTable",
|
|
|
|
],
|
|
|
|
enabled() {
|
|
|
|
return Services.prefs.getBoolPref(
|
|
|
|
"privacy.trackingprotection.annotate_channels"
|
|
|
|
);
|
|
|
|
},
|
2019-01-22 19:13:41 +03:00
|
|
|
update() {
|
|
|
|
return Services.prefs.getBoolPref(
|
|
|
|
"browser.safebrowsing.features.trackingAnnotation.update",
|
|
|
|
this.enabled()
|
|
|
|
);
|
|
|
|
},
|
2019-01-15 23:04:40 +03:00
|
|
|
},
|
2019-01-22 19:13:41 +03:00
|
|
|
{
|
|
|
|
name: "trackingProtection",
|
2019-01-15 23:04:40 +03:00
|
|
|
list: [
|
|
|
|
"urlclassifier.trackingTable",
|
|
|
|
"urlclassifier.trackingWhitelistTable",
|
|
|
|
],
|
|
|
|
enabled() {
|
2019-02-06 10:23:39 +03:00
|
|
|
return (
|
|
|
|
Services.prefs.getBoolPref("privacy.trackingprotection.enabled") ||
|
2019-01-15 23:04:40 +03:00
|
|
|
Services.prefs.getBoolPref("privacy.trackingprotection.pbmode.enabled")
|
|
|
|
);
|
|
|
|
},
|
2019-01-22 19:13:41 +03:00
|
|
|
update() {
|
|
|
|
return Services.prefs.getBoolPref(
|
|
|
|
"browser.safebrowsing.features.trackingProtection.update",
|
|
|
|
this.enabled()
|
|
|
|
);
|
|
|
|
},
|
2019-01-15 23:04:40 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "flashBlock",
|
|
|
|
list: [
|
|
|
|
"urlclassifier.flashAllowTable",
|
|
|
|
"urlclassifier.flashAllowExceptTable",
|
|
|
|
"urlclassifier.flashTable",
|
|
|
|
"urlclassifier.flashExceptTable",
|
|
|
|
"urlclassifier.flashSubDocTable",
|
|
|
|
"urlclassifier.flashSubDocExceptTable",
|
|
|
|
],
|
|
|
|
enabled() {
|
|
|
|
return Services.prefs.getBoolPref("plugins.flashBlock.enabled");
|
|
|
|
},
|
2019-01-22 19:13:41 +03:00
|
|
|
update() {
|
|
|
|
return Services.prefs.getBoolPref(
|
|
|
|
"browser.safebrowsing.features.flashBlock.update",
|
|
|
|
this.enabled()
|
|
|
|
);
|
|
|
|
},
|
2019-01-15 23:04:40 +03:00
|
|
|
},
|
2019-03-14 20:48:33 +03:00
|
|
|
{
|
|
|
|
name: "fingerprinting-annotation",
|
|
|
|
list: [
|
|
|
|
"urlclassifier.features.fingerprinting.annotate.blacklistTables",
|
|
|
|
"urlclassifier.features.fingerprinting.annotate.whitelistTables",
|
|
|
|
],
|
|
|
|
enabled() {
|
2019-08-13 10:51:50 +03:00
|
|
|
// Annotation features are enabled by default.
|
2019-08-05 14:34:24 +03:00
|
|
|
return true;
|
2019-03-14 20:48:33 +03:00
|
|
|
},
|
|
|
|
update() {
|
|
|
|
return Services.prefs.getBoolPref(
|
|
|
|
"browser.safebrowsing.features.fingerprinting.annotate.update",
|
|
|
|
this.enabled()
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "fingerprinting-protection",
|
2019-01-15 22:29:49 +03:00
|
|
|
list: [
|
|
|
|
"urlclassifier.features.fingerprinting.blacklistTables",
|
|
|
|
"urlclassifier.features.fingerprinting.whitelistTables",
|
|
|
|
],
|
|
|
|
enabled() {
|
|
|
|
return Services.prefs.getBoolPref(
|
|
|
|
"privacy.trackingprotection.fingerprinting.enabled",
|
|
|
|
false
|
|
|
|
);
|
|
|
|
},
|
2019-01-22 19:13:41 +03:00
|
|
|
update() {
|
|
|
|
return Services.prefs.getBoolPref(
|
|
|
|
"browser.safebrowsing.features.fingerprinting.update",
|
|
|
|
this.enabled()
|
|
|
|
);
|
|
|
|
},
|
2019-01-15 22:29:49 +03:00
|
|
|
},
|
2019-03-14 20:48:33 +03:00
|
|
|
{
|
|
|
|
name: "cryptomining-annotation",
|
|
|
|
list: [
|
|
|
|
"urlclassifier.features.cryptomining.annotate.blacklistTables",
|
|
|
|
"urlclassifier.features.cryptomining.annotate.whitelistTables",
|
|
|
|
],
|
|
|
|
enabled() {
|
2019-08-13 10:51:50 +03:00
|
|
|
// Annotation features are enabled by default.
|
|
|
|
return true;
|
2019-03-14 20:48:33 +03:00
|
|
|
},
|
|
|
|
update() {
|
|
|
|
return Services.prefs.getBoolPref(
|
|
|
|
"browser.safebrowsing.features.cryptomining.annotate.update",
|
|
|
|
this.enabled()
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "cryptomining-protection",
|
2019-01-15 22:29:49 +03:00
|
|
|
list: [
|
|
|
|
"urlclassifier.features.cryptomining.blacklistTables",
|
|
|
|
"urlclassifier.features.cryptomining.whitelistTables",
|
|
|
|
],
|
|
|
|
enabled() {
|
|
|
|
return Services.prefs.getBoolPref(
|
|
|
|
"privacy.trackingprotection.cryptomining.enabled",
|
|
|
|
false
|
|
|
|
);
|
|
|
|
},
|
2019-01-22 19:13:41 +03:00
|
|
|
update() {
|
|
|
|
return Services.prefs.getBoolPref(
|
|
|
|
"browser.safebrowsing.features.cryptomining.update",
|
|
|
|
this.enabled()
|
|
|
|
);
|
|
|
|
},
|
2019-01-15 22:29:49 +03:00
|
|
|
},
|
2019-07-11 11:04:05 +03:00
|
|
|
{
|
|
|
|
name: "socialtracking-annotation",
|
|
|
|
list: [
|
|
|
|
"urlclassifier.features.socialtracking.annotate.blacklistTables",
|
|
|
|
"urlclassifier.features.socialtracking.annotate.whitelistTables",
|
|
|
|
],
|
|
|
|
enabled() {
|
2019-08-13 10:51:50 +03:00
|
|
|
// Annotation features are enabled by default.
|
2019-08-05 14:34:24 +03:00
|
|
|
return true;
|
2019-07-11 11:04:05 +03:00
|
|
|
},
|
|
|
|
update() {
|
|
|
|
return Services.prefs.getBoolPref(
|
|
|
|
"browser.safebrowsing.features.socialtracking.annotate.update",
|
|
|
|
this.enabled()
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "socialtracking-protection",
|
|
|
|
list: [
|
|
|
|
"urlclassifier.features.socialtracking.blacklistTables",
|
|
|
|
"urlclassifier.features.socialtracking.whitelistTables",
|
|
|
|
],
|
|
|
|
enabled() {
|
|
|
|
return Services.prefs.getBoolPref(
|
|
|
|
"privacy.trackingprotection.socialtracking.enabled",
|
|
|
|
false
|
|
|
|
);
|
|
|
|
},
|
|
|
|
update() {
|
|
|
|
return Services.prefs.getBoolPref(
|
|
|
|
"browser.safebrowsing.features.socialtracking.update",
|
|
|
|
this.enabled()
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
2016-07-19 03:53:21 +03:00
|
|
|
];
|
2012-07-28 10:25:11 +04:00
|
|
|
|
2012-10-31 20:13:28 +04:00
|
|
|
var SafeBrowsing = {
|
2017-08-02 18:12:07 +03:00
|
|
|
init() {
|
2012-07-28 10:25:11 +04:00
|
|
|
if (this.initialized) {
|
|
|
|
log("Already initialized");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-15 00:39:22 +03:00
|
|
|
Services.prefs.addObserver("browser.safebrowsing", this);
|
|
|
|
Services.prefs.addObserver("privacy.trackingprotection", this);
|
|
|
|
Services.prefs.addObserver("urlclassifier", this);
|
|
|
|
Services.prefs.addObserver("plugins.flashBlock.enabled", this);
|
2016-07-19 03:53:21 +03:00
|
|
|
|
2012-07-28 10:25:11 +04:00
|
|
|
this.readPrefs();
|
|
|
|
|
2015-09-08 09:22:10 +03:00
|
|
|
this.controlUpdateChecking();
|
|
|
|
this.initialized = true;
|
|
|
|
|
|
|
|
log("init() finished");
|
|
|
|
},
|
|
|
|
|
2017-08-02 18:12:07 +03:00
|
|
|
registerTableWithURLs(listname) {
|
2012-07-28 10:25:11 +04:00
|
|
|
let listManager = Cc[
|
|
|
|
"@mozilla.org/url-classifier/listmanager;1"
|
2015-09-08 09:22:10 +03:00
|
|
|
].getService(Ci.nsIUrlListManager);
|
|
|
|
|
|
|
|
let providerName = this.listToProvider[listname];
|
|
|
|
let provider = this.providers[providerName];
|
|
|
|
|
2016-06-01 21:37:00 +03:00
|
|
|
if (!providerName || !provider) {
|
|
|
|
log("No provider info found for " + listname);
|
|
|
|
log("Check browser.safebrowsing.provider.[google/mozilla].lists");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-25 10:20:44 +03:00
|
|
|
if (!provider.updateURL) {
|
|
|
|
log("Invalid update url " + listname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-06 14:53:07 +03:00
|
|
|
listManager.registerTable(
|
|
|
|
listname,
|
|
|
|
providerName,
|
|
|
|
provider.updateURL,
|
|
|
|
provider.gethashURL
|
|
|
|
);
|
2015-09-08 09:22:10 +03:00
|
|
|
},
|
|
|
|
|
2017-08-02 18:12:07 +03:00
|
|
|
registerTables() {
|
2019-01-15 23:04:40 +03:00
|
|
|
this.features.forEach(feature => {
|
|
|
|
feature.list.forEach(table => {
|
|
|
|
this.registerTableWithURLs(table);
|
|
|
|
});
|
|
|
|
});
|
2012-07-28 10:25:11 +04:00
|
|
|
},
|
|
|
|
|
2017-08-31 13:46:23 +03:00
|
|
|
unregisterTables(obsoleteLists) {
|
|
|
|
let listManager = Cc[
|
|
|
|
"@mozilla.org/url-classifier/listmanager;1"
|
|
|
|
].getService(Ci.nsIUrlListManager);
|
|
|
|
|
2019-01-15 23:04:40 +03:00
|
|
|
obsoleteLists.forEach(list => {
|
|
|
|
list.forEach(table => {
|
|
|
|
listManager.unregisterTable(table);
|
|
|
|
});
|
|
|
|
});
|
2017-08-31 13:46:23 +03:00
|
|
|
},
|
|
|
|
|
2016-12-01 07:12:00 +03:00
|
|
|
initialized: false,
|
2012-07-28 10:25:11 +04:00
|
|
|
|
2019-01-15 23:04:40 +03:00
|
|
|
features: [],
|
2016-07-19 03:53:21 +03:00
|
|
|
|
2012-07-28 10:25:11 +04:00
|
|
|
updateURL: null,
|
|
|
|
gethashURL: null,
|
2012-08-02 02:52:47 +04:00
|
|
|
reportURL: null,
|
2012-07-28 10:25:11 +04:00
|
|
|
|
2017-08-02 18:12:07 +03:00
|
|
|
getReportURL(kind, info) {
|
2015-06-16 22:28:42 +03:00
|
|
|
let pref;
|
|
|
|
switch (kind) {
|
|
|
|
case "Phish":
|
|
|
|
pref = "browser.safebrowsing.reportPhishURL";
|
|
|
|
break;
|
2017-02-21 04:46:36 +03:00
|
|
|
|
2015-06-16 22:28:42 +03:00
|
|
|
case "PhishMistake":
|
|
|
|
case "MalwareMistake":
|
2017-02-21 04:46:36 +03:00
|
|
|
pref =
|
|
|
|
"browser.safebrowsing.provider." +
|
|
|
|
info.provider +
|
|
|
|
".report" +
|
|
|
|
kind +
|
|
|
|
"URL";
|
2015-06-16 22:28:42 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
let err =
|
|
|
|
"SafeBrowsing getReportURL() called with unknown kind: " + kind;
|
|
|
|
Cu.reportError(err);
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
2017-03-20 09:43:08 +03:00
|
|
|
// The "Phish" reports are about submitting new phishing URLs to Google so
|
|
|
|
// they don't have an associated list URL
|
|
|
|
if (kind != "Phish" && (!info.list || !info.uri)) {
|
2017-02-21 04:46:36 +03:00
|
|
|
return null;
|
|
|
|
}
|
2012-07-28 10:25:11 +04:00
|
|
|
|
2017-02-21 04:46:36 +03:00
|
|
|
let reportUrl = Services.urlFormatter.formatURLPref(pref);
|
|
|
|
// formatURLPref might return "about:blank" if getting the pref fails
|
|
|
|
if (reportUrl == "about:blank") {
|
|
|
|
reportUrl = null;
|
|
|
|
}
|
2015-06-16 22:28:42 +03:00
|
|
|
|
2017-02-21 04:46:36 +03:00
|
|
|
if (reportUrl) {
|
|
|
|
reportUrl += encodeURIComponent(info.uri);
|
|
|
|
}
|
2015-06-16 22:28:42 +03:00
|
|
|
return reportUrl;
|
2012-07-28 10:25:11 +04:00
|
|
|
},
|
|
|
|
|
2017-08-02 18:12:07 +03:00
|
|
|
observe(aSubject, aTopic, aData) {
|
2016-08-24 12:06:48 +03:00
|
|
|
// skip nextupdatetime and lastupdatetime
|
|
|
|
if (aData.includes("lastupdatetime") || aData.includes("nextupdatetime")) {
|
|
|
|
return;
|
|
|
|
}
|
2017-07-04 11:36:31 +03:00
|
|
|
|
|
|
|
if (aData == PREF_DEBUG_ENABLED) {
|
|
|
|
loggingEnabled = Services.prefs.getBoolPref(PREF_DEBUG_ENABLED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-24 12:06:48 +03:00
|
|
|
this.readPrefs();
|
|
|
|
},
|
2012-07-28 10:25:11 +04:00
|
|
|
|
2017-08-02 18:12:07 +03:00
|
|
|
readPrefs() {
|
2017-07-04 11:36:31 +03:00
|
|
|
loggingEnabled = Services.prefs.getBoolPref(PREF_DEBUG_ENABLED);
|
2012-07-28 10:25:11 +04:00
|
|
|
log("reading prefs");
|
|
|
|
|
2019-01-15 23:04:40 +03:00
|
|
|
let obsoleteLists = [];
|
2017-08-31 13:46:23 +03:00
|
|
|
// Make a copy of the original lists before we re-read the prefs.
|
|
|
|
if (this.initialized) {
|
2019-01-15 23:04:40 +03:00
|
|
|
obsoleteLists = this.features.map(feature => {
|
|
|
|
return feature.list;
|
|
|
|
});
|
2017-08-31 13:46:23 +03:00
|
|
|
}
|
|
|
|
|
2019-01-15 23:04:40 +03:00
|
|
|
this.features = [];
|
|
|
|
for (let i = 0; i < FEATURES.length; ++i) {
|
2019-01-22 19:13:41 +03:00
|
|
|
this.features[i] = {
|
|
|
|
name: FEATURES[i].name,
|
|
|
|
list: [],
|
|
|
|
enabled: FEATURES[i].enabled(),
|
|
|
|
update: FEATURES[i].update(),
|
|
|
|
};
|
|
|
|
|
2019-01-15 23:04:40 +03:00
|
|
|
FEATURES[i].list.forEach(pref => {
|
|
|
|
this.features[i].list.push(...getLists(pref));
|
|
|
|
});
|
|
|
|
}
|
2016-07-19 03:53:21 +03:00
|
|
|
|
2019-01-15 23:04:40 +03:00
|
|
|
for (let i = 0; i < obsoleteLists.length; ++i) {
|
|
|
|
obsoleteLists[i] = obsoleteLists[i].filter(
|
|
|
|
list => !this.features[i].list.includes(list)
|
|
|
|
);
|
2017-08-31 13:46:23 +03:00
|
|
|
}
|
|
|
|
|
2012-08-02 02:52:47 +04:00
|
|
|
this.updateProviderURLs();
|
2015-09-08 09:22:10 +03:00
|
|
|
this.registerTables();
|
2017-08-31 13:46:23 +03:00
|
|
|
if (obsoleteLists) {
|
|
|
|
this.unregisterTables(obsoleteLists);
|
|
|
|
}
|
2012-07-28 10:25:11 +04:00
|
|
|
|
|
|
|
// XXX The listManager backend gets confused if this is called before the
|
|
|
|
// lists are registered. So only call it here when a pref changes, and not
|
|
|
|
// when doing initialization. I expect to refactor this later, so pardon the hack.
|
2014-07-11 05:13:35 +04:00
|
|
|
if (this.initialized) {
|
2012-07-28 10:25:11 +04:00
|
|
|
this.controlUpdateChecking();
|
2014-07-11 05:13:35 +04:00
|
|
|
}
|
2012-07-28 10:25:11 +04:00
|
|
|
},
|
|
|
|
|
2017-08-02 18:12:07 +03:00
|
|
|
updateProviderURLs() {
|
2013-01-10 11:38:50 +04:00
|
|
|
try {
|
|
|
|
var clientID = Services.prefs.getCharPref("browser.safebrowsing.id");
|
2017-08-02 18:12:07 +03:00
|
|
|
} catch (e) {
|
2015-09-08 09:22:10 +03:00
|
|
|
clientID = Services.appinfo.name;
|
2013-01-10 11:38:50 +04:00
|
|
|
}
|
2012-07-31 04:14:29 +04:00
|
|
|
|
2015-09-08 09:22:10 +03:00
|
|
|
log("initializing safe browsing URLs, client id", clientID);
|
2012-08-02 02:52:47 +04:00
|
|
|
|
2015-09-08 09:22:10 +03:00
|
|
|
// Get the different providers
|
|
|
|
let branch = Services.prefs.getBranch("browser.safebrowsing.provider.");
|
2019-05-21 09:20:40 +03:00
|
|
|
let children = branch.getChildList("");
|
2015-09-08 09:22:10 +03:00
|
|
|
this.providers = {};
|
|
|
|
this.listToProvider = {};
|
2012-08-02 02:52:47 +04:00
|
|
|
|
2015-09-08 09:22:10 +03:00
|
|
|
for (let child of children) {
|
|
|
|
log("Child: " + child);
|
|
|
|
let prefComponents = child.split(".");
|
|
|
|
let providerName = prefComponents[0];
|
|
|
|
this.providers[providerName] = {};
|
|
|
|
}
|
|
|
|
|
2017-07-04 11:36:31 +03:00
|
|
|
if (loggingEnabled) {
|
2015-09-08 09:22:10 +03:00
|
|
|
let providerStr = "";
|
|
|
|
Object.keys(this.providers).forEach(function(provider) {
|
|
|
|
if (providerStr === "") {
|
|
|
|
providerStr = provider;
|
|
|
|
} else {
|
|
|
|
providerStr += ", " + provider;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
log("Providers: " + providerStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
Object.keys(this.providers).forEach(function(provider) {
|
2018-02-07 02:36:48 +03:00
|
|
|
if (provider == "test") {
|
|
|
|
return; // skip
|
|
|
|
}
|
2015-09-08 09:22:10 +03:00
|
|
|
let updateURL = Services.urlFormatter.formatURLPref(
|
|
|
|
"browser.safebrowsing.provider." + provider + ".updateURL"
|
|
|
|
);
|
|
|
|
let gethashURL = Services.urlFormatter.formatURLPref(
|
|
|
|
"browser.safebrowsing.provider." + provider + ".gethashURL"
|
|
|
|
);
|
|
|
|
updateURL = updateURL.replace("SAFEBROWSING_ID", clientID);
|
|
|
|
gethashURL = gethashURL.replace("SAFEBROWSING_ID", clientID);
|
|
|
|
|
2017-04-25 10:20:44 +03:00
|
|
|
// Disable updates and gethash if the Google API key is missing.
|
2019-03-10 18:29:41 +03:00
|
|
|
let googleSafebrowsingKey = Services.urlFormatter
|
|
|
|
.formatURL("%GOOGLE_SAFEBROWSING_API_KEY%")
|
|
|
|
.trim();
|
2017-04-25 10:20:44 +03:00
|
|
|
if (
|
|
|
|
(provider == "google" || provider == "google4") &&
|
2019-03-10 18:29:41 +03:00
|
|
|
(!googleSafebrowsingKey ||
|
|
|
|
googleSafebrowsingKey == "no-google-safebrowsing-api-key")
|
|
|
|
) {
|
|
|
|
log(
|
|
|
|
"Missing Google SafeBrowsing API key, clearing updateURL and gethashURL."
|
|
|
|
);
|
2017-08-02 18:12:07 +03:00
|
|
|
updateURL = "";
|
|
|
|
gethashURL = "";
|
2017-04-25 10:20:44 +03:00
|
|
|
}
|
|
|
|
|
2015-09-08 09:22:10 +03:00
|
|
|
log("Provider: " + provider + " updateURL=" + updateURL);
|
|
|
|
log("Provider: " + provider + " gethashURL=" + gethashURL);
|
|
|
|
|
|
|
|
// Urls used to update DB
|
|
|
|
this.providers[provider].updateURL = updateURL;
|
|
|
|
this.providers[provider].gethashURL = gethashURL;
|
|
|
|
|
|
|
|
// Get lists this provider manages
|
|
|
|
let lists = getLists(
|
|
|
|
"browser.safebrowsing.provider." + provider + ".lists"
|
|
|
|
);
|
|
|
|
if (lists) {
|
|
|
|
lists.forEach(function(list) {
|
|
|
|
this.listToProvider[list] = provider;
|
|
|
|
}, this);
|
|
|
|
} else {
|
|
|
|
log("Update URL given but no lists managed for provider: " + provider);
|
|
|
|
}
|
|
|
|
}, this);
|
2012-07-28 10:25:11 +04:00
|
|
|
},
|
|
|
|
|
2017-08-02 18:12:07 +03:00
|
|
|
controlUpdateChecking() {
|
2019-01-15 23:04:40 +03:00
|
|
|
if (loggingEnabled) {
|
|
|
|
this.features.forEach(feature => {
|
|
|
|
log("feature " + feature.name + ":");
|
|
|
|
log(" enabled:" + feature.enabled);
|
2019-01-22 19:13:41 +03:00
|
|
|
log(" update:" + feature.update);
|
2019-01-15 23:04:40 +03:00
|
|
|
log(" tables:" + feature.list);
|
|
|
|
});
|
|
|
|
}
|
2012-07-28 10:25:11 +04:00
|
|
|
|
|
|
|
let listManager = Cc[
|
|
|
|
"@mozilla.org/url-classifier/listmanager;1"
|
|
|
|
].getService(Ci.nsIUrlListManager);
|
|
|
|
|
2018-08-15 15:13:16 +03:00
|
|
|
listManager.disableAllUpdates();
|
|
|
|
|
2019-01-15 23:04:40 +03:00
|
|
|
this.features.forEach(feature => {
|
2019-01-22 19:13:41 +03:00
|
|
|
if (feature.update) {
|
2019-01-15 23:04:40 +03:00
|
|
|
feature.list.forEach(table => {
|
|
|
|
listManager.enableUpdate(table);
|
|
|
|
});
|
2017-08-09 02:23:10 +03:00
|
|
|
}
|
2019-01-15 23:04:40 +03:00
|
|
|
});
|
|
|
|
|
2014-07-11 05:13:35 +04:00
|
|
|
listManager.maybeToggleUpdateChecking();
|
2012-07-28 10:25:11 +04:00
|
|
|
},
|
|
|
|
};
|