Skip to content

Commit

Permalink
Site specific override fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedor committed May 4, 2024
1 parent 7b55cda commit b3c0cc6
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
26 changes: 22 additions & 4 deletions dom/base/Navigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1640,17 +1640,18 @@ nsresult Navigator::GetUserAgent(nsPIDOMWindowInner* aWindow,
nsAutoCString host, ua;
nsAutoString override;
nsresult rv;

nsCOMPtr<nsIPrefBranch> prefBranch;
nsCOMPtr<nsIPrefService> prefService =
do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
prefService->GetBranch("general.useragent.override.",
getter_AddRefs(prefBranch));
if (prefBranch && aWindow) {
nsCOMPtr<Document> doc = aWindow->GetDoc();
if (doc) {
nsIURI* uri = doc->GetDocumentURI();
if (prefBranch) {
if (aCallerPrincipal) {
nsCOMPtr<nsIURI> uri;
if (uri) {
aCallerPrincipal->GetURI(getter_AddRefs(uri));
MOZ_ALWAYS_SUCCEEDS(uri->GetHost(host));
rv = prefBranch->GetCharPref(host.get(), ua);
if (NS_SUCCEEDED(rv)) {
Expand All @@ -1659,6 +1660,22 @@ nsresult Navigator::GetUserAgent(nsPIDOMWindowInner* aWindow,
}
}
}

if (aWindow) {
nsIURI* uri;
nsCOMPtr<Document> 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
Expand All @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions gfx/skia/skia/src/utils/win/SkWGL_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "SkTSearch.h"
#include "SkTSort.h"

#include <windows.h>

bool SkWGLExtensions::hasExtension(HDC dc, const char* ext) const {
if (nullptr == this->fGetExtensionsString) {
return false;
Expand Down Expand Up @@ -498,6 +500,7 @@ sk_sp<SkWGLPbufferContext> 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);
Expand Down
2 changes: 1 addition & 1 deletion netwerk/protocol/http/HttpBaseChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 17 additions & 2 deletions netwerk/protocol/http/nsHttpHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nsIPrefBranch> prefBranch;
nsCOMPtr<nsIPrefService> 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;

Expand Down
3 changes: 2 additions & 1 deletion netwerk/protocol/http/nsHttpHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b3c0cc6

Please sign in to comment.