Skip to content

Commit

Permalink
Bug 1843841 - Make navigator.appName constant. r=dom-worker-reviewers…
Browse files Browse the repository at this point in the history
…,webidl,smaug,timhuang

This is supposed to constant per https://html.spec.whatwg.org/#client-identification.

Differential Revision: https://phabricator.services.mozilla.com/D183723
  • Loading branch information
Tom Schuster committed Jul 19, 2023
1 parent 584ea48 commit 7906e7f
Show file tree
Hide file tree
Showing 18 changed files with 39 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"],
],
});

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 2 additions & 31 deletions dom/base/Navigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,8 @@ void Navigator::GetAppVersion(nsAString& aAppVersion, CallerType aCallerType,
}
}

void Navigator::GetAppName(nsAString& aAppName, CallerType aCallerType) const {
nsCOMPtr<Document> doc = mWindow->GetExtantDoc();

AppName(aAppName, doc,
/* aUsePrefOverriddenValue = */ aCallerType != CallerType::System);
void Navigator::GetAppName(nsAString& aAppName) const {
aAppName.AssignLiteral("Netscape");
}

/**
Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 1 addition & 4 deletions dom/base/Navigator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -132,9 +132,6 @@ class Navigator final : public nsISupports, public nsWrapperCache {
bool CanShare(const ShareData& aData);
already_AddRefed<Promise> Share(const ShareData& aData, ErrorResult& aRv);

static void AppName(nsAString& aAppName, Document* aCallerDoc,
bool aUsePrefOverriddenValue);

static nsresult GetPlatform(nsAString& aPlatform, Document* aCallerDoc,
bool aUsePrefOverriddenValue);

Expand Down
1 change: 0 additions & 1 deletion dom/base/test/mochitest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
26 changes: 0 additions & 26 deletions dom/base/test/test_appname_override.html

This file was deleted.

11 changes: 4 additions & 7 deletions dom/base/test/test_navigatorPrefOverride.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,27 @@
<pre id="test"></pre>
<script class="testbody" type="text/javascript">

ok(navigator.appName, "This is used just to populate the cache");
ok(navigator.appVersion, "This is used just to populate the cache");

// B2G could have an empty platform.
info(navigator.platform);

ok(navigator.platform, "This is used just to populate the cache");
ok(navigator.userAgent, "This is used just to populate the cache");
ok(navigator.buildID, "This is used just to populate the cache");

SpecialPowers.pushPrefEnv({"set": [
["general.appname.override", "appName overridden"],
["general.appversion.override", "appVersion overridden"],
["general.platform.override", "platform overridden"],
["general.useragent.override", "userAgent overridden"],
["general.buildID.override", "buildID overridden"],
]},
function() {
var ifr = document.createElement('IFRAME');
ifr.src = "about:blank";

ifr.addEventListener('load', function() {
var nav = ifr.contentWindow.navigator;
isnot(navigator.appName, nav.appName, "appName should match");
isnot(navigator.appVersion, nav.appVersion, "appVersion should match");
isnot(navigator.platform, nav.platform, "platform should match");
isnot(navigator.userAgent, nav.userAgent, "userAgent should match");
isnot(navigator.buildID, nav.buildID, "buildID should match");
SimpleTest.finish();
});

Expand Down
8 changes: 4 additions & 4 deletions dom/webidl/Navigator.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* The origin of this IDL file is
* http://www.whatwg.org/specs/web-apps/current-work/#the-navigator-object
* https://html.spec.whatwg.org/#the-navigator-object
* http://www.w3.org/TR/tracking-dnt/
* http://www.w3.org/TR/geolocation-API/#geolocation_interface
* http://www.w3.org/TR/battery-status/#navigatorbattery-interface
Expand All @@ -26,7 +26,7 @@

interface URI;

// http://www.whatwg.org/specs/web-apps/current-work/#the-navigator-object
// https://html.spec.whatwg.org/#the-navigator-object
[HeaderFile="Navigator.h",
Exposed=Window]
interface Navigator {
Expand All @@ -47,8 +47,8 @@ interface mixin NavigatorID {
// WebKit/Blink/Trident/Presto support this (hardcoded "Mozilla").
[Constant, Cached, Throws]
readonly attribute DOMString appCodeName; // constant "Mozilla"
[Constant, Cached, NeedsCallerType]
readonly attribute DOMString appName;
[Constant, Cached]
readonly attribute DOMString appName; // constant "Netscape"
[Constant, Cached, Throws, NeedsCallerType]
readonly attribute DOMString appVersion;
[Pure, Cached, Throws, NeedsCallerType]
Expand Down
22 changes: 0 additions & 22 deletions dom/workers/RuntimeService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -992,18 +992,6 @@ void PrefLanguagesChanged(const char* /* aPrefName */, void* /* aClosure */) {
}
}

void AppNameOverrideChanged(const char* /* aPrefName */, void* /* aClosure */) {
AssertIsOnMainThread();

nsAutoString override;
Preferences::GetString("general.appname.override", override);

RuntimeService* runtime = RuntimeService::GetService();
if (runtime) {
runtime->UpdateAppNameOverridePreference(override);
}
}

void AppVersionOverrideChanged(const char* /* aPrefName */,
void* /* aClosure */) {
AssertIsOnMainThread();
Expand Down Expand Up @@ -1172,9 +1160,6 @@ bool RuntimeService::RegisterWorker(WorkerPrivate& aWorkerPrivate) {
}
} else {
if (!mNavigatorPropertiesLoaded) {
Navigator::AppName(mNavigatorProperties.mAppName,
aWorkerPrivate.GetDocument(),
false /* aUsePrefOverriddenValue */);
if (NS_FAILED(Navigator::GetAppVersion(
mNavigatorProperties.mAppVersion, aWorkerPrivate.GetDocument(),
false /* aUsePrefOverriddenValue */)) ||
Expand Down Expand Up @@ -1407,7 +1392,6 @@ nsresult RuntimeService::Init() {
LoadGCZealOptions, PREF_JS_OPTIONS_PREFIX PREF_GCZEAL)) ||
#endif
WORKER_PREF("intl.accept_languages", PrefLanguagesChanged) ||
WORKER_PREF("general.appname.override", AppNameOverrideChanged) ||
WORKER_PREF("general.appversion.override", AppVersionOverrideChanged) ||
WORKER_PREF("general.platform.override", PlatformOverrideChanged) ||
NS_FAILED(Preferences::RegisterPrefixCallbackAndCall(
Expand Down Expand Up @@ -1657,7 +1641,6 @@ void RuntimeService::Cleanup() {
if (NS_FAILED(Preferences::UnregisterPrefixCallback(
LoadContextOptions, PREF_JS_OPTIONS_PREFIX)) ||
WORKER_PREF("intl.accept_languages", PrefLanguagesChanged) ||
WORKER_PREF("general.appname.override", AppNameOverrideChanged) ||
WORKER_PREF("general.appversion.override", AppVersionOverrideChanged) ||
WORKER_PREF("general.platform.override", PlatformOverrideChanged) ||
#ifdef JS_GC_ZEAL
Expand Down Expand Up @@ -1815,11 +1798,6 @@ void RuntimeService::UpdateAllWorkerContextOptions() {
});
}

void RuntimeService::UpdateAppNameOverridePreference(const nsAString& aValue) {
AssertIsOnMainThread();
mNavigatorProperties.mAppNameOverridden = aValue;
}

void RuntimeService::UpdateAppVersionOverridePreference(
const nsAString& aValue) {
AssertIsOnMainThread();
Expand Down
4 changes: 0 additions & 4 deletions dom/workers/RuntimeService.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ class RuntimeService final : public nsIObserver {

public:
struct NavigatorProperties {
nsString mAppName;
nsString mAppNameOverridden;
nsString mAppVersion;
nsString mAppVersionOverridden;
nsString mPlatform;
Expand Down Expand Up @@ -125,8 +123,6 @@ class RuntimeService final : public nsIObserver {
sDefaultJSSettings->contextOptions = aContextOptions;
}

void UpdateAppNameOverridePreference(const nsAString& aValue);

void UpdateAppVersionOverridePreference(const nsAString& aValue);

void UpdatePlatformOverridePreference(const nsAString& aValue);
Expand Down
22 changes: 0 additions & 22 deletions dom/workers/WorkerNavigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,6 @@ void WorkerNavigator::SetLanguages(const nsTArray<nsString>& aLanguages) {
mProperties.mLanguages = aLanguages.Clone();
}

void WorkerNavigator::GetAppName(nsString& aAppName,
CallerType aCallerType) const {
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(workerPrivate);

if (aCallerType != CallerType::System) {
if (workerPrivate->ShouldResistFingerprinting(
RFPTarget::NavigatorAppName)) {
// See nsRFPService.h for spoofed value.
aAppName.AssignLiteral(SPOOFED_APPNAME);
return;
}

if (!mProperties.mAppNameOverridden.IsEmpty()) {
aAppName = mProperties.mAppNameOverridden;
return;
}
}

aAppName = mProperties.mAppName;
}

void WorkerNavigator::GetAppVersion(nsString& aAppVersion,
CallerType aCallerType,
ErrorResult& aRv) const {
Expand Down
4 changes: 3 additions & 1 deletion dom/workers/WorkerNavigator.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ class WorkerNavigator final : public nsWrapperCache {
void GetAppCodeName(nsString& aAppCodeName, ErrorResult& /* unused */) const {
aAppCodeName.AssignLiteral("Mozilla");
}
void GetAppName(nsString& aAppName, CallerType aCallerType) const;
void GetAppName(nsString& aAppName) const {
aAppName.AssignLiteral("Netscape");
}

void GetAppVersion(nsString& aAppVersion, CallerType aCallerType,
ErrorResult& aRv) const;
Expand Down
1 change: 0 additions & 1 deletion dom/workers/test/test_bug1062920.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

function replaceAndCheckValues() {
SpecialPowers.pushPrefEnv({"set": [
["general.appname.override", "appName overridden"],
["general.appversion.override", "appVersion overridden"],
["general.platform.override", "platform overridden"],
["general.useragent.override", "userAgent overridden"]
Expand Down
3 changes: 0 additions & 3 deletions dom/workers/test/test_bug1062920.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

worker.onmessage = function(event) {
is(event.data.appCodeName, navigator.appCodeName, "appCodeName should match");
is(event.data.appName, navigator.appName, "appName should match");
isnot(event.data.appName, "appName overridden", "appName is not overridden");
is(event.data.appVersion, navigator.appVersion, "appVersion should match");
isnot(event.data.appVersion, "appVersion overridden", "appVersion is not overridden");
is(event.data.platform, navigator.platform, "platform should match");
Expand All @@ -31,7 +29,6 @@

function replaceAndCheckValues() {
SpecialPowers.pushPrefEnv({"set": [
["general.appname.override", "appName overridden"],
["general.appversion.override", "appVersion overridden"],
["general.platform.override", "platform overridden"],
["general.useragent.override", "userAgent overridden"]
Expand Down
1 change: 0 additions & 1 deletion modules/libpref/Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6110,7 +6110,6 @@ static const PrefListEntry sDynamicPrefOverrideList[]{
PREF_LIST_ENTRY("extensions.foobaz"),
PREF_LIST_ENTRY(
"extensions.formautofill.creditCards.heuristics.testConfidence"),
PREF_LIST_ENTRY("general.appname.override"),
PREF_LIST_ENTRY("general.appversion.override"),
PREF_LIST_ENTRY("general.buildID.override"),
PREF_LIST_ENTRY("general.oscpu.override"),
Expand Down
Loading

0 comments on commit 7906e7f

Please sign in to comment.