Bug 1024610: Register tracking protection list and hook it up in nsChannelClassifier (r=gcp)

This commit is contained in:
Monica Chew 2014-07-02 12:41:00 -07:00
parent 73e8fdd516
commit 01b8cd578d
8 changed files with 89 additions and 30 deletions

View File

@ -1,5 +1,5 @@
// Force SafeBrowsing to be initialized for the tests
Services.prefs.setCharPref("urlclassifier.malware_table", "test-malware-simple");
Services.prefs.setCharPref("urlclassifier.phish_table", "test-phish-simple");
Services.prefs.setCharPref("urlclassifier.malwareTable", "test-malware-simple");
Services.prefs.setCharPref("urlclassifier.phishTable", "test-phish-simple");
SafeBrowsing.init();

View File

@ -819,6 +819,8 @@ pref("privacy.donottrackheader.enabled", false);
// 0 = tracking is acceptable
// 1 = tracking is unacceptable
pref("privacy.donottrackheader.value", 1);
// Enforce tracking protection
pref("privacy.trackingprotection.enabled", false);
pref("dom.event.contextmenu.enabled", true);
pref("dom.event.clipboardevents.enabled", true);
@ -4187,11 +4189,17 @@ pref("dom.voicemail.defaultServiceId", 0);
pref("dom.inter-app-communication-api.enabled", false);
// The tables used for Safebrowsing phishing and malware checks.
pref("urlclassifier.malware_table", "goog-malware-shavar,test-malware-simple");
pref("urlclassifier.phish_table", "goog-phish-shavar,test-phish-simple");
pref("urlclassifier.malwareTable", "goog-malware-shavar,test-malware-simple");
pref("urlclassifier.phishTable", "goog-phish-shavar,test-phish-simple");
pref("urlclassifier.downloadBlockTable", "");
pref("urlclassifier.downloadAllowTable", "");
pref("urlclassifier.disallow_completions", "test-malware-simple,test-phish-simple,goog-downloadwhite-digest256");
pref("urlclassifier.disallow_completions", "test-malware-simple,test-phish-simple,goog-downloadwhite-digest256,mozpub-track-digest256");
// The table and update/gethash URLs for Safebrowsing phishing and malware
// checks.
pref("urlclassifier.trackingTable", "mozpub-track-digest256");
pref("browser.trackingprotection.updateURL", "https://tracking.services.mozilla.com/update?client=SAFEBROWSING_ID&appver=%VERSION%&pver=2.2");
pref("browser.trackingprotection.gethashURL", "https://tracking.services.mozilla.com/gethash?client=SAFEBROWSING_ID&appver=%VERSION%&pver=2.2");
// Turn off Spatial navigation by default.
pref("snav.enabled", false);

View File

@ -24,10 +24,11 @@ function getLists(prefName) {
}
// These may be a comma-separated lists of tables.
const phishingLists = getLists("urlclassifier.phish_table");
const malwareLists = getLists("urlclassifier.malware_table");
const phishingLists = getLists("urlclassifier.phishTable");
const malwareLists = getLists("urlclassifier.malwareTable");
const downloadBlockLists = getLists("urlclassifier.downloadBlockTable");
const downloadAllowLists = getLists("urlclassifier.downloadAllowTable");
const trackingProtectionLists = getLists("urlclassifier.trackingTable");
var debug = false;
function log(...stuff) {
@ -65,6 +66,11 @@ this.SafeBrowsing = {
for (let i = 0; i < downloadAllowLists.length; ++i) {
listManager.registerTable(downloadAllowLists[i], this.updateURL, this.gethashURL);
}
for (let i = 0; i < trackingProtectionLists.length; ++i) {
listManager.registerTable(trackingProtectionLists[i],
this.trackingUpdateURL,
this.trackingGethashURL);
}
this.addMozEntries();
this.controlUpdateChecking();
@ -99,7 +105,8 @@ this.SafeBrowsing = {
debug = Services.prefs.getBoolPref("browser.safebrowsing.debug");
this.phishingEnabled = Services.prefs.getBoolPref("browser.safebrowsing.enabled");
this.malwareEnabled = Services.prefs.getBoolPref("browser.safebrowsing.malware.enabled");
this.malwareEnabled = Services.prefs.getBoolPref("browser.safebrowsing.malware.enabled");
this.trackingEnabled = Services.prefs.getBoolPref("privacy.trackingprotection.enabled");
this.updateProviderURLs();
// XXX The listManager backend gets confused if this is called before the
@ -134,6 +141,10 @@ this.SafeBrowsing = {
this.updateURL = this.updateURL.replace("SAFEBROWSING_ID", clientID);
this.gethashURL = this.gethashURL.replace("SAFEBROWSING_ID", clientID);
this.trackingUpdateURL = Services.urlFormatter.formatURLPref(
"browser.trackingprotection.updateURL");
this.trackingGethashURL = Services.urlFormatter.formatURLPref(
"browser.trackingprotection.gethashURL");
},
controlUpdateChecking: function() {
@ -170,6 +181,13 @@ this.SafeBrowsing = {
listManager.disableUpdate(downloadAllowLists[i]);
}
}
for (let i = 0; i < trackingProtectionLists.length; ++i) {
if (this.trackingEnabled) {
listManager.enableUpdate(trackingProtectionLists[i]);
} else {
listManager.disableUpdate(trackingProtectionLists[i]);
}
}
},

View File

@ -67,12 +67,16 @@ PRLogModuleInfo *gUrlClassifierDbServiceLog = nullptr;
#define CHECK_PHISHING_PREF "browser.safebrowsing.enabled"
#define CHECK_PHISHING_DEFAULT false
#define CHECK_TRACKING_PREF "privacy.trackingprotection.enabled"
#define CHECK_TRACKING_DEFAULT false
#define GETHASH_NOISE_PREF "urlclassifier.gethashnoise"
#define GETHASH_NOISE_DEFAULT 4
// Comma-separated lists
#define MALWARE_TABLE_PREF "urlclassifier.malware_table"
#define PHISH_TABLE_PREF "urlclassifier.phish_table"
#define MALWARE_TABLE_PREF "urlclassifier.malwareTable"
#define PHISH_TABLE_PREF "urlclassifier.phishTable"
#define TRACKING_TABLE_PREF "urlclassifier.trackingTable"
#define DOWNLOAD_BLOCK_TABLE_PREF "urlclassifier.downloadBlockTable"
#define DOWNLOAD_ALLOW_TABLE_PREF "urlclassifier.downloadAllowTable"
#define DISALLOW_COMPLETION_TABLE_PREF "urlclassifier.disallow_completions"
@ -850,7 +854,8 @@ nsUrlClassifierLookupCallback::LookupComplete(nsTArray<LookupResult>* results)
}
} else {
// For tables with no hash completer, a complete hash match is
// good enough, we'll consider it fresh.
// good enough, we'll consider it fresh, even if it hasn't been updated
// in 45 minutes.
if (result.Complete()) {
result.mFresh = true;
} else {
@ -996,10 +1001,12 @@ public:
nsUrlClassifierClassifyCallback(nsIURIClassifierCallback *c,
bool checkMalware,
bool checkPhishing)
bool checkPhishing,
bool checkTracking)
: mCallback(c)
, mCheckMalware(checkMalware)
, mCheckPhishing(checkPhishing)
, mCheckTracking(checkTracking)
{}
private:
@ -1008,6 +1015,7 @@ private:
nsCOMPtr<nsIURIClassifierCallback> mCallback;
bool mCheckMalware;
bool mCheckPhishing;
bool mCheckTracking;
};
NS_IMPL_ISUPPORTS(nsUrlClassifierClassifyCallback,
@ -1021,21 +1029,16 @@ nsUrlClassifierClassifyCallback::HandleEvent(const nsACString& tables)
// enough information.
nsresult response = NS_OK;
nsACString::const_iterator begin, end;
tables.BeginReading(begin);
tables.EndReading(end);
if (mCheckMalware &&
FindInReadable(NS_LITERAL_CSTRING("-malware-"), begin, end)) {
FindInReadable(NS_LITERAL_CSTRING("-malware-"), tables)) {
response = NS_ERROR_MALWARE_URI;
} else {
// Reset begin before checking phishing table
tables.BeginReading(begin);
if (mCheckPhishing &&
FindInReadable(NS_LITERAL_CSTRING("-phish-"), begin, end)) {
response = NS_ERROR_PHISHING_URI;
}
} else if (mCheckPhishing &&
FindInReadable(NS_LITERAL_CSTRING("-phish-"), tables)) {
response = NS_ERROR_PHISHING_URI;
} else if (mCheckTracking &&
FindInReadable(NS_LITERAL_CSTRING("-track-"), tables)) {
LOG(("Blocking tracking uri [this=%p]", this));
response = NS_ERROR_TRACKING_URI;
}
mCallback->OnClassifyComplete(response);
@ -1081,6 +1084,7 @@ nsUrlClassifierDBService::GetInstance(nsresult *result)
nsUrlClassifierDBService::nsUrlClassifierDBService()
: mCheckMalware(CHECK_MALWARE_DEFAULT)
, mCheckPhishing(CHECK_PHISHING_DEFAULT)
, mCheckTracking(CHECK_TRACKING_DEFAULT)
, mInUpdate(false)
{
}
@ -1115,6 +1119,12 @@ nsUrlClassifierDBService::ReadTablesFromPrefs()
allTables.Append(tables);
}
Preferences::GetCString(TRACKING_TABLE_PREF, &tables);
if (!tables.IsEmpty()) {
allTables.Append(',');
allTables.Append(tables);
}
Classifier::SplitTables(allTables, mGethashTables);
Preferences::GetCString(DISALLOW_COMPLETION_TABLE_PREF, &tables);
@ -1136,6 +1146,8 @@ nsUrlClassifierDBService::Init()
CHECK_MALWARE_DEFAULT);
mCheckPhishing = Preferences::GetBool(CHECK_PHISHING_PREF,
CHECK_PHISHING_DEFAULT);
mCheckTracking = Preferences::GetBool(CHECK_TRACKING_PREF,
CHECK_TRACKING_DEFAULT);
uint32_t gethashNoise = Preferences::GetUint(GETHASH_NOISE_PREF,
GETHASH_NOISE_DEFAULT);
gFreshnessGuarantee = Preferences::GetInt(CONFIRM_AGE_PREF,
@ -1145,10 +1157,12 @@ nsUrlClassifierDBService::Init()
// Do we *really* need to be able to change all of these at runtime?
Preferences::AddStrongObserver(this, CHECK_MALWARE_PREF);
Preferences::AddStrongObserver(this, CHECK_PHISHING_PREF);
Preferences::AddStrongObserver(this, CHECK_TRACKING_PREF);
Preferences::AddStrongObserver(this, GETHASH_NOISE_PREF);
Preferences::AddStrongObserver(this, CONFIRM_AGE_PREF);
Preferences::AddStrongObserver(this, PHISH_TABLE_PREF);
Preferences::AddStrongObserver(this, MALWARE_TABLE_PREF);
Preferences::AddStrongObserver(this, TRACKING_TABLE_PREF);
Preferences::AddStrongObserver(this, DOWNLOAD_BLOCK_TABLE_PREF);
Preferences::AddStrongObserver(this, DOWNLOAD_ALLOW_TABLE_PREF);
Preferences::AddStrongObserver(this, DISALLOW_COMPLETION_TABLE_PREF);
@ -1212,7 +1226,8 @@ nsUrlClassifierDBService::Classify(nsIPrincipal* aPrincipal,
}
nsRefPtr<nsUrlClassifierClassifyCallback> callback =
new nsUrlClassifierClassifyCallback(c, mCheckMalware, mCheckPhishing);
new nsUrlClassifierClassifyCallback(c, mCheckMalware, mCheckPhishing,
mCheckTracking);
if (!callback) return NS_ERROR_OUT_OF_MEMORY;
nsAutoCString tables;
@ -1228,6 +1243,13 @@ nsUrlClassifierDBService::Classify(nsIPrincipal* aPrincipal,
tables.Append(',');
tables.Append(phishing);
}
nsAutoCString tracking;
Preferences::GetCString(TRACKING_TABLE_PREF, &tracking);
if (!tracking.IsEmpty()) {
LOG(("Looking up in tracking table, [cb=%p]", callback.get()));
tables.Append(',');
tables.Append(tracking);
}
nsresult rv = LookupURI(aPrincipal, tables, callback, false, result);
if (rv == NS_ERROR_MALFORMED_URI) {
*result = false;
@ -1480,9 +1502,13 @@ nsUrlClassifierDBService::Observe(nsISupports *aSubject, const char *aTopic,
} else if (NS_LITERAL_STRING(CHECK_PHISHING_PREF).Equals(aData)) {
mCheckPhishing = Preferences::GetBool(CHECK_PHISHING_PREF,
CHECK_PHISHING_DEFAULT);
} else if (NS_LITERAL_STRING(CHECK_TRACKING_PREF).Equals(aData)) {
mCheckTracking = Preferences::GetBool(CHECK_TRACKING_PREF,
CHECK_TRACKING_DEFAULT);
} else if (
NS_LITERAL_STRING(PHISH_TABLE_PREF).Equals(aData) ||
NS_LITERAL_STRING(MALWARE_TABLE_PREF).Equals(aData) ||
NS_LITERAL_STRING(TRACKING_TABLE_PREF).Equals(aData) ||
NS_LITERAL_STRING(DOWNLOAD_BLOCK_TABLE_PREF).Equals(aData) ||
NS_LITERAL_STRING(DOWNLOAD_ALLOW_TABLE_PREF).Equals(aData) ||
NS_LITERAL_STRING(DISALLOW_COMPLETION_TABLE_PREF).Equals(aData)) {
@ -1517,8 +1543,10 @@ nsUrlClassifierDBService::Shutdown()
if (prefs) {
prefs->RemoveObserver(CHECK_MALWARE_PREF, this);
prefs->RemoveObserver(CHECK_PHISHING_PREF, this);
prefs->RemoveObserver(CHECK_TRACKING_PREF, this);
prefs->RemoveObserver(PHISH_TABLE_PREF, this);
prefs->RemoveObserver(MALWARE_TABLE_PREF, this);
prefs->RemoveObserver(TRACKING_TABLE_PREF, this);
prefs->RemoveObserver(DOWNLOAD_BLOCK_TABLE_PREF, this);
prefs->RemoveObserver(DOWNLOAD_ALLOW_TABLE_PREF, this);
prefs->RemoveObserver(DISALLOW_COMPLETION_TABLE_PREF, this);

View File

@ -99,6 +99,10 @@ private:
// uris on document loads.
bool mCheckPhishing;
// TRUE if the nsURIClassifier implementation should check for tracking
// uris on document loads.
bool mCheckTracking;
// TRUE if a BeginUpdate() has been called without an accompanying
// CancelUpdate()/FinishUpdate(). This is used to prevent competing
// updates, not to determine whether an update is still being

View File

@ -61,8 +61,8 @@ function doUpdate(update) {
}
SpecialPowers.pushPrefEnv(
{"set" : [["urlclassifier.malware_table", "test-malware-simple"],
["urlclassifier.phish_table", "test-phish-simple"]]},
{"set" : [["urlclassifier.malwareTable", "test-malware-simple"],
["urlclassifier.phishTable", "test-phish-simple"]]},
function() { doUpdate(testUpdate); });
// Expected finish() call is in "classifierFrame.html".

View File

@ -73,8 +73,8 @@ function onmessage(event)
}
SpecialPowers.pushPrefEnv(
{"set" : [["urlclassifier.malware_table", "test-malware-simple"],
["urlclassifier.phish_table", "test-phish-simple"]]},
{"set" : [["urlclassifier.malwareTable", "test-malware-simple"],
["urlclassifier.phishTable", "test-phish-simple"]]},
function() { doUpdate(testUpdate); });
window.addEventListener("message", onmessage, false);

View File

@ -664,6 +664,7 @@
* blacklist. */
ERROR(NS_ERROR_MALWARE_URI, FAILURE(30)),
ERROR(NS_ERROR_PHISHING_URI, FAILURE(31)),
ERROR(NS_ERROR_TRACKING_URI, FAILURE(34)),
/* Used when "Save Link As..." doesn't see the headers quickly enough to
* choose a filename. See nsContextMenu.js. */
ERROR(NS_ERROR_SAVE_LINK_AS_TIMEOUT, FAILURE(32)),