summary refs log tree commit diff
path: root/synapse/http/client.py
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2019-05-14 11:12:22 +0100
committerRichard van der Hoff <richard@matrix.org>2019-05-14 11:12:22 +0100
commit9feee29d76555de7c2720ac661e7d9106dc51be3 (patch)
treef52c39344606d29b6876f3ca916323e11fd83d6d /synapse/http/client.py
parentMerge commit 'a845abbf3' into matrix-org-hotfixes (diff)
parent0.99.4rc1 (diff)
downloadsynapse-9feee29d76555de7c2720ac661e7d9106dc51be3.tar.xz
Merge tag 'v0.99.4rc1' into matrix-org-hotfixes
v0.99.4rc1
Diffstat (limited to 'synapse/http/client.py')
-rw-r--r--synapse/http/client.py45
1 files changed, 25 insertions, 20 deletions
diff --git a/synapse/http/client.py b/synapse/http/client.py

index ad454f4964..ddbfb72228 100644 --- a/synapse/http/client.py +++ b/synapse/http/client.py
@@ -90,45 +90,50 @@ class IPBlacklistingResolver(object): def resolveHostName(self, recv, hostname, portNumber=0): r = recv() - d = defer.Deferred() addresses = [] - @provider(IResolutionReceiver) - class EndpointReceiver(object): - @staticmethod - def resolutionBegan(resolutionInProgress): - pass + def _callback(): + r.resolutionBegan(None) - @staticmethod - def addressResolved(address): - ip_address = IPAddress(address.host) + has_bad_ip = False + for i in addresses: + ip_address = IPAddress(i.host) if check_against_blacklist( ip_address, self._ip_whitelist, self._ip_blacklist ): logger.info( - "Dropped %s from DNS resolution to %s" % (ip_address, hostname) + "Dropped %s from DNS resolution to %s due to blacklist" % + (ip_address, hostname) ) - raise SynapseError(403, "IP address blocked by IP blacklist entry") + has_bad_ip = True + + # if we have a blacklisted IP, we'd like to raise an error to block the + # request, but all we can really do from here is claim that there were no + # valid results. + if not has_bad_ip: + for i in addresses: + r.addressResolved(i) + r.resolutionComplete() + @provider(IResolutionReceiver) + class EndpointReceiver(object): + @staticmethod + def resolutionBegan(resolutionInProgress): + pass + + @staticmethod + def addressResolved(address): addresses.append(address) @staticmethod def resolutionComplete(): - d.callback(addresses) + _callback() self._reactor.nameResolver.resolveHostName( EndpointReceiver, hostname, portNumber=portNumber ) - def _callback(addrs): - r.resolutionBegan(None) - for i in addrs: - r.addressResolved(i) - r.resolutionComplete() - - d.addCallback(_callback) - return r