From 7906e7f3403b588f31322534b16ad5c09aba5ae7 Mon Sep 17 00:00:00 2001 From: Tom Schuster Date: Wed, 19 Jul 2023 17:00:53 +0000 Subject: [PATCH] Bug 1843841 - Make navigator.appName constant. r=dom-worker-reviewers,webidl,smaug,timhuang This is supposed to constant per https://html.spec.whatwg.org/#client-identification. Differential Revision: https://phabricator.services.mozilla.com/D183723 --- .../test/browser/browser_navigator.js | 10 ++++-- .../test/browser/file_navigator.html | 1 + dom/base/Navigator.cpp | 33 ++----------------- dom/base/Navigator.h | 5 +-- dom/base/test/mochitest.ini | 1 - dom/base/test/test_appname_override.html | 26 --------------- dom/base/test/test_navigatorPrefOverride.html | 11 +++---- dom/webidl/Navigator.webidl | 8 ++--- dom/workers/RuntimeService.cpp | 22 ------------- dom/workers/RuntimeService.h | 4 --- dom/workers/WorkerNavigator.cpp | 22 ------------- dom/workers/WorkerNavigator.h | 4 ++- dom/workers/test/test_bug1062920.html | 1 - dom/workers/test/test_bug1062920.xhtml | 3 -- modules/libpref/Preferences.cpp | 1 - .../test_resistfingerprinting_exempt.js | 26 +++++++-------- .../resistfingerprinting/RFPTargets.inc | 4 ++- .../resistfingerprinting/nsRFPService.h | 1 - 18 files changed, 39 insertions(+), 144 deletions(-) delete mode 100644 dom/base/test/test_appname_override.html diff --git a/browser/components/resistfingerprinting/test/browser/browser_navigator.js b/browser/components/resistfingerprinting/test/browser/browser_navigator.js index 934f84b69e7d1..7fef231467597 100644 --- a/browser/components/resistfingerprinting/test/browser/browser_navigator.js +++ b/browser/components/resistfingerprinting/test/browser/browser_navigator.js @@ -114,6 +114,7 @@ const CONST_PRODUCT = "Gecko"; const CONST_PRODUCTSUB = "20100101"; const CONST_VENDOR = ""; const CONST_VENDORSUB = ""; +const CONST_LEGACY_BUILD_ID = "20181001000000"; const appVersion = parseInt(Services.appinfo.version); const rvVersion = @@ -228,6 +229,11 @@ async function testNavigator() { CONST_APPNAME, "Navigator.appName reports correct constant value." ); + is( + result.buildID, + CONST_LEGACY_BUILD_ID, + "Navigator.buildID reports correct constant value." + ); is( result.product, CONST_PRODUCT, @@ -438,11 +444,11 @@ add_task(async function setupResistFingerprinting() { add_task(async function runOverrideTest() { await SpecialPowers.pushPrefEnv({ set: [ - ["general.appname.override", "appName overridden"], ["general.appversion.override", "appVersion overridden"], ["general.platform.override", "platform overridden"], ["general.useragent.override", "userAgent overridden"], ["general.oscpu.override", "oscpu overridden"], + ["general.buildID.override", "buildID overridden"], ], }); @@ -452,7 +458,7 @@ add_task(async function runOverrideTest() { await testUserAgentHeader(); - // Pop general.appname.override etc + // Pop general.appversion.override etc await SpecialPowers.popPrefEnv(); // Pop privacy.resistFingerprinting diff --git a/browser/components/resistfingerprinting/test/browser/file_navigator.html b/browser/components/resistfingerprinting/test/browser/file_navigator.html index 73029a21688cc..1ce49786c89c6 100644 --- a/browser/components/resistfingerprinting/test/browser/file_navigator.html +++ b/browser/components/resistfingerprinting/test/browser/file_navigator.html @@ -11,6 +11,7 @@ result.appCodeName = navigator.appCodeName; result.appName = navigator.appName; result.appVersion = navigator.appVersion; + result.buildID = navigator.buildID; result.platform = navigator.platform; result.userAgent = navigator.userAgent; result.product = navigator.product; diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index e856d68c61f22..cd6f5d5bf603c 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -307,11 +307,8 @@ void Navigator::GetAppVersion(nsAString& aAppVersion, CallerType aCallerType, } } -void Navigator::GetAppName(nsAString& aAppName, CallerType aCallerType) const { - nsCOMPtr doc = mWindow->GetExtantDoc(); - - AppName(aAppName, doc, - /* aUsePrefOverriddenValue = */ aCallerType != CallerType::System); +void Navigator::GetAppName(nsAString& aAppName) const { + aAppName.AssignLiteral("Netscape"); } /** @@ -2028,32 +2025,6 @@ nsresult Navigator::GetAppVersion(nsAString& aAppVersion, Document* aCallerDoc, return rv; } -/* static */ -void Navigator::AppName(nsAString& aAppName, Document* aCallerDoc, - bool aUsePrefOverriddenValue) { - MOZ_ASSERT(NS_IsMainThread()); - - if (aUsePrefOverriddenValue) { - // If fingerprinting resistance is on, we will spoof this value. See - // nsRFPService.h for details about spoofed values. - if (ShouldResistFingerprinting(aCallerDoc, RFPTarget::NavigatorAppName)) { - aAppName.AssignLiteral(SPOOFED_APPNAME); - return; - } - - nsAutoString override; - nsresult rv = - mozilla::Preferences::GetString("general.appname.override", override); - - if (NS_SUCCEEDED(rv)) { - aAppName = override; - return; - } - } - - aAppName.AssignLiteral("Netscape"); -} - void Navigator::ClearUserAgentCache() { Navigator_Binding::ClearCachedUserAgentValue(this); } diff --git a/dom/base/Navigator.h b/dom/base/Navigator.h index cbe8d6bb27eb7..f878c11dff3d4 100644 --- a/dom/base/Navigator.h +++ b/dom/base/Navigator.h @@ -107,7 +107,7 @@ class Navigator final : public nsISupports, public nsWrapperCache { void GetProduct(nsAString& aProduct); void GetLanguage(nsAString& aLanguage); - void GetAppName(nsAString& aAppName, CallerType aCallerType) const; + void GetAppName(nsAString& aAppName) const; void GetAppVersion(nsAString& aAppName, CallerType aCallerType, ErrorResult& aRv) const; void GetPlatform(nsAString& aPlatform, CallerType aCallerType, @@ -132,9 +132,6 @@ class Navigator final : public nsISupports, public nsWrapperCache { bool CanShare(const ShareData& aData); already_AddRefed Share(const ShareData& aData, ErrorResult& aRv); - static void AppName(nsAString& aAppName, Document* aCallerDoc, - bool aUsePrefOverriddenValue); - static nsresult GetPlatform(nsAString& aPlatform, Document* aCallerDoc, bool aUsePrefOverriddenValue); diff --git a/dom/base/test/mochitest.ini b/dom/base/test/mochitest.ini index 626ec35b4d424..e5cb465419610 100644 --- a/dom/base/test/mochitest.ini +++ b/dom/base/test/mochitest.ini @@ -268,7 +268,6 @@ skip-if = headless # Bug 1405867 [test_anonymousContent_insert.html] [test_anonymousContent_manipulate_content.html] [test_anonymousContent_style_csp.html] -[test_appname_override.html] [test_async_setTimeout_stack.html] [test_async_setTimeout_stack_across_globals.html] [test_base.xhtml] diff --git a/dom/base/test/test_appname_override.html b/dom/base/test/test_appname_override.html deleted file mode 100644 index bf1162a90083c..0000000000000 --- a/dom/base/test/test_appname_override.html +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - Test for Bug 939445 - general.appname.override - - - - -Mozilla Bug 939445 - - - diff --git a/dom/base/test/test_navigatorPrefOverride.html b/dom/base/test/test_navigatorPrefOverride.html index 478b14e7914a7..2d254adee2db3 100644 --- a/dom/base/test/test_navigatorPrefOverride.html +++ b/dom/base/test/test_navigatorPrefOverride.html @@ -15,19 +15,16 @@