Bug 1753805 - Add pref for enterprise users to override the User-Agent string's Firefox version. r=necko-reviewers,valentin

Firefox version 100 will ship on 2022-05-03. The Webcompat team can use Firefox's site interventions to spoof a version 99 UA for individual sites broken by a three-digit version number. But Firefox’s site interventions can’t override the UA for enterprise intranet sites we don't know about.

This patch adds a new "network.http.useragent.forceVersion" pref that enterprise admins can set to a known-good UA version (like 99) in an enterprise policy file. If the pref has a non-zero value, then override the User-Agent string's Firefox version. The value 0 means use the default Firefox version.

We can remove this pref in Firefox 103 after the next ESR is branched (version 102 on 2022-06-28). Enterprise users can use ESR 102 with forceVersion pref = 99 until the next ESR in mid-2023. Hopefully they can fix their broken intranet sites by that time.

Differential Revision: https://phabricator.services.mozilla.com/D137929
This commit is contained in:
Chris Peterson 2022-02-08 05:03:10 +00:00
Родитель 820821f476
Коммит a0c975962b
2 изменённых файлов: 37 добавлений и 3 удалений

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

@ -9883,6 +9883,16 @@
value: true
mirror: always
# Set this pref to an integer like 99 to override the User-Agent string's
# Firefox version. The value 0 means use the default Firefox version. If
# enterprise users rely on sites that aren't compatible with Firefox version
# 100's three-digit version number, enterprise admins can set this pref to a
# known-good version (like 99) in an enterprise policy file.
- name: network.http.useragent.forceVersion
type: uint32_t
value: 0
mirror: always
# Whether or not we use Windows for SSO to Microsoft sites.
- name: network.http.windows-sso.enabled
type: RelaxedAtomicBool

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

@ -341,6 +341,25 @@ static const char* gCallbackPrefs[] = {
nullptr,
};
static void GetFirefoxVersionForUserAgent(nsACString& aVersion) {
// If the "network.http.useragent.forceVersion" pref has a non-zero value,
// then override the User-Agent string's Firefox version. The value 0 means
// use the default Firefox version. If enterprise users rely on sites that
// aren't compatible with Firefox version 100's three-digit version number,
// enterprise admins can set this pref to a known-good version (like 99) in an
// enterprise policy file.
uint32_t forceVersion =
mozilla::StaticPrefs::network_http_useragent_forceVersion();
if (forceVersion == 0) {
// Use the default Firefox version.
aVersion.AssignLiteral(MOZILLA_UAVERSION);
} else {
// Use the pref's version.
aVersion.AppendInt(forceVersion);
aVersion.AppendLiteral(".0");
}
}
nsresult nsHttpHandler::Init() {
nsresult rv;
@ -423,9 +442,14 @@ nsresult nsHttpHandler::Init() {
Telemetry::ScalarSet(Telemetry::ScalarID::NETWORKING_HTTP3_ENABLED,
StaticPrefs::network_http_http3_enable());
mMisc.AssignLiteral("rv:" MOZILLA_UAVERSION);
nsAutoCString uaVersion;
GetFirefoxVersionForUserAgent(uaVersion);
mCompatFirefox.AssignLiteral("Firefox/" MOZILLA_UAVERSION);
mMisc.AssignLiteral("rv:");
mMisc.Append(uaVersion);
mCompatFirefox.AssignLiteral("Firefox/");
mCompatFirefox.Append(uaVersion);
nsCOMPtr<nsIXULAppInfo> appInfo =
do_GetService("@mozilla.org/xre/app-info;1");
@ -457,7 +481,7 @@ nsresult nsHttpHandler::Init() {
mRequestContextService = RequestContextService::GetOrCreate();
#if defined(ANDROID)
mProductSub.AssignLiteral(MOZILLA_UAVERSION);
mProductSub.Assign(uaVersion);
#else
mProductSub.AssignLiteral(LEGACY_UA_GECKO_TRAIL);
#endif