Bug 1811863 - Make WorkerNavigator use more precise RFP check. r=dom-worker-reviewers,smaug

This refactors the code to be closer to the main-thread Navigator implementation, but
the new CallerType and old workerPrivate->UsesSystemPrincipal() is functionally identical.

Differential Revision: https://phabricator.services.mozilla.com/D167821
This commit is contained in:
Tom Schuster 2023-01-27 14:08:58 +00:00
Родитель 49eb23edff
Коммит 29918f4073
1 изменённых файлов: 39 добавлений и 31 удалений

Просмотреть файл

@ -21,7 +21,6 @@
#include "mozilla/dom/WorkerNavigatorBinding.h" #include "mozilla/dom/WorkerNavigatorBinding.h"
#include "mozilla/dom/WorkerStatus.h" #include "mozilla/dom/WorkerStatus.h"
#include "mozilla/dom/network/Connection.h" #include "mozilla/dom/network/Connection.h"
#include "mozilla/StaticPrefs_privacy.h"
#include "mozilla/webgpu/Instance.h" #include "mozilla/webgpu/Instance.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsDebug.h" #include "nsDebug.h"
@ -102,17 +101,20 @@ void WorkerNavigator::GetAppName(nsString& aAppName,
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate(); WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(workerPrivate); MOZ_ASSERT(workerPrivate);
if ((!mProperties.mAppNameOverridden.IsEmpty() || if (aCallerType != CallerType::System) {
StaticPrefs::privacy_resistFingerprinting()) && if (workerPrivate->GlobalScope()->ShouldResistFingerprinting()) {
!workerPrivate->UsesSystemPrincipal()) { // See nsRFPService.h for spoofed value.
// We will spoof this value when 'privacy.resistFingerprinting' is true. aAppName.AssignLiteral(SPOOFED_APPNAME);
// See nsRFPService.h for spoofed value. return;
aAppName = StaticPrefs::privacy_resistFingerprinting() }
? NS_LITERAL_STRING_FROM_CSTRING(SPOOFED_APPNAME)
: mProperties.mAppNameOverridden; if (!mProperties.mAppNameOverridden.IsEmpty()) {
} else { aAppName = mProperties.mAppNameOverridden;
aAppName = mProperties.mAppName; return;
}
} }
aAppName = mProperties.mAppName;
} }
void WorkerNavigator::GetAppVersion(nsString& aAppVersion, void WorkerNavigator::GetAppVersion(nsString& aAppVersion,
@ -121,17 +123,20 @@ void WorkerNavigator::GetAppVersion(nsString& aAppVersion,
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate(); WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(workerPrivate); MOZ_ASSERT(workerPrivate);
if ((!mProperties.mAppVersionOverridden.IsEmpty() || if (aCallerType != CallerType::System) {
StaticPrefs::privacy_resistFingerprinting()) && if (workerPrivate->GlobalScope()->ShouldResistFingerprinting()) {
!workerPrivate->UsesSystemPrincipal()) { // See nsRFPService.h for spoofed value.
// We will spoof this value when 'privacy.resistFingerprinting' is true. aAppVersion.AssignLiteral(SPOOFED_APPVERSION);
// See nsRFPService.h for spoofed value. return;
aAppVersion = StaticPrefs::privacy_resistFingerprinting() }
? NS_LITERAL_STRING_FROM_CSTRING(SPOOFED_APPVERSION)
: mProperties.mAppVersionOverridden; if (!mProperties.mAppVersionOverridden.IsEmpty()) {
} else { aAppVersion = mProperties.mAppVersionOverridden;
aAppVersion = mProperties.mAppVersion; return;
}
} }
aAppVersion = mProperties.mAppVersion;
} }
void WorkerNavigator::GetPlatform(nsString& aPlatform, CallerType aCallerType, void WorkerNavigator::GetPlatform(nsString& aPlatform, CallerType aCallerType,
@ -139,17 +144,20 @@ void WorkerNavigator::GetPlatform(nsString& aPlatform, CallerType aCallerType,
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate(); WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(workerPrivate); MOZ_ASSERT(workerPrivate);
if ((!mProperties.mPlatformOverridden.IsEmpty() || if (aCallerType != CallerType::System) {
StaticPrefs::privacy_resistFingerprinting()) && if (workerPrivate->GlobalScope()->ShouldResistFingerprinting()) {
!workerPrivate->UsesSystemPrincipal()) { // See nsRFPService.h for spoofed value.
// We will spoof this value when 'privacy.resistFingerprinting' is true. aPlatform.AssignLiteral(SPOOFED_PLATFORM);
// See nsRFPService.h for spoofed value. return;
aPlatform = StaticPrefs::privacy_resistFingerprinting() }
? NS_LITERAL_STRING_FROM_CSTRING(SPOOFED_PLATFORM)
: mProperties.mPlatformOverridden; if (!mProperties.mPlatformOverridden.IsEmpty()) {
} else { aPlatform = mProperties.mPlatformOverridden;
aPlatform = mProperties.mPlatform; return;
}
} }
aPlatform = mProperties.mPlatform;
} }
namespace { namespace {