Skip to content

Commit 5b44cc6

Browse files
bitterpanda63claude
andcommitted
Trim trailing dot and normalize case for trusted IMDS hostnames
DNS resolvers may return hostnames with a trailing dot (e.g. `metadata.google.internal.`), which is a valid FQDN form. The previous direct equality check failed to match these, so they would not be skipped and could cause false-positive stored-SSRF blocks. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 4af94ea commit 5b44cc6

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

aikido_zen/vulnerabilities/ssrf/imds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def is_trusted_hostname(hostname):
2929
"""
3030
If the hostname is a trusted host (like metadata.goog), there was no spoofing of hostnames, so it's not an attack
3131
"""
32-
return hostname in trusted_hosts
32+
return hostname.lower().rstrip(".") in trusted_hosts
3333

3434

3535
def resolves_to_imds_ip(resolved_ip_addresses, hostname):

aikido_zen/vulnerabilities/ssrf/imds_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ def test_is_imds_ip_address_ipv6_mapped():
2121
def test_trusted_hostname_returns_none():
2222
"""Test that trusted hostnames always return None."""
2323
assert resolves_to_imds_ip(["1.1.1.1"], "metadata.google.internal") is None
24+
assert resolves_to_imds_ip(["169.254.169.254"], "metadata.google.internal.") is None
25+
assert resolves_to_imds_ip(["169.254.169.254"], "metadata.goog.") is None
26+
assert resolves_to_imds_ip(["169.254.169.254"], "METADATA.GOOGLE.INTERNAL") is None
2427

2528

2629
def test_aws_imds_ipv4_present_returns_ip():

0 commit comments

Comments
 (0)