Bug 1404608 - Reveal the real operating system when fingerprinting resistance is enabled. r=arthuredelstein,smaug

This patch makes Firefox not to lie about the real operating system when pref
'privacy.resistFingerprinting' is true. This will also change the testcase as well.

MozReview-Commit-ID: Gdnp2lMU3wr

--HG--
extra : rebase_source : 62c408db6dc372091510fe1adf29f529eae99cdc
This commit is contained in:
Tim Huang 2017-12-12 15:25:49 -06:00
parent ac211431a8
commit 8a762bcc31
3 changed files with 65 additions and 12 deletions

View File

@ -5,15 +5,44 @@
const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
XPCOMUtils.defineLazyModuleGetter(this, "AppConstants",
"resource://gre/modules/AppConstants.jsm");
const TEST_PATH = "http://example.net/browser/browser/" +
"components/resistfingerprinting/test/browser/";
var spoofedUserAgent;
const SPOOFED_APPNAME = "Netscape";
const SPOOFED_APPVERSION = "5.0 (Windows)";
const SPOOFED_PLATFORM = "Win64";
const SPOOFED_OSCPU = "Windows NT 6.1; Win64; x64";
const SPOOFED_APPNAME = "Netscape";
const SPOOFED_APPVERSION = {
linux: "5.0 (X11)",
win: "5.0 (Windows)",
macosx: "5.0 (Macintosh)",
android: "5.0 (Android 6.0)",
other: "5.0 (X11)",
};
const SPOOFED_PLATFORM = {
linux: "Linux x86_64",
win: "Win64",
macosx: "MacIntel",
android: "Linux armv7l",
other: "Linux x86_64",
};
const SPOOFED_OSCPU = {
linux: "Linux x86_64",
win: "Windows NT 6.1; Win64; x64",
macosx: "Intel Mac OS X 10.13",
android: "Linux armv7l",
other: "Linux x86_64",
};
const SPOOFED_UA_OS = {
linux: "X11; Linux x86_64",
win: "Windows NT 6.1; Win64; x64",
macosx: "Macintosh; Intel Mac OS X 10.13",
android: "Android 6.0; Mobile",
other: "X11; Linux x86_64",
};
const SPOOFED_BUILDID = "20100101";
const SPOOFED_HW_CONCURRENCY = 2;
@ -35,12 +64,12 @@ async function testNavigator() {
result = JSON.parse(result);
is(result.appName, SPOOFED_APPNAME, "Navigator.appName is correctly spoofed.");
is(result.appVersion, SPOOFED_APPVERSION, "Navigator.appVersion is correctly spoofed.");
is(result.platform, SPOOFED_PLATFORM, "Navigator.platform is correctly spoofed.");
is(result.appVersion, SPOOFED_APPVERSION[AppConstants.platform], "Navigator.appVersion is correctly spoofed.");
is(result.platform, SPOOFED_PLATFORM[AppConstants.platform], "Navigator.platform is correctly spoofed.");
is(result.userAgent, spoofedUserAgent, "Navigator.userAgent is correctly spoofed.");
is(result.mimeTypesLength, 0, "Navigator.mimeTypes has a length of 0.");
is(result.pluginsLength, 0, "Navigator.plugins has a length of 0.");
is(result.oscpu, SPOOFED_OSCPU, "Navigator.oscpu is correctly spoofed.");
is(result.oscpu, SPOOFED_OSCPU[AppConstants.platform], "Navigator.oscpu is correctly spoofed.");
is(result.buildID, SPOOFED_BUILDID, "Navigator.buildID is correctly spoofed.");
is(result.hardwareConcurrency, SPOOFED_HW_CONCURRENCY, "Navigator.hardwareConcurrency is correctly spoofed.");
@ -73,8 +102,8 @@ async function testWorkerNavigator() {
result = JSON.parse(result);
is(result.appName, SPOOFED_APPNAME, "Navigator.appName is correctly spoofed.");
is(result.appVersion, SPOOFED_APPVERSION, "Navigator.appVersion is correctly spoofed.");
is(result.platform, SPOOFED_PLATFORM, "Navigator.platform is correctly spoofed.");
is(result.appVersion, SPOOFED_APPVERSION[AppConstants.platform], "Navigator.appVersion is correctly spoofed.");
is(result.platform, SPOOFED_PLATFORM[AppConstants.platform], "Navigator.platform is correctly spoofed.");
is(result.userAgent, spoofedUserAgent, "Navigator.userAgent is correctly spoofed.");
is(result.hardwareConcurrency, SPOOFED_HW_CONCURRENCY, "Navigator.hardwareConcurrency is correctly spoofed.");
@ -91,7 +120,7 @@ add_task(async function setup() {
let appVersion = parseInt(Services.appinfo.version);
let spoofedVersion = appVersion - ((appVersion - 3) % 7);
spoofedUserAgent = `Mozilla/5.0 (${SPOOFED_OSCPU}; rv:${spoofedVersion}.0) Gecko/20100101 Firefox/${spoofedVersion}.0`;
spoofedUserAgent = `Mozilla/5.0 (${SPOOFED_UA_OS[AppConstants.platform]}; rv:${spoofedVersion}.0) Gecko/20100101 Firefox/${spoofedVersion}.0`;
});
add_task(async function runNavigatorTest() {

View File

@ -213,7 +213,7 @@ nsRFPService::GetSpoofedUserAgent(nsACString &userAgent)
uint32_t spoofedVersion = firefoxVersion - ((firefoxVersion - 3) % 7);
userAgent.Assign(nsPrintfCString(
"Mozilla/5.0 (%s; rv:%d.0) Gecko/%s Firefox/%d.0",
SPOOFED_OSCPU, spoofedVersion, LEGACY_BUILD_ID, spoofedVersion));
SPOOFED_UA_OS, spoofedVersion, LEGACY_BUILD_ID, spoofedVersion));
return rv;
}

View File

@ -13,11 +13,35 @@
// Defines regarding spoofed values of Navigator object. These spoofed values
// are returned when 'privacy.resistFingerprinting' is true.
#define SPOOFED_APPNAME "Netscape"
// We decided to give different spoofed values according to the platform. The
// reason is that it is easy to detect the real platform. So there is no benefit
// for hiding the platform: it only brings breakages, like keyboard shortcuts won't
// work in MAC OS if we spoof it as a window platform.
#ifdef XP_WIN
#define SPOOFED_UA_OS "Windows NT 6.1; Win64; x64"
#define SPOOFED_APPVERSION "5.0 (Windows)"
#define SPOOFED_OSCPU "Windows NT 6.1; Win64; x64"
#define SPOOFED_PLATFORM "Win64"
#elif defined(XP_MACOSX)
#define SPOOFED_UA_OS "Macintosh; Intel Mac OS X 10.13"
#define SPOOFED_APPVERSION "5.0 (Macintosh)"
#define SPOOFED_OSCPU "Intel Mac OS X 10.13"
#define SPOOFED_PLATFORM "MacIntel"
#elif defined(MOZ_WIDGET_ANDROID)
#define SPOOFED_UA_OS "Android 6.0; Mobile"
#define SPOOFED_APPVERSION "5.0 (Android 6.0)"
#define SPOOFED_OSCPU "Linux armv7l"
#define SPOOFED_PLATFORM "Linux armv7l"
#else
// For Linux and other platforms, like BSDs, SunOS and etc, we will use Linux
// platform.
#define SPOOFED_UA_OS "X11; Linux x86_64"
#define SPOOFED_APPVERSION "5.0 (X11)"
#define SPOOFED_OSCPU "Linux x86_64"
#define SPOOFED_PLATFORM "Linux x86_64"
#endif
#define SPOOFED_APPNAME "Netscape"
#define LEGACY_BUILD_ID "20100101"
namespace mozilla {