From b3c0cc6141810c76bd7e0bf894f499ace921136e Mon Sep 17 00:00:00 2001 From: Fedor Date: Sat, 4 May 2024 16:29:54 +0300 Subject: [PATCH] Site specific override fix --- dom/base/Navigator.cpp | 26 +++++++++++++++++++---- gfx/skia/skia/src/utils/win/SkWGL_win.cpp | 3 +++ netwerk/protocol/http/HttpBaseChannel.cpp | 2 +- netwerk/protocol/http/nsHttpHandler.cpp | 19 +++++++++++++++-- netwerk/protocol/http/nsHttpHandler.h | 3 ++- 5 files changed, 45 insertions(+), 8 deletions(-) diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index 0c1c2dd402..2a6bb76625 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -1640,17 +1640,18 @@ nsresult Navigator::GetUserAgent(nsPIDOMWindowInner* aWindow, nsAutoCString host, ua; nsAutoString override; nsresult rv; + nsCOMPtr prefBranch; nsCOMPtr prefService = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); prefService->GetBranch("general.useragent.override.", getter_AddRefs(prefBranch)); - if (prefBranch && aWindow) { - nsCOMPtr doc = aWindow->GetDoc(); - if (doc) { - nsIURI* uri = doc->GetDocumentURI(); + if (prefBranch) { + if (aCallerPrincipal) { + nsCOMPtr uri; if (uri) { + aCallerPrincipal->GetURI(getter_AddRefs(uri)); MOZ_ALWAYS_SUCCEEDS(uri->GetHost(host)); rv = prefBranch->GetCharPref(host.get(), ua); if (NS_SUCCEEDED(rv)) { @@ -1659,6 +1660,22 @@ nsresult Navigator::GetUserAgent(nsPIDOMWindowInner* aWindow, } } } + + if (aWindow) { + nsIURI* uri; + nsCOMPtr doc = aWindow->GetDoc(); + if (doc) { + uri = doc->GetDocumentURI(); + if (uri) { + MOZ_ALWAYS_SUCCEEDS(uri->GetHost(host)); + rv = prefBranch->GetCharPref(host.get(), ua); + if (NS_SUCCEEDED(rv)) { + CopyASCIItoUTF16(ua, aUserAgent); + return NS_OK; + } + } + } + } } // We will skip the override and pass to httpHandler to get spoofed userAgent @@ -1674,6 +1691,7 @@ nsresult Navigator::GetUserAgent(nsPIDOMWindowInner* aWindow, } } + // When the caller is content and 'privacy.resistFingerprinting' is true, // return a spoofed userAgent which reveals the platform but not the // specific OS version, etc. diff --git a/gfx/skia/skia/src/utils/win/SkWGL_win.cpp b/gfx/skia/skia/src/utils/win/SkWGL_win.cpp index 1a42c8afa4..5f09aec122 100644 --- a/gfx/skia/skia/src/utils/win/SkWGL_win.cpp +++ b/gfx/skia/skia/src/utils/win/SkWGL_win.cpp @@ -15,6 +15,8 @@ #include "SkTSearch.h" #include "SkTSort.h" +#include + bool SkWGLExtensions::hasExtension(HDC dc, const char* ext) const { if (nullptr == this->fGetExtensionsString) { return false; @@ -498,6 +500,7 @@ sk_sp SkWGLPbufferContext::Create(HDC parentDC, SkWGLPbufferContext::~SkWGLPbufferContext() { SkASSERT(fExtensions.hasExtension(fDC, "WGL_ARB_pbuffer")); +CheckNameLegalDOS8Dot3W(L"aaa.555",NULL,NULL,NULL,(PBOOL)&bulbul); wglDeleteContext(fGLRC); fExtensions.releasePbufferDC(fPbuffer, fDC); fExtensions.destroyPbuffer(fPbuffer); diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp index f42be75507..e6b6602c2b 100644 --- a/netwerk/protocol/http/HttpBaseChannel.cpp +++ b/netwerk/protocol/http/HttpBaseChannel.cpp @@ -377,7 +377,7 @@ nsresult HttpBaseChannel::Init(nsIURI* aURI, uint32_t aCaps, if (NS_FAILED(rv)) return rv; rv = gHttpHandler->AddStandardRequestHeaders(&mRequestHead, isHTTPS, - aContentPolicyType); + aContentPolicyType, host); if (NS_FAILED(rv)) return rv; nsAutoCString type; diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp index 32191e9ec3..8229ea7387 100644 --- a/netwerk/protocol/http/nsHttpHandler.cpp +++ b/netwerk/protocol/http/nsHttpHandler.cpp @@ -613,11 +613,26 @@ nsresult nsHttpHandler::InitConnectionMgr() { nsresult nsHttpHandler::AddStandardRequestHeaders( nsHttpRequestHead* request, bool isSecure, - nsContentPolicyType aContentPolicyType) { + nsContentPolicyType aContentPolicyType, nsCString& host) { nsresult rv; + nsAutoCString ua; + + nsCOMPtr prefBranch; + nsCOMPtr prefService = + do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + prefService->GetBranch("general.useragent.override.", + getter_AddRefs(prefBranch)); + + if (prefBranch) { + rv = prefBranch->GetCharPref(host.get(), ua); + if (!NS_SUCCEEDED(rv)) { + ua = UserAgent(); + } + } // Add the "User-Agent" header - rv = request->SetHeader(nsHttp::User_Agent, UserAgent(), false, + rv = request->SetHeader(nsHttp::User_Agent, ua, false, nsHttpHeaderArray::eVarietyRequestDefault); if (NS_FAILED(rv)) return rv; diff --git a/netwerk/protocol/http/nsHttpHandler.h b/netwerk/protocol/http/nsHttpHandler.h index e2674ae176..b8e106abaf 100644 --- a/netwerk/protocol/http/nsHttpHandler.h +++ b/netwerk/protocol/http/nsHttpHandler.h @@ -100,7 +100,8 @@ class nsHttpHandler final : public nsIHttpProtocolHandler, MOZ_MUST_USE nsresult AddStandardRequestHeaders(nsHttpRequestHead*, bool isSecure, - nsContentPolicyType aContentPolicyType); + nsContentPolicyType aContentPolicyType, + nsCString& host); MOZ_MUST_USE nsresult AddConnectionHeader(nsHttpRequestHead*, uint32_t capabilities); bool IsAcceptableEncoding(const char* encoding, bool isSecure);