Skip to content

Commit

Permalink
network: harden against eclipse attacks
Browse files Browse the repository at this point in the history
  • Loading branch information
SomberNight committed Jun 27, 2019
1 parent baa0293 commit a2bffb9
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions electrum/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,20 +476,26 @@ def get_interfaces(self) -> List[str]:

@with_recent_servers_lock
def get_servers(self):
# start with hardcoded servers
out = dict(constants.net.DEFAULT_SERVERS) # copy
# note: order of sources when adding servers here is crucial!
# don't let "server_peers" overwrite anything,
# otherwise main server can eclipse the client
out = dict()
# add servers received from main interface
server_peers = self.server_peers
if server_peers:
out.update(filter_version(server_peers.copy()))
# hardcoded servers
out.update(constants.net.DEFAULT_SERVERS)
# add recent servers
for s in self.recent_servers:
try:
host, port, protocol = deserialize_server(s)
except:
continue
if host not in out:
if host in out:
out[host].update({protocol: port})
else:
out[host] = {protocol: port}
# add servers received from main interface
server_peers = self.server_peers
if server_peers:
out.update(filter_version(server_peers.copy()))
# potentially filter out some
if self.config.get('noonion'):
out = filter_noonion(out)
Expand Down

0 comments on commit a2bffb9

Please sign in to comment.