Repository navigation
Reject WHOIS referral targets that resolve to private/internal addresses (SSRF, #312) - #321
Merged
richardpenman merged 1 commit intoJul 11, 2026
Conversation
…ses (SSRF, richardpenman#312) findwhois_server extracts the referral host from the untrusted 'Whois Server:' field of an upstream response, and whois() then connects to it. Without validation a malicious/compromised server can redirect the client to internal services (SSRF) such as cloud metadata endpoints (e.g. 169.254.169.254). Adds _is_safe_referral_host(), which resolves the referral host and skips the referral if any resolved address is private/loopback/link-local/reserved/multicast/unspecified. Only referral hosts are checked; the caller's chosen server is untouched. Note: this is a resolve-then-connect check, so a DNS-rebinding attacker could still bypass it -- pushing the check into _connect on the resolved sockaddr would close that fully, happy to adjust to your preference. Refs richardpenman#312.
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.
Addresses the SSRF item in #312 (CWE-918).
findwhois_server extracts the referral host from the untrusted "Whois Server:"
field of an upstream response, and whois() then connects to it. Without
validation, a malicious or compromised WHOIS server can redirect the client to
internal services — e.g. cloud metadata endpoints like 169.254.169.254.
This adds _is_safe_referral_host(), which resolves the referral host and skips
the referral if any resolved address is private / loopback / link-local /
reserved / multicast / unspecified. Only server-provided referral hosts are
checked — the caller's own chosen server is untouched.
Note on approach: this is a resolve-then-connect check, so a DNS-rebinding
attacker could still bypass it. Pushing the check into _connect on the resolved
sockaddr would close that fully — happy to adjust to whichever you prefer.
Refs #312