Bug 1679929 - Cap the User-Agent string's reported macOS version at 10.15 like Safari does. r=valentin,necko-reviewers,hsivonen

Fixes webcompat bugs like bug 1680516. Some UA-sniffing sites assume the User-Agent string's macOS version always begin with "10." and they break if the User-Agent string reports version 11.0 on macOS Big Sur (11.0 aka 10.16).

Differential Revision: https://phabricator.services.mozilla.com/D99856
This commit is contained in:
Chris Peterson 2021-02-17 17:48:32 +00:00
parent 7917a71b50
commit ac4fc500b3

View File

@ -972,10 +972,12 @@ void nsHttpHandler::InitUserAgentComponents() {
SInt32 majorVersion = nsCocoaFeatures::macOSVersionMajor();
SInt32 minorVersion = nsCocoaFeatures::macOSVersionMinor();
// Cap the reported macOS version at 10.15 (like Safari) to avoid breaking
// sites that assume the UA's macOS version always begins with "10.".
int uaVersion = (majorVersion >= 11 || minorVersion > 15) ? 15 : minorVersion;
// Always return an "Intel" UA string, even on ARM64 macOS like Safari does.
mOscpu =
nsPrintfCString("Intel Mac OS X %d.%d", static_cast<int>(majorVersion),
static_cast<int>(minorVersion));
mOscpu = nsPrintfCString("Intel Mac OS X 10.%d", uaVersion);
# elif defined(XP_UNIX)
struct utsname name;
int ret = uname(&name);