@cryptotaxi247 / kubo / commits / 094baf6fb

error out if attempting connection to loopback

Jeromy committed Nov 3, 2014 at 00:28 UTC 094baf6fbf64cc7bba6c77a2afd2df781697fb63
2 files changed +12 -1
net/conn/dial.go
+5
@@ -8,6 +8,7 @@ import (
8 manet "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr/net"
9
10 peer "github.com/jbenet/go-ipfs/peer"
11 + "github.com/jbenet/go-ipfs/util"
12 )
13
14 // Dial connects to a particular peer, over a given network
@@ -23,6 +24,10 @@ func (d *Dialer) Dial(ctx context.Context, network string, remote peer.Peer) (Co
24 return nil, fmt.Errorf("No remote address for network %s", network)
25 }
26
27 + if util.IsLoopbackAddr(raddr.String()) {
28 + return nil, fmt.Errorf("Attempted to connect to loopback address: %s", raddr)
29 + }
30 +
31 remote, err := d.Peerstore.Add(remote)
32 if err != nil {
33 log.Errorf("Error putting peer into peerstore: %s", remote)
util/util.go
+7 -1
@@ -113,7 +113,13 @@ func GetenvBool(name string) bool {
113 }
114
115 func IsLoopbackAddr(addr string) bool {
116 - return addr == "/ip4/127.0.0.1" || addr == "/ip6/::1"
116 + loops := []string{"/ip4/127.0.0.1", "/ip6/::1", "/ip4/0.0.0.0"}
117 + for _, loop := range loops {
118 + if strings.HasPrefix(addr, loop) {
119 + return true
120 + }
121 + }
122 + return false
123 }
124
125 func GetLocalAddresses() ([]ma.Multiaddr, error) {