Browse Source

Reject invalid hostnames in Env

master
Neil Booth 8 years ago
parent
commit
8a2821d542
  1. 2
      lib/util.py
  2. 7
      server/env.py
  3. 2
      server/peers.py

2
lib/util.py

@ -249,6 +249,6 @@ def is_valid_hostname(hostname):
if len(hostname) > 255:
return False
# strip exactly one dot from the right, if present
if hostname[-1] == ".":
if hostname and hostname[-1] == ".":
hostname = hostname[:-1]
return all(SEGMENT_REGEX.match(x) for x in hostname.split("."))

7
server/env.py

@ -14,13 +14,13 @@ from ipaddress import ip_address
from os import environ
from lib.coins import Coin
from lib.util import LoggedClass
import lib.util as lib_util
NetIdentity = namedtuple('NetIdentity', 'host tcp_port ssl_port nick_suffix')
class Env(LoggedClass):
class Env(lib_util.LoggedClass):
'''Wraps environment configuration.'''
class Error(Exception):
@ -126,7 +126,8 @@ class Env(LoggedClass):
try:
ip = ip_address(host)
except ValueError:
bad = host.lower().strip() in ('', 'localhost')
bad = (not lib_util.is_valid_hostname(host)
or hostname.lower() == 'localhost')
else:
bad = (ip.is_multicast or ip.is_unspecified
or (ip.is_private and (self.irc or self.peer_announce)))

2
server/peers.py

@ -118,7 +118,7 @@ class PeerSession(JSONSession):
self.peer.update_features(features)
else:
self.bad = True
self.log_warning('marking DNS alias bad')
self.log_warning('ignoring - not listed in features')
self.close_if_done()
def on_headers(self, result, error):

Loading…
Cancel
Save