Skip to content

Commit 6e725f5

Browse files
bitterpanda63claude
andcommitted
Move normalize_hostname to helpers to break circular import
Importing from sinks.socket in vulnerabilities.ssrf.imds created a cycle through sinks.socket.__init__ → aikido_zen.vulnerabilities. Move the implementation to helpers/normalize_hostname.py and have sinks/socket/normalize_hostname.py re-export from there. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 5f241aa commit 6e725f5

3 files changed

Lines changed: 17 additions & 14 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def normalize_hostname(hostname):
2+
if not hostname or not isinstance(hostname, str):
3+
return hostname
4+
5+
# Lowercase and strip trailing dot (DNS resolvers may return FQDNs like "example.com.")
6+
result = hostname.lower().rstrip(".")
7+
8+
try:
9+
# Decode Punycode if the hostname starts with xn--
10+
if result.startswith("xn--"):
11+
result = result.encode("ascii").decode("idna")
12+
return result
13+
except (UnicodeError, LookupError):
14+
return result
Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
def normalize_hostname(hostname):
2-
if not hostname or not isinstance(hostname, str):
3-
return hostname
1+
from aikido_zen.helpers.normalize_hostname import normalize_hostname
42

5-
# Lowercase and strip trailing dot (DNS resolvers may return FQDNs like "example.com.")
6-
result = hostname.lower().rstrip(".")
7-
8-
try:
9-
# Decode Punycode if the hostname starts with xn--
10-
if result.startswith("xn--"):
11-
result = result.encode("ascii").decode("idna")
12-
return result
13-
except (UnicodeError, LookupError):
14-
return result
3+
__all__ = ["normalize_hostname"]

aikido_zen/vulnerabilities/ssrf/imds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55

66
from aikido_zen.helpers.ip_matcher import IPMatcher
7-
from aikido_zen.sinks.socket.normalize_hostname import normalize_hostname
7+
from aikido_zen.helpers.normalize_hostname import normalize_hostname
88

99
imds_addresses = IPMatcher(
1010
[

0 commit comments

Comments
 (0)