File tree Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,10 @@ def __init__(
9696 except Exception :
9797 raise ConfigurationError (_INVALID_HOST_MSG % (fqdn ,)) from None
9898 self .__slen = len (self .__plist )
99+ if fqdn == self ._resolve_uri (True )[0 ].target .to_text ():
100+ raise ConfigurationError (
101+ "Invalid SRV host: return address is identical to SRV hostname"
102+ )
99103
100104 async def get_options (self ) -> Optional [str ]:
101105 from dns import resolver
Original file line number Diff line number Diff line change @@ -96,6 +96,10 @@ def __init__(
9696 except Exception :
9797 raise ConfigurationError (_INVALID_HOST_MSG % (fqdn ,)) from None
9898 self .__slen = len (self .__plist )
99+ if fqdn == self ._resolve_uri (True )[0 ].target .to_text ():
100+ raise ConfigurationError (
101+ "Invalid SRV host: return address is identical to SRV hostname"
102+ )
99103
100104 def get_options (self ) -> Optional [str ]:
101105 from dns import resolver
Original file line number Diff line number Diff line change @@ -576,6 +576,21 @@ def test_error_when_return_address_does_not_end_with_srv_domain(self):
576576 "mock_target" : "test_1.evil.com" ,
577577 "expected_error" : "Invalid SRV host" ,
578578 },
579+ {
580+ "query" : "_mongodb._tcp.localhost" ,
581+ "mock_target" : "localhost" ,
582+ "expected_error" : "Invalid SRV host" ,
583+ },
584+ {
585+ "query" : "_mongodb._tcp.localhost" ,
586+ "mock_target" : "localhost" ,
587+ "expected_error" : "Invalid SRV host" ,
588+ },
589+ {
590+ "query" : "_mongodb._tcp.mongo.local" ,
591+ "mock_target" : "mongo.local" ,
592+ "expected_error" : "Invalid SRV host" ,
593+ },
579594 ]
580595 for case in test_cases :
581596 with patch ("dns.resolver.resolve" ) as mock_resolver :
You can’t perform that action at this time.
0 commit comments