From 7586806f59e4853da8d38dc6d0556bc5114e35ee Mon Sep 17 00:00:00 2001 From: Mike Perry Date: Tue, 10 Sep 2013 17:00:27 -0700 Subject: [PATCH] Bug #5741: Prevent WebSocket DNS leak. This is due to an improper implementation of the WebSocket spec by Mozilla. "There MUST be no more than one connection in a CONNECTING state. If multiple connections to the same IP address are attempted simultaneously, the client MUST serialize them so that there is no more than one connection at a time running through the following steps. If the client cannot determine the IP address of the remote host (for example, because all communication is being done through a proxy server that performs DNS queries itself), then the client MUST assume for the purposes of this step that each host name refers to a distinct remote host," https://tools.ietf.org/html/rfc6455#page-15 They implmented the first paragraph, but not the second... While we're at it, we also prevent the DNS service from being used to look up anything other than IP addresses if socks_remote_dns is set to true, so this bug can't turn up in other components or due to 3rd party addons. --- netwerk/dns/nsDNSService2.cpp | 25 ++++++++++++++++++++++++- netwerk/dns/nsDNSService2.h | 1 + 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/netwerk/dns/nsDNSService2.cpp b/netwerk/dns/nsDNSService2.cpp index 19958a56515b3..d091afc15fcbe 100644 --- a/netwerk/dns/nsDNSService2.cpp +++ b/netwerk/dns/nsDNSService2.cpp @@ -510,6 +510,7 @@ nsDNSService::Init() { bool disableIPv6 = false; bool offlineLocalhost = true; bool disablePrefetch = false; + bool disableDNS = false; bool blockDotOnion = true; int proxyType = nsIProtocolProxyService::PROXYCONFIG_DIRECT; bool notifyResolution = false; @@ -540,6 +541,11 @@ nsDNSService::Init() { // If a manual proxy is in use, disable prefetch implicitly prefs->GetIntPref("network.proxy.type", &proxyType); + + // If the user wants remote DNS, we should fail any lookups that still + // make it here. + prefs->GetBoolPref("network.proxy.socks_remote_dns", &disableDNS); + prefs->GetBoolPref(kPrefDnsNotifyResolution, ¬ifyResolution); if (mFirstTime) { @@ -560,7 +566,7 @@ nsDNSService::Init() { // Monitor these to see if there is a change in proxy configuration // If a manual proxy is in use, disable prefetch implicitly - prefs->AddObserver("network.proxy.type", this, false); + prefs->AddObserver("network.proxy.", this, false); } } @@ -586,6 +592,7 @@ nsDNSService::Init() { mIPv4OnlyDomains = ipv4OnlyDomains; mOfflineLocalhost = offlineLocalhost; mDisableIPv6 = disableIPv6; + mDisableDNS = disableDNS; mBlockDotOnion = blockDotOnion; mForceResolve = forceResolve; mForceResolveOn = !mForceResolve.IsEmpty(); @@ -778,6 +785,14 @@ nsDNSService::AsyncResolveExtendedNative( NS_DispatchToMainThread(new NotifyDNSResolution(aHostname)); } + PRNetAddr tempAddr; + if (mDisableDNS) { + // Allow IP lookups through, but nothing else. + if (PR_StringToNetAddr(aHostname.BeginReading(), &tempAddr) != PR_SUCCESS) { + return NS_ERROR_UNKNOWN_PROXY_HOST; // XXX: NS_ERROR_NOT_IMPLEMENTED? + } + } + if (!res) return NS_ERROR_OFFLINE; nsCString hostname; @@ -960,6 +975,14 @@ nsresult nsDNSService::ResolveInternal( flags |= RESOLVE_OFFLINE; } + PRNetAddr tempAddr; + if (mDisableDNS) { + // Allow IP lookups through, but nothing else. + if (PR_StringToNetAddr(aHostname.BeginReading(), &tempAddr) != PR_SUCCESS) { + return NS_ERROR_UNKNOWN_PROXY_HOST; // XXX: NS_ERROR_NOT_IMPLEMENTED? + } + } + // // sync resolve: since the host resolver only works asynchronously, we need // to use a mutex and a condvar to wait for the result. however, since the diff --git a/netwerk/dns/nsDNSService2.h b/netwerk/dns/nsDNSService2.h index 141e4fc939d62..cb4f2f7e28fcb 100644 --- a/netwerk/dns/nsDNSService2.h +++ b/netwerk/dns/nsDNSService2.h @@ -77,6 +77,7 @@ class nsDNSService final : public nsPIDNSService, bool mDisablePrefetch; bool mBlockDotOnion; bool mFirstTime; + bool mDisableDNS; bool mNotifyResolution; bool mOfflineLocalhost; bool mForceResolveOn; -- GitLab