From 6651828e8cb6f62681c48c786b572fea6e437003 Mon Sep 17 00:00:00 2001 From: Yoshi Huang Date: Tue, 3 May 2016 17:29:21 +0800 Subject: [PATCH] Bug 1077874 - Only expose Major version of Firefox in SafeBrowsing. r=francois --- modules/libpref/init/all.js | 8 ++--- .../tests/unit/test_provider_url.js | 34 +++++++++++++++++++ .../url-classifier/tests/unit/xpcshell.ini | 1 + .../components/urlformatter/nsURLFormatter.js | 1 + 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 toolkit/components/url-classifier/tests/unit/test_provider_url.js diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 6fb1230371f9..af15c78b7bff 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -4999,8 +4999,8 @@ pref("browser.safebrowsing.downloads.remote.block_uncommon", true); pref("browser.safebrowsing.debug", false); pref("browser.safebrowsing.provider.google.lists", "goog-badbinurl-shavar,goog-downloadwhite-digest256,goog-phish-shavar,goog-malware-shavar,goog-unwanted-shavar"); -pref("browser.safebrowsing.provider.google.updateURL", "https://safebrowsing.google.com/safebrowsing/downloads?client=SAFEBROWSING_ID&appver=%VERSION%&pver=2.2&key=%GOOGLE_API_KEY%"); -pref("browser.safebrowsing.provider.google.gethashURL", "https://safebrowsing.google.com/safebrowsing/gethash?client=SAFEBROWSING_ID&appver=%VERSION%&pver=2.2"); +pref("browser.safebrowsing.provider.google.updateURL", "https://safebrowsing.google.com/safebrowsing/downloads?client=SAFEBROWSING_ID&appver=%MAJOR_VERSION%&pver=2.2&key=%GOOGLE_API_KEY%"); +pref("browser.safebrowsing.provider.google.gethashURL", "https://safebrowsing.google.com/safebrowsing/gethash?client=SAFEBROWSING_ID&appver=%MAJOR_VERSION%&pver=2.2"); pref("browser.safebrowsing.provider.google.reportURL", "https://safebrowsing.google.com/safebrowsing/diagnostic?client=%NAME%&hl=%LOCALE%&site="); pref("browser.safebrowsing.reportPhishMistakeURL", "https://%LOCALE%.phish-error.mozilla.com/?hl=%LOCALE%&url="); @@ -5016,8 +5016,8 @@ pref("browser.safebrowsing.blockedURIs.enabled", false); pref("urlclassifier.blockedTable", "test-block-simple,mozplugin-block-digest256"); pref("browser.safebrowsing.provider.mozilla.lists", "mozstd-track-digest256,mozstd-trackwhite-digest256,mozfull-track-digest256,mozplugin-block-digest256,mozplugin2-block-digest256"); -pref("browser.safebrowsing.provider.mozilla.updateURL", "https://shavar.services.mozilla.com/downloads?client=SAFEBROWSING_ID&appver=%VERSION%&pver=2.2"); -pref("browser.safebrowsing.provider.mozilla.gethashURL", "https://shavar.services.mozilla.com/gethash?client=SAFEBROWSING_ID&appver=%VERSION%&pver=2.2"); +pref("browser.safebrowsing.provider.mozilla.updateURL", "https://shavar.services.mozilla.com/downloads?client=SAFEBROWSING_ID&appver=%MAJOR_VERSION%&pver=2.2"); +pref("browser.safebrowsing.provider.mozilla.gethashURL", "https://shavar.services.mozilla.com/gethash?client=SAFEBROWSING_ID&appver=%MAJOR_VERSION%&pver=2.2"); // Set to a date in the past to force immediate download in new profiles. pref("browser.safebrowsing.provider.mozilla.nextupdatetime", "1"); // Block lists for tracking protection. The name values will be used as the keys diff --git a/toolkit/components/url-classifier/tests/unit/test_provider_url.js b/toolkit/components/url-classifier/tests/unit/test_provider_url.js new file mode 100644 index 000000000000..9a946dc3fecc --- /dev/null +++ b/toolkit/components/url-classifier/tests/unit/test_provider_url.js @@ -0,0 +1,34 @@ +Cu.import("resource://testing-common/AppInfo.jsm", this); +Cu.import("resource://gre/modules/Services.jsm"); + +function updateVersion(version) { + updateAppInfo({ version }); +} + +add_test(function test_provider_url() { + let urls = [ + "browser.safebrowsing.provider.google.updateURL", + "browser.safebrowsing.provider.google.gethashURL", + "browser.safebrowsing.provider.mozilla.updateURL", + "browser.safebrowsing.provider.mozilla.gethashURL" + ]; + + let versions = [ + "49.0", + "49.0.1", + "49.0a1", + "49.0b1", + "49.0esr", + "49.0.1esr" + ]; + + for (let version of versions) { + for (let url of urls) { + updateVersion(version); + let value = Services.urlFormatter.formatURLPref(url); + Assert.notEqual(value.indexOf("&appver=49.0&"), -1); + } + } + + run_next_test(); +}); diff --git a/toolkit/components/url-classifier/tests/unit/xpcshell.ini b/toolkit/components/url-classifier/tests/unit/xpcshell.ini index 1c923b277a4a..3e09d0e0a406 100644 --- a/toolkit/components/url-classifier/tests/unit/xpcshell.ini +++ b/toolkit/components/url-classifier/tests/unit/xpcshell.ini @@ -14,5 +14,6 @@ support-files = #skip-if = os == "mac" || os == "linux" [test_partial.js] [test_prefixset.js] +[test_provider_url.js] [test_streamupdater.js] [test_digest256.js] diff --git a/toolkit/components/urlformatter/nsURLFormatter.js b/toolkit/components/urlformatter/nsURLFormatter.js index cee1615ba520..beb3bea53613 100644 --- a/toolkit/components/urlformatter/nsURLFormatter.js +++ b/toolkit/components/urlformatter/nsURLFormatter.js @@ -104,6 +104,7 @@ nsURLFormatterService.prototype = { NAME: function() { return this.appInfo.name; }, ID: function() { return this.appInfo.ID; }, VERSION: function() { return this.appInfo.version; }, + MAJOR_VERSION: function() { return this.appInfo.version.replace(/^([^\.]+\.[0-9]+[a-z]*).*/gi, "$1"); }, APPBUILDID: function() { return this.appInfo.appBuildID; }, PLATFORMVERSION: function() { return this.appInfo.platformVersion; }, PLATFORMBUILDID: function() { return this.appInfo.platformBuildID; },