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__(
96
96
except Exception :
97
97
raise ConfigurationError (_INVALID_HOST_MSG % (fqdn ,)) from None
98
98
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
+ )
99
103
100
104
async def get_options (self ) -> Optional [str ]:
101
105
from dns import resolver
Original file line number Diff line number Diff line change @@ -96,6 +96,10 @@ def __init__(
96
96
except Exception :
97
97
raise ConfigurationError (_INVALID_HOST_MSG % (fqdn ,)) from None
98
98
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
+ )
99
103
100
104
def get_options (self ) -> Optional [str ]:
101
105
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):
576
576
"mock_target" : "test_1.evil.com" ,
577
577
"expected_error" : "Invalid SRV host" ,
578
578
},
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
+ },
579
594
]
580
595
for case in test_cases :
581
596
with patch ("dns.resolver.resolve" ) as mock_resolver :
You can’t perform that action at this time.
0 commit comments