morgan pushed to branch base-browser-115.16.0esr-13.5-1 at The Tor Project / Applications / Tor Browser
Commits:
-
bd216fff
by Pier Angelo Vendrame at 2024-10-16T22:27:14+00:00
2 changed files:
Changes:
... | ... | @@ -497,6 +497,9 @@ nsresult nsHttpHandler::Init() { |
497 | 497 | // obsService->AddObserver(this, "net:failed-to-process-uri-content", true);
|
498 | 498 | }
|
499 | 499 | |
500 | + Preferences::AddWeakObserver(
|
|
501 | + this, "privacy.resistFingerprinting.spoofOsInUserAgentHeader"_ns);
|
|
502 | + |
|
500 | 503 | MakeNewRequestTokenBucket();
|
501 | 504 | mWifiTickler = new Tickler();
|
502 | 505 | if (NS_FAILED(mWifiTickler->Init())) mWifiTickler = nullptr;
|
... | ... | @@ -2064,6 +2067,9 @@ nsHttpHandler::Observe(nsISupports* subject, const char* topic, |
2064 | 2067 | // Inform nsIOService that network is tearing down.
|
2065 | 2068 | gIOService->SetHttpHandlerAlreadyShutingDown();
|
2066 | 2069 | |
2070 | + Preferences::RemoveObserver(
|
|
2071 | + this, "privacy.resistFingerprinting.spoofOsInUserAgentHeader"_ns);
|
|
2072 | + |
|
2067 | 2073 | ShutdownConnectionManager();
|
2068 | 2074 | |
2069 | 2075 | // need to reset the session start time since cache validation may
|
... | ... | @@ -2189,6 +2195,11 @@ nsHttpHandler::Observe(nsISupports* subject, const char* topic, |
2189 | 2195 | ShutdownConnectionManager();
|
2190 | 2196 | mConnMgr = nullptr;
|
2191 | 2197 | Unused << InitConnectionMgr();
|
2198 | + } else if (!strcmp(topic, "nsPref:changed") &&
|
|
2199 | + !NS_strcmp(
|
|
2200 | + data,
|
|
2201 | + u"privacy.resistFingerprinting.spoofOsInUserAgentHeader")) {
|
|
2202 | + nsRFPService::GetSpoofedUserAgent(mSpoofedUserAgent, true);
|
|
2192 | 2203 | }
|
2193 | 2204 | |
2194 | 2205 | return NS_OK;
|
... | ... | @@ -939,12 +939,17 @@ void nsRFPService::GetSpoofedUserAgent(nsACString& userAgent, |
939 | 939 | // https://developer.mozilla.org/en-US/docs/Web/API/NavigatorID/userAgent
|
940 | 940 | // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent
|
941 | 941 | |
942 | + const bool spoofOs =
|
|
943 | + isForHTTPHeader &&
|
|
944 | + Preferences::GetBool(
|
|
945 | + "privacy.resistFingerprinting.spoofOsInUserAgentHeader", true);
|
|
946 | + |
|
942 | 947 | // These magic numbers are the lengths of the UA string literals below.
|
943 | 948 | // Assume three-digit Firefox version numbers so we have room to grow.
|
944 | 949 | size_t preallocatedLength =
|
945 | 950 | 13 +
|
946 | - (isForHTTPHeader ? mozilla::ArrayLength(SPOOFED_HTTP_UA_OS)
|
|
947 | - : mozilla::ArrayLength(SPOOFED_UA_OS)) -
|
|
951 | + (spoofOs ? mozilla::ArrayLength(SPOOFED_HTTP_UA_OS)
|
|
952 | + : mozilla::ArrayLength(SPOOFED_UA_OS)) -
|
|
948 | 953 | 1 + 5 + 3 + 10 + mozilla::ArrayLength(LEGACY_UA_GECKO_TRAIL) - 1 + 9 + 3 +
|
949 | 954 | 2;
|
950 | 955 | userAgent.SetCapacity(preallocatedLength);
|
... | ... | @@ -954,7 +959,7 @@ void nsRFPService::GetSpoofedUserAgent(nsACString& userAgent, |
954 | 959 | // "Mozilla/5.0 (%s; rv:%d.0) Gecko/%d Firefox/%d.0"
|
955 | 960 | userAgent.AssignLiteral("Mozilla/5.0 (");
|
956 | 961 | |
957 | - if (isForHTTPHeader) {
|
|
962 | + if (spoofOs) {
|
|
958 | 963 | userAgent.AppendLiteral(SPOOFED_HTTP_UA_OS);
|
959 | 964 | } else {
|
960 | 965 | userAgent.AppendLiteral(SPOOFED_UA_OS);
|