Bug 1418162 Use a build constant to determine update channel, and update ESR equation for 60 r?gijs,Build
Previously we used Services.appinfo.defaultUpdateChannel to determine if we were on ESR
and if so, we would assert to make sure the ESR equation hadn't changed. But that method
is a footgun. We could use UpdateUtils.getUpdateChannel, but for our purposes here, the
compile-time constant will work just as well.
If it's set correctly, for Mozilla, we will perform our assert check. If it's not set to
esr (e.g. for Tor), they'll skip the assert. They probably want to control their user agent
themselves anyway.
MozReview-Commit-ID: DLnWSEpCVJ6
--- a/browser/components/resistfingerprinting/test/browser/browser_navigator.js
+++ b/browser/components/resistfingerprinting/test/browser/browser_navigator.js
@@ -114,17 +114,17 @@ async function testWorkerNavigator() {
}
add_task(async function setup() {
await SpecialPowers.pushPrefEnv({"set":
[["privacy.resistFingerprinting", true]]
});
let appVersion = parseInt(Services.appinfo.version);
- let spoofedVersion = appVersion - ((appVersion - 3) % 7);
+ let spoofedVersion = appVersion - ((appVersion - 4) % 7);
spoofedUserAgent = `Mozilla/5.0 (${SPOOFED_UA_OS[AppConstants.platform]}; rv:${spoofedVersion}.0) Gecko/20100101 Firefox/${spoofedVersion}.0`;
});
add_task(async function runNavigatorTest() {
await testNavigator();
});
add_task(async function runWorkerNavigatorTest() {
--- a/toolkit/components/resistfingerprinting/nsRFPService.cpp
+++ b/toolkit/components/resistfingerprinting/nsRFPService.cpp
@@ -685,36 +685,29 @@ nsRFPService::GetSpoofedUserAgent(nsACSt
NS_ENSURE_SUCCESS(rv, rv);
// The browser version will be spoofed as the last ESR version.
// By doing so, the anonymity group will cover more versions instead of one
// version.
uint32_t firefoxVersion = appVersion.ToInteger(&rv);
NS_ENSURE_SUCCESS(rv, rv);
- // Starting from Firefox 10, Firefox ESR was released once every seven
- // Firefox releases, e.g. Firefox 10, 17, 24, 31, and so on.
- // We infer the last and closest ESR version based on this rule.
- nsCOMPtr<nsIXULRuntime> runtime =
- do_GetService("@mozilla.org/xre/runtime;1", &rv);
- NS_ENSURE_SUCCESS(rv, rv);
-
- nsAutoCString updateChannel;
- rv = runtime->GetDefaultUpdateChannel(updateChannel);
- NS_ENSURE_SUCCESS(rv, rv);
-
// If we are running in Firefox ESR, determine whether the formula of ESR
// version has changed. Once changed, we must update the formula in this
// function.
- if (updateChannel.EqualsLiteral("esr")) {
- MOZ_ASSERT(((firefoxVersion % 7) == 3),
+ if (!strcmp(NS_STRINGIFY(MOZ_UPDATE_CHANNEL), "esr")) {
+ MOZ_ASSERT(((firefoxVersion % 7) == 4),
"Please udpate ESR version formula in nsRFPService.cpp");
}
- uint32_t spoofedVersion = firefoxVersion - ((firefoxVersion - 3) % 7);
+ // Starting from Firefox 10, Firefox ESR was released once every seven
+ // Firefox releases, e.g. Firefox 10, 17, 24, 31, and so on.
+ // Except we used 60 as an ESR instead of 59.
+ // We infer the last and closest ESR version based on this rule.
+ uint32_t spoofedVersion = firefoxVersion - ((firefoxVersion - 4) % 7);
userAgent.Assign(nsPrintfCString(
"Mozilla/5.0 (%s; rv:%d.0) Gecko/%s Firefox/%d.0",
SPOOFED_UA_OS, spoofedVersion, LEGACY_BUILD_ID, spoofedVersion));
return rv;
}
nsresult