fix: prevent resolver from overwriting DNS cache hostname entries#11
Merged
fix: prevent resolver from overwriting DNS cache hostname entries#11
Conversation
When gost calls the resolver with a raw IP (e.g. from tun2socks), LookupIP returns the IP itself. RegisterIPs then overwrites the correct hostname entry (e.g. 160.79.104.10 -> api.anthropic.com) with a self-referential mapping (160.79.104.10 -> 160.79.104.10). This caused pending requests and logs to show raw IPs instead of hostnames, worsening over time as each connection corrupted its cache entry. Skip cache registration when the host is already an IP address.
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
net.LookupIPreturns the IP itself.RegisterIPsthen overwrites the correct hostname mapping (e.g.160.79.104.10 -> api.anthropic.com) with a self-referential one (160.79.104.10 -> 160.79.104.10).RegisterIPswhen the host is already an IP address.Root cause
The DNS cache is populated correctly by the DNS handler wrapper (
dns_cache_handler.go) when a DNS query flows through the proxy. However, once the connection is allowed and gost dials the destination, gost calls the resolver plugin to "resolve" the target. For IP destinations,LookupIP("160.79.104.10")trivially returns[160.79.104.10], andRegisterIPs("160.79.104.10", ...)overwrites the correct entry.Reproduction:
api.anthropic.com -> 160.79.104.10(cache correct)160.79.104.10: cache HIT, showsapi.anthropic.com(correct)160.79.104.10 -> 160.79.104.10160.79.104.10: cache HIT, shows160.79.104.10(wrong)Test plan
go test ./internal/greyproxy/...passes