@@ -295,8 +295,8 @@ def _get_dns_txt_options(hostname):
295
295
return None
296
296
except Exception as exc :
297
297
raise ConfigurationError (str (exc ))
298
- return '&' . join ([ maybe_decode ( val )
299
- for res in results for val in res . strings ] )
298
+ return (
299
+ b'&' . join ([ b'' . join ( res . strings ) for res in results ])). decode ( 'utf-8' )
300
300
301
301
302
302
def parse_uri (uri , default_port = DEFAULT_PORT , validate = True , warn = False ):
@@ -386,12 +386,28 @@ def parse_uri(uri, default_port=DEFAULT_PORT, validate=True, warn=False):
386
386
raise InvalidURI (
387
387
"%s URIs must include one, "
388
388
"and only one, hostname" % (SRV_SCHEME ,))
389
- hostname , port = nodes [0 ]
389
+ fqdn , port = nodes [0 ]
390
390
if port is not None :
391
391
raise InvalidURI (
392
392
"%s URIs must not include a port number" % (SRV_SCHEME ,))
393
- nodes = _get_dns_srv_hosts (hostname )
394
- dns_options = _get_dns_txt_options (hostname )
393
+ nodes = _get_dns_srv_hosts (fqdn )
394
+
395
+ try :
396
+ plist = fqdn .split ("." )[1 :]
397
+ except Exception :
398
+ raise ConfigurationError ("Invalid URI host" )
399
+ slen = len (plist )
400
+ if slen < 2 :
401
+ raise ConfigurationError ("Invalid URI host" )
402
+ for node in nodes :
403
+ try :
404
+ nlist = node [0 ].split ("." )[1 :][- slen :]
405
+ except Exception :
406
+ raise ConfigurationError ("Invalid SRV host" )
407
+ if plist != nlist :
408
+ raise ConfigurationError ("Invalid SRV host" )
409
+
410
+ dns_options = _get_dns_txt_options (fqdn )
395
411
if dns_options :
396
412
options = split_options (dns_options , validate , warn )
397
413
else :
0 commit comments