Trim trailing dot from trusted IMDS hostnames#301
Open
bitterpanda63 wants to merge 2 commits into
Open
Conversation
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 Report❌ Patch coverage is
📢 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>
tomaisthorpe
approved these changes
Jun 8, 2026
kapytein
reviewed
Jun 10, 2026
| String lower = hostname.toLowerCase(); | ||
| String noDot = lower.endsWith(".") ? lower.substring(0, lower.length() - 1) : lower; | ||
| try { | ||
| return IDN.toUnicode(noDot); |
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DNS resolvers sometimes return fully-qualified domain names with a trailing dot (e.g.
metadata.google.internal.). The previousArrays.asList(trustedHosts).contains(hostname)check inTrustedHosts.isTrustedHostnamedid not normalize the hostname, so trailing-dot forms were not matched and GCP IMDS requests could be incorrectly flagged as stored SSRF.ResolverTestThis 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"passesSummary by Aikido
🐛 Bugfixes
🔧 Refactors
More info