security: prevent SSRF DNS rebinding by dialing validated IP directly (#3)#582
Merged
Conversation
…#3) ValidateEndpointURL() resolved DNS during validation, but http.NewRequest re-resolved the hostname when actually dialing. An attacker controlling authoritative DNS could return a public IP for the validation lookup and a private IP (e.g. 169.254.169.254 cloud metadata) for the dial — a TOCTOU DNS rebinding bypass. Add validators.SafeHTTPClient that resolves the host once, rejects any private/loopback/link-local IPs, and pins http.Transport.DialContext to the validated IP. TLS still uses ServerName=host so SNI and certificate validation work normally. Updated callers: - internal/graphql/test_endpoint.go (admin webhook test) - internal/events/events.go (webhook dispatcher) Save-time validators (add_webhook.go, update_webhook.go) keep using ValidateEndpointURL since they don't make outbound HTTP requests.
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
Closes a TOCTOU / DNS rebinding hole in webhook endpoint validation.
ValidateEndpointURLresolved DNS during validation buthttp.NewRequestre-resolved when dialing — an attacker controlling DNS could return a public IP for validation and a private IP (e.g.169.254.169.254) for the actual dial.Changes
validators.SafeHTTPClient(ctx, rawURL, timeout)that resolves the host once, rejects private/loopback/link-local IPs, and pinshttp.Transport.DialContextto the validated IP. TLS still usesServerName=hostso SNI and cert validation work normally.internal/graphql/test_endpoint.goandinternal/events/events.gonow useSafeHTTPClientinstead of constructing a freshhttp.Client.ValidateEndpointURLcallers (add_webhook.go,update_webhook.go) keep the existing format check — they don't make outbound HTTP.Test plan
go build ./...go test ./internal/validators/...http://169.254.169.254/) is rejected