Skip to content
Permalink
Browse files Browse the repository at this point in the history
fix ipv6 unspecified address
  • Loading branch information
mvisat committed Apr 22, 2019
1 parent a5a8577 commit 07f671d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client.go
Expand Up @@ -121,7 +121,7 @@ func safeAddr(ctx context.Context, resolver *net.Resolver, hostport string, opts

ip := net.ParseIP(host)
if ip != nil {
if ip.To4() != nil && c.isIPForbidden(ip) {
if ip.IsUnspecified() || (ip.To4() != nil && c.isIPForbidden(ip)) {
return "", fmt.Errorf("bad ip is detected: %v", ip)
}
return net.JoinHostPort(ip.String(), port), nil
Expand Down
4 changes: 4 additions & 0 deletions client_test.go
Expand Up @@ -19,6 +19,10 @@ func TestRequest(t *testing.T) {
if _, err := DefaultClient.Get("http://192.168.0.1"); err == nil {
t.Errorf("The request for localhost should be fail")
}

if _, err := DefaultClient.Get("http://[::]"); err == nil {
t.Errorf("The request for IPv6 unspecified address should be fail")
}
}

func TestIsHostForbidden(t *testing.T) {
Expand Down

0 comments on commit 07f671d

Please sign in to comment.