Skip to content

Trim trailing dot from trusted IMDS hostnames#301

Open
bitterpanda63 wants to merge 2 commits into
mainfrom
fix/trusted-hostname-trailing-dot
Open

Trim trailing dot from trusted IMDS hostnames#301
bitterpanda63 wants to merge 2 commits into
mainfrom
fix/trusted-hostname-trailing-dot

Conversation

@bitterpanda63

@bitterpanda63 bitterpanda63 commented Jun 8, 2026

Copy link
Copy Markdown
Member

Summary

DNS resolvers sometimes return fully-qualified domain names with a trailing dot (e.g. metadata.google.internal.). The previous Arrays.asList(trustedHosts).contains(hostname) check in TrustedHosts.isTrustedHostname did not normalize the hostname, so trailing-dot forms were not matched and GCP IMDS requests could be incorrectly flagged as stored SSRF.

  • Lowercase + strip trailing dot before the contains check
  • Add test cases for trailing-dot variants in ResolverTest

This is the same fix already applied in firewall-go (PR #459). Ported to Python, Ruby, .NET, PHP, and Java.

Test plan

  • ./gradlew :agent_api:test --tests "vulnerabilities.ssrf.ResolverTest" passes

Summary by Aikido

Security Issues: 0 Quality Issues: 0 Resolved Issues: 0

🐛 Bugfixes

  • Normalized hostnames and trimmed trailing dots to fix mismatches

🔧 Refactors

  • Removed unused imports and replaced inline normalization with helper

More info

DNS resolvers may return hostnames with a trailing dot (FQDN form),
e.g. `metadata.google.internal.`. The previous equality check failed
to match these, risking false-positive stored-SSRF blocks for GCP IMDS.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ikido/agent_api/helpers/net/NormalizeHostname.java 71.42% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Create helpers/net/NormalizeHostname.java (lowercase, strip trailing
dot, IDN via java.net.IDN) to give SSRF code a canonical hostname form.
Replace the inline normalization in TrustedHosts.isTrustedHostname with
a call to this helper.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
String lower = hostname.toLowerCase();
String noDot = lower.endsWith(".") ? lower.substring(0, lower.length() - 1) : lower;
try {
return IDN.toUnicode(noDot);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this? if a DNS request is made to a host with punycode, it isn't converted to unicode by java's getallbyname

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants